public virtual void TestBootstrapStandbyWithActiveNN() { // make nn0 active cluster.TransitionToActive(0); // do ops and generate in-progress edit log data Configuration confNN1 = cluster.GetConfiguration(1); DistributedFileSystem dfs = (DistributedFileSystem)HATestUtil.ConfigureFailoverFs (cluster, confNN1); for (int i = 1; i <= 10; i++) { dfs.Mkdirs(new Path("/test" + i)); } dfs.Close(); // shutdown nn1 and delete its edit log files cluster.ShutdownNameNode(1); DeleteEditLogIfExists(confNN1); cluster.GetNameNodeRpc(0).SetSafeMode(HdfsConstants.SafeModeAction.SafemodeEnter, true); cluster.GetNameNodeRpc(0).SaveNamespace(); cluster.GetNameNodeRpc(0).SetSafeMode(HdfsConstants.SafeModeAction.SafemodeLeave, true); // check without -skipSharedEditsCheck, Bootstrap should fail for BKJM // immediately after saveNamespace int rc = BootstrapStandby.Run(new string[] { "-force", "-nonInteractive" }, confNN1 ); NUnit.Framework.Assert.AreEqual("Mismatches return code", 6, rc); // check with -skipSharedEditsCheck rc = BootstrapStandby.Run(new string[] { "-force", "-nonInteractive", "-skipSharedEditsCheck" }, confNN1); NUnit.Framework.Assert.AreEqual("Mismatches return code", 0, rc); // Checkpoint as fast as we can, in a tight loop. confNN1.SetInt(DFSConfigKeys.DfsNamenodeCheckpointPeriodKey, 1); cluster.RestartNameNode(1); cluster.TransitionToStandby(1); NameNode nn0 = cluster.GetNameNode(0); HATestUtil.WaitForStandbyToCatchUp(nn0, cluster.GetNameNode(1)); long expectedCheckpointTxId = NameNodeAdapter.GetNamesystem(nn0).GetFSImage().GetMostRecentCheckpointTxId (); HATestUtil.WaitForCheckpoint(cluster, 1, ImmutableList.Of((int)expectedCheckpointTxId )); // Should have copied over the namespace FSImageTestUtil.AssertNNHasCheckpoints(cluster, 1, ImmutableList.Of((int)expectedCheckpointTxId )); FSImageTestUtil.AssertNNFilesMatch(cluster); }
/// <summary> /// Check the blocks of dst file are cleaned after rename with overwrite /// Restart NN to check the rename successfully /// </summary> /// <exception cref="System.Exception"/> public virtual void TestRenameWithOverwrite() { short replFactor = 2; long blockSize = 512; Configuration conf = new Configuration(); MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf).NumDataNodes(replFactor ).Build(); DistributedFileSystem dfs = cluster.GetFileSystem(); try { long fileLen = blockSize * 3; string src = "/foo/src"; string dst = "/foo/dst"; Path srcPath = new Path(src); Path dstPath = new Path(dst); DFSTestUtil.CreateFile(dfs, srcPath, fileLen, replFactor, 1); DFSTestUtil.CreateFile(dfs, dstPath, fileLen, replFactor, 1); LocatedBlocks lbs = NameNodeAdapter.GetBlockLocations(cluster.GetNameNode(), dst, 0, fileLen); BlockManager bm = NameNodeAdapter.GetNamesystem(cluster.GetNameNode()).GetBlockManager (); NUnit.Framework.Assert.IsTrue(bm.GetStoredBlock(lbs.GetLocatedBlocks()[0].GetBlock ().GetLocalBlock()) != null); dfs.Rename(srcPath, dstPath, Options.Rename.Overwrite); NUnit.Framework.Assert.IsTrue(bm.GetStoredBlock(lbs.GetLocatedBlocks()[0].GetBlock ().GetLocalBlock()) == null); // Restart NN and check the rename successfully cluster.RestartNameNodes(); NUnit.Framework.Assert.IsFalse(dfs.Exists(srcPath)); NUnit.Framework.Assert.IsTrue(dfs.Exists(dstPath)); } finally { if (dfs != null) { dfs.Close(); } if (cluster != null) { cluster.Shutdown(); } } }
public virtual void TestDownloadingLaterCheckpoint() { // Roll edit logs a few times to inflate txid nn0.GetRpcServer().RollEditLog(); nn0.GetRpcServer().RollEditLog(); // Make checkpoint NameNodeAdapter.EnterSafeMode(nn0, false); NameNodeAdapter.SaveNamespace(nn0); NameNodeAdapter.LeaveSafeMode(nn0); long expectedCheckpointTxId = NameNodeAdapter.GetNamesystem(nn0).GetFSImage().GetMostRecentCheckpointTxId (); NUnit.Framework.Assert.AreEqual(6, expectedCheckpointTxId); int rc = BootstrapStandby.Run(new string[] { "-force" }, cluster.GetConfiguration (1)); NUnit.Framework.Assert.AreEqual(0, rc); // Should have copied over the namespace from the active FSImageTestUtil.AssertNNHasCheckpoints(cluster, 1, ImmutableList.Of((int)expectedCheckpointTxId )); FSImageTestUtil.AssertNNFilesMatch(cluster); // We should now be able to start the standby successfully. cluster.RestartNameNode(1); }