/// <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); }
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(); } }