/// <exception cref="Javax.Servlet.ServletException"/>
        /// <exception cref="System.IO.IOException"/>
        protected override void DoGet(HttpServletRequest request, HttpServletResponse response
                                      )
        {
            FileInputStream editFileIn = null;

            try
            {
                ServletContext context = GetServletContext();
                Configuration  conf    = (Configuration)GetServletContext().GetAttribute(JspHelper.CurrentConf
                                                                                         );
                string journalId = request.GetParameter(JournalIdParam);
                QuorumJournalManager.CheckJournalId(journalId);
                JNStorage storage = JournalNodeHttpServer.GetJournalFromContext(context, journalId
                                                                                ).GetStorage();
                // Check security
                if (!CheckRequestorOrSendError(conf, request, response))
                {
                    return;
                }
                // Check that the namespace info is correct
                if (!CheckStorageInfoOrSendError(storage, request, response))
                {
                    return;
                }
                long segmentTxId       = ServletUtil.ParseLongParam(request, SegmentTxidParam);
                FileJournalManager fjm = storage.GetJournalManager();
                FilePath           editFile;
                lock (fjm)
                {
                    // Synchronize on the FJM so that the file doesn't get finalized
                    // out from underneath us while we're in the process of opening
                    // it up.
                    FileJournalManager.EditLogFile elf = fjm.GetLogFile(segmentTxId);
                    if (elf == null)
                    {
                        response.SendError(HttpServletResponse.ScNotFound, "No edit log found starting at txid "
                                           + segmentTxId);
                        return;
                    }
                    editFile = elf.GetFile();
                    ImageServlet.SetVerificationHeadersForGet(response, editFile);
                    ImageServlet.SetFileNameHeaders(response, editFile);
                    editFileIn = new FileInputStream(editFile);
                }
                DataTransferThrottler throttler = ImageServlet.GetThrottler(conf);
                // send edits
                TransferFsImage.CopyFileToStream(response.GetOutputStream(), editFile, editFileIn
                                                 , throttler);
            }
            catch (Exception t)
            {
                string errMsg = "getedit failed. " + StringUtils.StringifyException(t);
                response.SendError(HttpServletResponse.ScInternalServerError, errMsg);
                throw new IOException(errMsg);
            }
            finally
            {
                IOUtils.CloseStream(editFileIn);
            }
        }
Example #2
0
 /// <exception cref="System.IO.IOException"/>
 internal virtual Journal GetOrCreateJournal(string jid, HdfsServerConstants.StartupOption
                                             startOpt)
 {
     lock (this)
     {
         QuorumJournalManager.CheckJournalId(jid);
         Journal journal = journalsById[jid];
         if (journal == null)
         {
             FilePath logDir = GetLogDir(jid);
             Log.Info("Initializing journal in directory " + logDir);
             journal = new Journal(conf, logDir, jid, startOpt, new JournalNode.ErrorReporter(
                                       this));
             journalsById[jid] = journal;
         }
         return(journal);
     }
 }
Example #3
0
        /// <exception cref="System.IO.IOException"/>
        public static EditLogOutputStream WriteSegment(MiniJournalCluster cluster, QuorumJournalManager
                                                       qjm, long startTxId, int numTxns, bool finalize)
        {
            EditLogOutputStream stm = qjm.StartLogSegment(startTxId, NameNodeLayoutVersion.CurrentLayoutVersion
                                                          );

            // Should create in-progress
            AssertExistsInQuorum(cluster, NNStorage.GetInProgressEditsFileName(startTxId));
            WriteTxns(stm, startTxId, numTxns);
            if (finalize)
            {
                stm.Close();
                qjm.FinalizeLogSegment(startTxId, startTxId + numTxns - 1);
                return(null);
            }
            else
            {
                return(stm);
            }
        }
Example #4
0
        /// <exception cref="System.IO.IOException"/>
        public static long RecoverAndReturnLastTxn(QuorumJournalManager qjm)
        {
            qjm.RecoverUnfinalizedSegments();
            long lastRecoveredTxn = 0;
            IList <EditLogInputStream> streams = Lists.NewArrayList();

            try
            {
                qjm.SelectInputStreams(streams, 0, false);
                foreach (EditLogInputStream elis in streams)
                {
                    NUnit.Framework.Assert.IsTrue(elis.GetFirstTxId() > lastRecoveredTxn);
                    lastRecoveredTxn = elis.GetLastTxId();
                }
            }
            finally
            {
                IOUtils.Cleanup(null, Sharpen.Collections.ToArray(streams, new IDisposable[0]));
            }
            return(lastRecoveredTxn);
        }