/// <exception cref="System.IO.IOException"/> private void SaveNameSystemSection(FsImageProto.FileSummary.Builder summary) { FSNamesystem fsn = context.GetSourceNamesystem(); OutputStream @out = sectionOutputStream; BlockIdManager blockIdManager = fsn.GetBlockIdManager(); FsImageProto.NameSystemSection.Builder b = FsImageProto.NameSystemSection.NewBuilder ().SetGenstampV1(blockIdManager.GetGenerationStampV1()).SetGenstampV1Limit(blockIdManager .GetGenerationStampV1Limit()).SetGenstampV2(blockIdManager.GetGenerationStampV2( )).SetLastAllocatedBlockId(blockIdManager.GetLastAllocatedBlockId()).SetTransactionId (context.GetTxId()); // We use the non-locked version of getNamespaceInfo here since // the coordinating thread of saveNamespace already has read-locked // the namespace for us. If we attempt to take another readlock // from the actual saver thread, there's a potential of a // fairness-related deadlock. See the comments on HDFS-2223. b.SetNamespaceId(fsn.UnprotectedGetNamespaceInfo().GetNamespaceID()); if (fsn.IsRollingUpgrade()) { b.SetRollingUpgradeStartTime(fsn.GetRollingUpgradeInfo().GetStartTime()); } FsImageProto.NameSystemSection s = ((FsImageProto.NameSystemSection)b.Build()); s.WriteDelimitedTo(@out); CommitSection(summary, FSImageFormatProtobuf.SectionName.NsInfo); }
/// <exception cref="System.IO.IOException"/> private void LoadNameSystemSection(InputStream @in) { FsImageProto.NameSystemSection s = FsImageProto.NameSystemSection.ParseDelimitedFrom (@in); BlockIdManager blockIdManager = fsn.GetBlockIdManager(); blockIdManager.SetGenerationStampV1(s.GetGenstampV1()); blockIdManager.SetGenerationStampV2(s.GetGenstampV2()); blockIdManager.SetGenerationStampV1Limit(s.GetGenstampV1Limit()); blockIdManager.SetLastAllocatedBlockId(s.GetLastAllocatedBlockId()); imgTxId = s.GetTransactionId(); if (s.HasRollingUpgradeStartTime() && fsn.GetFSImage().HasRollbackFSImage()) { // we set the rollingUpgradeInfo only when we make sure we have the // rollback image fsn.SetRollingUpgradeInfo(true, s.GetRollingUpgradeStartTime()); } }
/// <exception cref="System.Exception"/> public virtual void TestCancelSaveNamespace() { Configuration conf = GetConf(); NameNode.InitMetrics(conf, HdfsServerConstants.NamenodeRole.Namenode); DFSTestUtil.FormatNameNode(conf); FSNamesystem fsn = FSNamesystem.LoadFromDisk(conf); // Replace the FSImage with a spy FSImage image = fsn.GetFSImage(); NNStorage storage = image.GetStorage(); storage.Close(); // unlock any directories that FSNamesystem's initialization may have locked storage.SetStorageDirectories(FSNamesystem.GetNamespaceDirs(conf), FSNamesystem.GetNamespaceEditsDirs (conf)); FSNamesystem spyFsn = Org.Mockito.Mockito.Spy(fsn); FSNamesystem finalFsn = spyFsn; GenericTestUtils.DelayAnswer delayer = new GenericTestUtils.DelayAnswer(Log); BlockIdManager bid = Org.Mockito.Mockito.Spy(spyFsn.GetBlockIdManager()); Whitebox.SetInternalState(finalFsn, "blockIdManager", bid); Org.Mockito.Mockito.DoAnswer(delayer).When(bid).GetGenerationStampV2(); ExecutorService pool = Executors.NewFixedThreadPool(2); try { DoAnEdit(fsn, 1); Canceler canceler = new Canceler(); // Save namespace fsn.SetSafeMode(HdfsConstants.SafeModeAction.SafemodeEnter); try { Future <Void> saverFuture = pool.Submit(new _Callable_561(image, finalFsn, canceler )); // Wait until saveNamespace calls getGenerationStamp delayer.WaitForCall(); // then cancel the saveNamespace Future <Void> cancelFuture = pool.Submit(new _Callable_572(canceler)); // give the cancel call time to run Sharpen.Thread.Sleep(500); // allow saveNamespace to proceed - it should check the cancel flag after // this point and throw an exception delayer.Proceed(); cancelFuture.Get(); saverFuture.Get(); NUnit.Framework.Assert.Fail("saveNamespace did not fail even though cancelled!"); } catch (Exception t) { GenericTestUtils.AssertExceptionContains("SaveNamespaceCancelledException", t); } Log.Info("Successfully cancelled a saveNamespace"); // Check that we have only the original image and not any // cruft left over from half-finished images FSImageTestUtil.LogStorageContents(Log, storage); foreach (Storage.StorageDirectory sd in storage.DirIterable(null)) { FilePath curDir = sd.GetCurrentDir(); GenericTestUtils.AssertGlobEquals(curDir, "fsimage_.*", NNStorage.GetImageFileName (0), NNStorage.GetImageFileName(0) + MD5FileUtils.Md5Suffix); } } finally { fsn.Close(); } }