예제 #1
0
        /// <exception cref="System.IO.IOException"/>
        internal static void DoMerge(CheckpointSignature sig, RemoteEditLogManifest manifest
                                     , bool loadImage, FSImage dstImage, FSNamesystem dstNamesystem)
        {
            NNStorage dstStorage = dstImage.GetStorage();

            dstStorage.SetStorageInfo(sig);
            if (loadImage)
            {
                FilePath file = dstStorage.FindImageFile(NNStorage.NameNodeFile.Image, sig.mostRecentCheckpointTxId
                                                         );
                if (file == null)
                {
                    throw new IOException("Couldn't find image file at txid " + sig.mostRecentCheckpointTxId
                                          + " even though it should have " + "just been downloaded");
                }
                dstNamesystem.WriteLock();
                try
                {
                    dstImage.ReloadFromImageFile(file, dstNamesystem);
                }
                finally
                {
                    dstNamesystem.WriteUnlock();
                }
                dstNamesystem.ImageLoadComplete();
            }
            // error simulation code for junit test
            CheckpointFaultInjector.GetInstance().DuringMerge();
            Checkpointer.RollForwardByApplyingLogs(manifest, dstImage, dstNamesystem);
            // The following has the side effect of purging old fsimages/edit logs.
            dstImage.SaveFSImageInAllDirs(dstNamesystem, dstImage.GetLastAppliedTxId());
            dstStorage.WriteAll();
        }
예제 #2
0
        /// <exception cref="System.IO.IOException"/>
        internal static void RollForwardByApplyingLogs(RemoteEditLogManifest manifest, FSImage
                                                       dstImage, FSNamesystem dstNamesystem)
        {
            NNStorage dstStorage = dstImage.GetStorage();
            IList <EditLogInputStream> editsStreams = Lists.NewArrayList();

            foreach (RemoteEditLog log in manifest.GetLogs())
            {
                if (log.GetEndTxId() > dstImage.GetLastAppliedTxId())
                {
                    FilePath f = dstStorage.FindFinalizedEditsFile(log.GetStartTxId(), log.GetEndTxId
                                                                       ());
                    editsStreams.AddItem(new EditLogFileInputStream(f, log.GetStartTxId(), log.GetEndTxId
                                                                        (), true));
                }
            }
            Log.Info("Checkpointer about to load edits from " + editsStreams.Count + " stream(s)."
                     );
            dstImage.LoadEdits(editsStreams, dstNamesystem);
        }
예제 #3
0
 internal virtual void DoTailEdits()
 {
     // Write lock needs to be interruptible here because the
     // transitionToActive RPC takes the write lock before calling
     // tailer.stop() -- so if we're not interruptible, it will
     // deadlock.
     namesystem.WriteLockInterruptibly();
     try
     {
         FSImage image     = namesystem.GetFSImage();
         long    lastTxnId = image.GetLastAppliedTxId();
         if (Log.IsDebugEnabled())
         {
             Log.Debug("lastTxnId: " + lastTxnId);
         }
         ICollection <EditLogInputStream> streams;
         try
         {
             streams = editLog.SelectInputStreams(lastTxnId + 1, 0, null, false);
         }
         catch (IOException ioe)
         {
             // This is acceptable. If we try to tail edits in the middle of an edits
             // log roll, i.e. the last one has been finalized but the new inprogress
             // edits file hasn't been started yet.
             Log.Warn("Edits tailer failed to find any streams. Will try again " + "later.", ioe
                      );
             return;
         }
         if (Log.IsDebugEnabled())
         {
             Log.Debug("edit streams to load from: " + streams.Count);
         }
         // Once we have streams to load, errors encountered are legitimate cause
         // for concern, so we don't catch them here. Simple errors reading from
         // disk are ignored.
         long editsLoaded = 0;
         try
         {
             editsLoaded = image.LoadEdits(streams, namesystem);
         }
         catch (EditLogInputException elie)
         {
             editsLoaded = elie.GetNumEditsLoaded();
             throw;
         }
         finally
         {
             if (editsLoaded > 0 || Log.IsDebugEnabled())
             {
                 Log.Info(string.Format("Loaded %d edits starting from txid %d ", editsLoaded, lastTxnId
                                        ));
             }
         }
         if (editsLoaded > 0)
         {
             lastLoadTimeMs = Time.MonotonicNow();
         }
         lastLoadedTxnId = image.GetLastAppliedTxId();
     }
     finally
     {
         namesystem.WriteUnlock();
     }
 }