public virtual void TestFinalizeWithJournalNodes() { MiniQJMHACluster qjCluster = null; FileSystem fs = null; try { MiniQJMHACluster.Builder builder = new MiniQJMHACluster.Builder(conf); builder.GetDfsBuilder().NumDataNodes(0); qjCluster = builder.Build(); MiniDFSCluster cluster = qjCluster.GetDfsCluster(); // No upgrade is in progress at the moment. CheckJnPreviousDirExistence(qjCluster, false); CheckClusterPreviousDirExistence(cluster, false); AssertCTimesEqual(cluster); // Transition NN0 to active and do some FS ops. cluster.TransitionToActive(0); fs = HATestUtil.ConfigureFailoverFs(cluster, conf); NUnit.Framework.Assert.IsTrue(fs.Mkdirs(new Path("/foo1"))); long cidBeforeUpgrade = GetCommittedTxnIdValue(qjCluster); // Do the upgrade. Shut down NN1 and then restart NN0 with the upgrade // flag. cluster.ShutdownNameNode(1); cluster.GetNameNodeInfos()[0].SetStartOpt(HdfsServerConstants.StartupOption.Upgrade ); cluster.RestartNameNode(0, false); NUnit.Framework.Assert.IsTrue(cidBeforeUpgrade <= GetCommittedTxnIdValue(qjCluster )); NUnit.Framework.Assert.IsTrue(fs.Mkdirs(new Path("/foo2"))); CheckNnPreviousDirExistence(cluster, 0, true); CheckNnPreviousDirExistence(cluster, 1, false); CheckJnPreviousDirExistence(qjCluster, true); // Now bootstrap the standby with the upgraded info. int rc = BootstrapStandby.Run(new string[] { "-force" }, cluster.GetConfiguration (1)); NUnit.Framework.Assert.AreEqual(0, rc); cluster.RestartNameNode(1); long cidDuringUpgrade = GetCommittedTxnIdValue(qjCluster); NUnit.Framework.Assert.IsTrue(cidDuringUpgrade > cidBeforeUpgrade); RunFinalizeCommand(cluster); NUnit.Framework.Assert.AreEqual(cidDuringUpgrade, GetCommittedTxnIdValue(qjCluster )); CheckClusterPreviousDirExistence(cluster, false); CheckJnPreviousDirExistence(qjCluster, false); AssertCTimesEqual(cluster); } finally { if (fs != null) { fs.Close(); } if (qjCluster != null) { qjCluster.Shutdown(); } } }
/// <exception cref="System.IO.IOException"/> private MiniQJMHACluster(MiniQJMHACluster.Builder builder) { this.conf = builder.conf; int retryCount = 0; while (true) { try { basePort = 10000 + Random.Next(1000) * 4; // start 3 journal nodes journalCluster = new MiniJournalCluster.Builder(conf).Format(true).Build(); URI journalURI = journalCluster.GetQuorumJournalURI(Nameservice); // start cluster with 2 NameNodes MiniDFSNNTopology topology = CreateDefaultTopology(basePort); InitHAConf(journalURI, builder.conf); // First start up the NNs just to format the namespace. The MinIDFSCluster // has no way to just format the NameNodes without also starting them. cluster = builder.dfsBuilder.NnTopology(topology).ManageNameDfsSharedDirs(false). Build(); cluster.WaitActive(); cluster.ShutdownNameNodes(); // initialize the journal nodes Configuration confNN0 = cluster.GetConfiguration(0); NameNode.InitializeSharedEdits(confNN0, true); cluster.GetNameNodeInfos()[0].SetStartOpt(builder.startOpt); cluster.GetNameNodeInfos()[1].SetStartOpt(builder.startOpt); // restart the cluster cluster.RestartNameNodes(); ++retryCount; break; } catch (BindException) { Log.Info("MiniQJMHACluster port conflicts, retried " + retryCount + " times"); } } }
public virtual void TestRollbackWithJournalNodes() { MiniQJMHACluster qjCluster = null; FileSystem fs = null; try { MiniQJMHACluster.Builder builder = new MiniQJMHACluster.Builder(conf); builder.GetDfsBuilder().NumDataNodes(0); qjCluster = builder.Build(); MiniDFSCluster cluster = qjCluster.GetDfsCluster(); // No upgrade is in progress at the moment. CheckClusterPreviousDirExistence(cluster, false); AssertCTimesEqual(cluster); CheckJnPreviousDirExistence(qjCluster, false); // Transition NN0 to active and do some FS ops. cluster.TransitionToActive(0); fs = HATestUtil.ConfigureFailoverFs(cluster, conf); NUnit.Framework.Assert.IsTrue(fs.Mkdirs(new Path("/foo1"))); long cidBeforeUpgrade = GetCommittedTxnIdValue(qjCluster); // Do the upgrade. Shut down NN1 and then restart NN0 with the upgrade // flag. cluster.ShutdownNameNode(1); cluster.GetNameNodeInfos()[0].SetStartOpt(HdfsServerConstants.StartupOption.Upgrade ); cluster.RestartNameNode(0, false); CheckNnPreviousDirExistence(cluster, 0, true); CheckNnPreviousDirExistence(cluster, 1, false); CheckJnPreviousDirExistence(qjCluster, true); // NN0 should come up in the active state when given the -upgrade option, // so no need to transition it to active. NUnit.Framework.Assert.IsTrue(fs.Mkdirs(new Path("/foo2"))); long cidDuringUpgrade = GetCommittedTxnIdValue(qjCluster); NUnit.Framework.Assert.IsTrue(cidDuringUpgrade > cidBeforeUpgrade); // Now bootstrap the standby with the upgraded info. int rc = BootstrapStandby.Run(new string[] { "-force" }, cluster.GetConfiguration (1)); NUnit.Framework.Assert.AreEqual(0, rc); cluster.RestartNameNode(1); CheckNnPreviousDirExistence(cluster, 0, true); CheckNnPreviousDirExistence(cluster, 1, true); CheckJnPreviousDirExistence(qjCluster, true); AssertCTimesEqual(cluster); // Shut down the NNs, but deliberately leave the JNs up and running. ICollection <URI> nn1NameDirs = cluster.GetNameDirs(0); cluster.Shutdown(); conf.SetStrings(DFSConfigKeys.DfsNamenodeNameDirKey, Joiner.On(",").Join(nn1NameDirs )); NameNode.DoRollback(conf, false); long cidAfterRollback = GetCommittedTxnIdValue(qjCluster); NUnit.Framework.Assert.IsTrue(cidBeforeUpgrade < cidAfterRollback); // make sure the committedTxnId has been reset correctly after rollback NUnit.Framework.Assert.IsTrue(cidDuringUpgrade > cidAfterRollback); // The rollback operation should have rolled back the first NN's local // dirs, and the shared dir, but not the other NN's dirs. Those have to be // done by bootstrapping the standby. CheckNnPreviousDirExistence(cluster, 0, false); CheckJnPreviousDirExistence(qjCluster, false); } finally { if (fs != null) { fs.Close(); } if (qjCluster != null) { qjCluster.Shutdown(); } } }
public virtual void TestUpgradeWithJournalNodes() { MiniQJMHACluster qjCluster = null; FileSystem fs = null; try { MiniQJMHACluster.Builder builder = new MiniQJMHACluster.Builder(conf); builder.GetDfsBuilder().NumDataNodes(0); qjCluster = builder.Build(); MiniDFSCluster cluster = qjCluster.GetDfsCluster(); // No upgrade is in progress at the moment. CheckJnPreviousDirExistence(qjCluster, false); CheckClusterPreviousDirExistence(cluster, false); AssertCTimesEqual(cluster); // Transition NN0 to active and do some FS ops. cluster.TransitionToActive(0); fs = HATestUtil.ConfigureFailoverFs(cluster, conf); NUnit.Framework.Assert.IsTrue(fs.Mkdirs(new Path("/foo1"))); // get the value of the committedTxnId in journal nodes long cidBeforeUpgrade = GetCommittedTxnIdValue(qjCluster); // Do the upgrade. Shut down NN1 and then restart NN0 with the upgrade // flag. cluster.ShutdownNameNode(1); cluster.GetNameNodeInfos()[0].SetStartOpt(HdfsServerConstants.StartupOption.Upgrade ); cluster.RestartNameNode(0, false); CheckNnPreviousDirExistence(cluster, 0, true); CheckNnPreviousDirExistence(cluster, 1, false); CheckJnPreviousDirExistence(qjCluster, true); NUnit.Framework.Assert.IsTrue(cidBeforeUpgrade <= GetCommittedTxnIdValue(qjCluster )); // NN0 should come up in the active state when given the -upgrade option, // so no need to transition it to active. NUnit.Framework.Assert.IsTrue(fs.Mkdirs(new Path("/foo2"))); // Restart NN0 without the -upgrade flag, to make sure that works. cluster.GetNameNodeInfos()[0].SetStartOpt(HdfsServerConstants.StartupOption.Regular ); cluster.RestartNameNode(0, false); // Make sure we can still do FS ops after upgrading. cluster.TransitionToActive(0); NUnit.Framework.Assert.IsTrue(fs.Mkdirs(new Path("/foo3"))); NUnit.Framework.Assert.IsTrue(GetCommittedTxnIdValue(qjCluster) > cidBeforeUpgrade ); // Now bootstrap the standby with the upgraded info. int rc = BootstrapStandby.Run(new string[] { "-force" }, cluster.GetConfiguration (1)); NUnit.Framework.Assert.AreEqual(0, rc); // Now restart NN1 and make sure that we can do ops against that as well. cluster.RestartNameNode(1); cluster.TransitionToStandby(0); cluster.TransitionToActive(1); NUnit.Framework.Assert.IsTrue(fs.Mkdirs(new Path("/foo4"))); AssertCTimesEqual(cluster); } finally { if (fs != null) { fs.Close(); } if (qjCluster != null) { qjCluster.Shutdown(); } } }