/// <exception cref="System.Exception"/> public virtual void TestQuery() { Configuration conf = new Configuration(); MiniQJMHACluster cluster = null; try { cluster = new MiniQJMHACluster.Builder(conf).Build(); MiniDFSCluster dfsCluster = cluster.GetDfsCluster(); dfsCluster.WaitActive(); dfsCluster.TransitionToActive(0); DistributedFileSystem dfs = dfsCluster.GetFileSystem(0); dfsCluster.ShutdownNameNode(1); // start rolling upgrade RollingUpgradeInfo info = dfs.RollingUpgrade(HdfsConstants.RollingUpgradeAction.Prepare ); NUnit.Framework.Assert.IsTrue(info.IsStarted()); info = dfs.RollingUpgrade(HdfsConstants.RollingUpgradeAction.Query); NUnit.Framework.Assert.IsFalse(info.CreatedRollbackImages()); dfsCluster.RestartNameNode(1); QueryForPreparation(dfs); // The NN should have a copy of the fsimage in case of rollbacks. NUnit.Framework.Assert.IsTrue(dfsCluster.GetNamesystem(0).GetFSImage().HasRollbackFSImage ()); } finally { if (cluster != null) { cluster.Shutdown(); } } }
/// <exception cref="System.IO.IOException"/> /// <exception cref="System.Exception"/> public virtual void TestCheckpoint() { Configuration conf = new Configuration(); conf.SetInt(DFSConfigKeys.DfsHaTaileditsPeriodKey, 1); conf.SetInt(DFSConfigKeys.DfsNamenodeCheckpointPeriodKey, 1); MiniQJMHACluster cluster = null; Path foo = new Path("/foo"); try { cluster = new MiniQJMHACluster.Builder(conf).Build(); MiniDFSCluster dfsCluster = cluster.GetDfsCluster(); dfsCluster.WaitActive(); dfsCluster.TransitionToActive(0); DistributedFileSystem dfs = dfsCluster.GetFileSystem(0); // start rolling upgrade RollingUpgradeInfo info = dfs.RollingUpgrade(HdfsConstants.RollingUpgradeAction.Prepare ); NUnit.Framework.Assert.IsTrue(info.IsStarted()); QueryForPreparation(dfs); dfs.Mkdirs(foo); long txid = dfs.RollEdits(); NUnit.Framework.Assert.IsTrue(txid > 0); int retries = 0; while (++retries < 5) { NNStorage storage = dfsCluster.GetNamesystem(1).GetFSImage().GetStorage(); if (storage.GetFsImageName(txid - 1) != null) { return; } Sharpen.Thread.Sleep(1000); } NUnit.Framework.Assert.Fail("new checkpoint does not exist"); } finally { if (cluster != null) { cluster.Shutdown(); } } }
/// <exception cref="System.Exception"/> public virtual void TestFinalize() { Configuration conf = new HdfsConfiguration(); MiniQJMHACluster cluster = null; Path foo = new Path("/foo"); Path bar = new Path("/bar"); try { cluster = new MiniQJMHACluster.Builder(conf).Build(); MiniDFSCluster dfsCluster = cluster.GetDfsCluster(); dfsCluster.WaitActive(); // let NN1 tail editlog every 1s dfsCluster.GetConfiguration(1).SetInt(DFSConfigKeys.DfsHaTaileditsPeriodKey, 1); dfsCluster.RestartNameNode(1); dfsCluster.TransitionToActive(0); DistributedFileSystem dfs = dfsCluster.GetFileSystem(0); dfs.Mkdirs(foo); FSImage fsimage = dfsCluster.GetNamesystem(0).GetFSImage(); // start rolling upgrade RollingUpgradeInfo info = dfs.RollingUpgrade(HdfsConstants.RollingUpgradeAction.Prepare ); NUnit.Framework.Assert.IsTrue(info.IsStarted()); dfs.Mkdirs(bar); QueryForPreparation(dfs); // The NN should have a copy of the fsimage in case of rollbacks. NUnit.Framework.Assert.IsTrue(fsimage.HasRollbackFSImage()); info = dfs.RollingUpgrade(HdfsConstants.RollingUpgradeAction.Finalize); NUnit.Framework.Assert.IsTrue(info.IsFinalized()); NUnit.Framework.Assert.IsTrue(dfs.Exists(foo)); // Once finalized, there should be no more fsimage for rollbacks. NUnit.Framework.Assert.IsFalse(fsimage.HasRollbackFSImage()); // Should have no problem in restart and replaying edits that include // the FINALIZE op. dfsCluster.RestartNameNode(0); } finally { if (cluster != null) { cluster.Shutdown(); } } }
/// <exception cref="System.Exception"/> public virtual void TestDowngrade() { Configuration conf = new HdfsConfiguration(); MiniQJMHACluster cluster = null; Path foo = new Path("/foo"); Path bar = new Path("/bar"); try { cluster = new MiniQJMHACluster.Builder(conf).Build(); MiniDFSCluster dfsCluster = cluster.GetDfsCluster(); dfsCluster.WaitActive(); // let NN1 tail editlog every 1s dfsCluster.GetConfiguration(1).SetInt(DFSConfigKeys.DfsHaTaileditsPeriodKey, 1); dfsCluster.RestartNameNode(1); dfsCluster.TransitionToActive(0); DistributedFileSystem dfs = dfsCluster.GetFileSystem(0); dfs.Mkdirs(foo); // start rolling upgrade RollingUpgradeInfo info = dfs.RollingUpgrade(HdfsConstants.RollingUpgradeAction.Prepare ); NUnit.Framework.Assert.IsTrue(info.IsStarted()); dfs.Mkdirs(bar); TestRollingUpgrade.QueryForPreparation(dfs); dfs.Close(); dfsCluster.RestartNameNode(0, true, "-rollingUpgrade", "downgrade"); // Once downgraded, there should be no more fsimage for rollbacks. NUnit.Framework.Assert.IsFalse(dfsCluster.GetNamesystem(0).GetFSImage().HasRollbackFSImage ()); // shutdown NN1 dfsCluster.ShutdownNameNode(1); dfsCluster.TransitionToActive(0); dfs = dfsCluster.GetFileSystem(0); NUnit.Framework.Assert.IsTrue(dfs.Exists(foo)); NUnit.Framework.Assert.IsTrue(dfs.Exists(bar)); } finally { if (cluster != null) { cluster.Shutdown(); } } }
public virtual void TestRollbackWithHAQJM() { Configuration conf = new HdfsConfiguration(); MiniQJMHACluster cluster = null; Path foo = new Path("/foo"); Path bar = new Path("/bar"); try { cluster = new MiniQJMHACluster.Builder(conf).Build(); MiniDFSCluster dfsCluster = cluster.GetDfsCluster(); dfsCluster.WaitActive(); // let NN1 tail editlog every 1s dfsCluster.GetConfiguration(1).SetInt(DFSConfigKeys.DfsHaTaileditsPeriodKey, 1); dfsCluster.RestartNameNode(1); dfsCluster.TransitionToActive(0); DistributedFileSystem dfs = dfsCluster.GetFileSystem(0); dfs.Mkdirs(foo); // start rolling upgrade RollingUpgradeInfo info = dfs.RollingUpgrade(HdfsConstants.RollingUpgradeAction.Prepare ); NUnit.Framework.Assert.IsTrue(info.IsStarted()); // create new directory dfs.Mkdirs(bar); dfs.Close(); TestRollingUpgrade.QueryForPreparation(dfs); // If the query returns true, both active and the standby NN should have // rollback fsimage ready. NUnit.Framework.Assert.IsTrue(dfsCluster.GetNameNode(0).GetFSImage().HasRollbackFSImage ()); NUnit.Framework.Assert.IsTrue(dfsCluster.GetNameNode(1).GetFSImage().HasRollbackFSImage ()); // rollback NN0 dfsCluster.RestartNameNode(0, true, "-rollingUpgrade", "rollback"); // shutdown NN1 dfsCluster.ShutdownNameNode(1); dfsCluster.TransitionToActive(0); // make sure /foo is still there, but /bar is not dfs = dfsCluster.GetFileSystem(0); NUnit.Framework.Assert.IsTrue(dfs.Exists(foo)); NUnit.Framework.Assert.IsFalse(dfs.Exists(bar)); // check the details of NNStorage NNStorage storage = dfsCluster.GetNamesystem(0).GetFSImage().GetStorage(); // segments:(startSegment, mkdir, start upgrade endSegment), // (startSegment, mkdir, endSegment) CheckNNStorage(storage, 4, 7); // check storage in JNs for (int i = 0; i < NumJournalNodes; i++) { FilePath dir = cluster.GetJournalCluster().GetCurrentDir(0, MiniQJMHACluster.Nameservice ); CheckJNStorage(dir, 5, 7); } // restart NN0 again to make sure we can start using the new fsimage and // the corresponding md5 checksum dfsCluster.RestartNameNode(0); // start the rolling upgrade again to make sure we do not load upgrade // status after the rollback dfsCluster.TransitionToActive(0); dfs.RollingUpgrade(HdfsConstants.RollingUpgradeAction.Prepare); } finally { if (cluster != null) { cluster.Shutdown(); } } }
/// <exception cref="System.Exception"/> public virtual void TestRollingUpgradeWithQJM() { string nnDirPrefix = MiniDFSCluster.GetBaseDirectory() + "/nn/"; FilePath nn1Dir = new FilePath(nnDirPrefix + "image1"); FilePath nn2Dir = new FilePath(nnDirPrefix + "image2"); Log.Info("nn1Dir=" + nn1Dir); Log.Info("nn2Dir=" + nn2Dir); Configuration conf = new HdfsConfiguration(); MiniJournalCluster mjc = new MiniJournalCluster.Builder(conf).Build(); SetConf(conf, nn1Dir, mjc); { // Start the cluster once to generate the dfs dirs MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf).NumDataNodes(0).ManageNameDfsDirs (false).CheckExitOnShutdown(false).Build(); // Shutdown the cluster before making a copy of the namenode dir to release // all file locks, otherwise, the copy will fail on some platforms. cluster.Shutdown(); } MiniDFSCluster cluster2 = null; try { // Start a second NN pointed to the same quorum. // We need to copy the image dir from the first NN -- or else // the new NN will just be rejected because of Namespace mismatch. FileUtil.FullyDelete(nn2Dir); FileUtil.Copy(nn1Dir, FileSystem.GetLocal(conf).GetRaw(), new Path(nn2Dir.GetAbsolutePath ()), false, conf); // Start the cluster again MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf).NumDataNodes(0).Format( false).ManageNameDfsDirs(false).CheckExitOnShutdown(false).Build(); Path foo = new Path("/foo"); Path bar = new Path("/bar"); Path baz = new Path("/baz"); RollingUpgradeInfo info1; { DistributedFileSystem dfs = cluster.GetFileSystem(); dfs.Mkdirs(foo); //start rolling upgrade dfs.SetSafeMode(HdfsConstants.SafeModeAction.SafemodeEnter); info1 = dfs.RollingUpgrade(HdfsConstants.RollingUpgradeAction.Prepare); dfs.SetSafeMode(HdfsConstants.SafeModeAction.SafemodeLeave); Log.Info("START\n" + info1); //query rolling upgrade NUnit.Framework.Assert.AreEqual(info1, dfs.RollingUpgrade(HdfsConstants.RollingUpgradeAction .Query)); dfs.Mkdirs(bar); cluster.Shutdown(); } // cluster2 takes over QJM Configuration conf2 = SetConf(new Configuration(), nn2Dir, mjc); cluster2 = new MiniDFSCluster.Builder(conf2).NumDataNodes(0).Format(false).ManageNameDfsDirs (false).Build(); DistributedFileSystem dfs2 = cluster2.GetFileSystem(); // Check that cluster2 sees the edits made on cluster1 NUnit.Framework.Assert.IsTrue(dfs2.Exists(foo)); NUnit.Framework.Assert.IsTrue(dfs2.Exists(bar)); NUnit.Framework.Assert.IsFalse(dfs2.Exists(baz)); //query rolling upgrade in cluster2 NUnit.Framework.Assert.AreEqual(info1, dfs2.RollingUpgrade(HdfsConstants.RollingUpgradeAction .Query)); dfs2.Mkdirs(baz); Log.Info("RESTART cluster 2"); cluster2.RestartNameNode(); NUnit.Framework.Assert.AreEqual(info1, dfs2.RollingUpgrade(HdfsConstants.RollingUpgradeAction .Query)); NUnit.Framework.Assert.IsTrue(dfs2.Exists(foo)); NUnit.Framework.Assert.IsTrue(dfs2.Exists(bar)); NUnit.Framework.Assert.IsTrue(dfs2.Exists(baz)); //restart cluster with -upgrade should fail. try { cluster2.RestartNameNode("-upgrade"); } catch (IOException e) { Log.Info("The exception is expected.", e); } Log.Info("RESTART cluster 2 again"); cluster2.RestartNameNode(); NUnit.Framework.Assert.AreEqual(info1, dfs2.RollingUpgrade(HdfsConstants.RollingUpgradeAction .Query)); NUnit.Framework.Assert.IsTrue(dfs2.Exists(foo)); NUnit.Framework.Assert.IsTrue(dfs2.Exists(bar)); NUnit.Framework.Assert.IsTrue(dfs2.Exists(baz)); //finalize rolling upgrade RollingUpgradeInfo finalize = dfs2.RollingUpgrade(HdfsConstants.RollingUpgradeAction .Finalize); NUnit.Framework.Assert.IsTrue(finalize.IsFinalized()); Log.Info("RESTART cluster 2 with regular startup option"); cluster2.GetNameNodeInfos()[0].SetStartOpt(HdfsServerConstants.StartupOption.Regular ); cluster2.RestartNameNode(); NUnit.Framework.Assert.IsTrue(dfs2.Exists(foo)); NUnit.Framework.Assert.IsTrue(dfs2.Exists(bar)); NUnit.Framework.Assert.IsTrue(dfs2.Exists(baz)); } finally { if (cluster2 != null) { cluster2.Shutdown(); } } }