/// <exception cref="System.IO.IOException"/> /// <exception cref="System.Exception"/> public virtual void TestFinalizeErrorReportedToNNStorage() { FilePath f = new FilePath(TestEditLog.TestDir + "/filejournaltestError"); // abort after 10th roll NNStorage storage = TestEditLog.SetupEdits(Sharpen.Collections.SingletonList <URI> (f.ToURI()), 10, new TestEditLog.AbortSpec(10, 0)); Storage.StorageDirectory sd = storage.DirIterator(NNStorage.NameNodeDirType.Edits ).Next(); FileJournalManager jm = new FileJournalManager(conf, sd, storage); string sdRootPath = sd.GetRoot().GetAbsolutePath(); FileUtil.Chmod(sdRootPath, "-w", true); try { jm.FinalizeLogSegment(0, 1); } finally { FileUtil.Chmod(sdRootPath, "+w", true); NUnit.Framework.Assert.IsTrue(storage.GetRemovedStorageDirs().Contains(sd)); } }
/// <summary> /// Verify that a saveNamespace command brings faulty directories /// in fs.name.dir and fs.edit.dir back online. /// </summary> /// <exception cref="System.Exception"/> public virtual void TestReinsertnamedirsInSavenamespace() { // create a configuration with the key to restore error // directories in fs.name.dir Configuration conf = GetConf(); conf.SetBoolean(DFSConfigKeys.DfsNamenodeNameDirRestoreKey, true); NameNode.InitMetrics(conf, HdfsServerConstants.NamenodeRole.Namenode); DFSTestUtil.FormatNameNode(conf); FSNamesystem fsn = FSNamesystem.LoadFromDisk(conf); // Replace the FSImage with a spy FSImage originalImage = fsn.GetFSImage(); NNStorage storage = originalImage.GetStorage(); FSImage spyImage = Org.Mockito.Mockito.Spy(originalImage); Whitebox.SetInternalState(fsn, "fsImage", spyImage); FileSystem fs = FileSystem.GetLocal(conf); FilePath rootDir = storage.GetStorageDir(0).GetRoot(); Path rootPath = new Path(rootDir.GetPath(), "current"); FsPermission permissionNone = new FsPermission((short)0); FsPermission permissionAll = new FsPermission(FsAction.All, FsAction.ReadExecute, FsAction.ReadExecute); fs.SetPermission(rootPath, permissionNone); try { DoAnEdit(fsn, 1); fsn.SetSafeMode(HdfsConstants.SafeModeAction.SafemodeEnter); // Save namespace - should mark the first storage dir as faulty // since it's not traversable. Log.Info("Doing the first savenamespace."); fsn.SaveNamespace(); Log.Info("First savenamespace sucessful."); NUnit.Framework.Assert.IsTrue("Savenamespace should have marked one directory as bad." + " But found " + storage.GetRemovedStorageDirs().Count + " bad directories.", storage.GetRemovedStorageDirs().Count == 1); fs.SetPermission(rootPath, permissionAll); // The next call to savenamespace should try inserting the // erroneous directory back to fs.name.dir. This command should // be successful. Log.Info("Doing the second savenamespace."); fsn.SaveNamespace(); Log.Warn("Second savenamespace sucessful."); NUnit.Framework.Assert.IsTrue("Savenamespace should have been successful in removing " + " bad directories from Image." + " But found " + storage.GetRemovedStorageDirs ().Count + " bad directories.", storage.GetRemovedStorageDirs().Count == 0); // Now shut down and restart the namesystem Log.Info("Shutting down fsimage."); originalImage.Close(); fsn.Close(); fsn = null; // Start a new namesystem, which should be able to recover // the namespace from the previous incarnation. Log.Info("Loading new FSmage from disk."); fsn = FSNamesystem.LoadFromDisk(conf); // Make sure the image loaded including our edit. Log.Info("Checking reloaded image."); CheckEditExists(fsn, 1); Log.Info("Reloaded image is good."); } finally { if (rootDir.Exists()) { fs.SetPermission(rootPath, permissionAll); } if (fsn != null) { try { fsn.Close(); } catch (Exception t) { Log.Fatal("Failed to shut down", t); } } } }