/// <exception cref="System.Exception"/> private void TestFailoverFinalizesAndReadsInProgress(bool partialTxAtEnd) { Configuration conf = new Configuration(); MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf).NnTopology(MiniDFSNNTopology .SimpleHATopology()).NumDataNodes(0).Build(); try { // Create a fake in-progress edit-log in the shared directory URI sharedUri = cluster.GetSharedEditsDir(0, 1); FilePath sharedDir = new FilePath(sharedUri.GetPath(), "current"); FSNamesystem fsn = cluster.GetNamesystem(0); FSImageTestUtil.CreateAbortedLogWithMkdirs(sharedDir, NumDirsInLog, 1, fsn.GetFSDirectory ().GetLastInodeId() + 1); AssertEditFiles(Sharpen.Collections.SingletonList(sharedUri), NNStorage.GetInProgressEditsFileName (1)); if (partialTxAtEnd) { FileOutputStream outs = null; try { FilePath editLogFile = new FilePath(sharedDir, NNStorage.GetInProgressEditsFileName (1)); outs = new FileOutputStream(editLogFile, true); outs.Write(new byte[] { unchecked ((int)(0x18)), unchecked ((int)(0x00)), unchecked ( (int)(0x00)), unchecked ((int)(0x00)) }); Log.Error("editLogFile = " + editLogFile); } finally { IOUtils.Cleanup(Log, outs); } } // Transition one of the NNs to active cluster.TransitionToActive(0); // In the transition to active, it should have read the log -- and // hence see one of the dirs we made in the fake log. string testPath = "/dir" + NumDirsInLog; NUnit.Framework.Assert.IsNotNull(cluster.GetNameNode(0).GetRpcServer().GetFileInfo (testPath)); // It also should have finalized that log in the shared directory and started // writing to a new one at the next txid. AssertEditFiles(Sharpen.Collections.SingletonList(sharedUri), NNStorage.GetFinalizedEditsFileName (1, NumDirsInLog + 1), NNStorage.GetInProgressEditsFileName(NumDirsInLog + 2)); } finally { cluster.Shutdown(); } }
/// <summary> /// Test cancellation of ongoing checkpoints when failover happens /// mid-checkpoint. /// </summary> /// <exception cref="System.Exception"/> public virtual void TestCheckpointCancellation() { cluster.TransitionToStandby(0); // Create an edit log in the shared edits dir with a lot // of mkdirs operations. This is solely so that the image is // large enough to take a non-trivial amount of time to load. // (only ~15MB) URI sharedUri = cluster.GetSharedEditsDir(0, 1); FilePath sharedDir = new FilePath(sharedUri.GetPath(), "current"); FilePath tmpDir = new FilePath(MiniDFSCluster.GetBaseDirectory(), "testCheckpointCancellation-tmp" ); FSNamesystem fsn = cluster.GetNamesystem(0); FSImageTestUtil.CreateAbortedLogWithMkdirs(tmpDir, NumDirsInLog, 3, fsn.GetFSDirectory ().GetLastInodeId() + 1); string fname = NNStorage.GetInProgressEditsFileName(3); new FilePath(tmpDir, fname).RenameTo(new FilePath(sharedDir, fname)); // Checkpoint as fast as we can, in a tight loop. cluster.GetConfiguration(1).SetInt(DFSConfigKeys.DfsNamenodeCheckpointPeriodKey, 0); cluster.RestartNameNode(1); nn1 = cluster.GetNameNode(1); cluster.TransitionToActive(0); bool canceledOne = false; for (int i = 0; i < 10 && !canceledOne; i++) { DoEdits(i * 10, i * 10 + 10); cluster.TransitionToStandby(0); cluster.TransitionToActive(1); cluster.TransitionToStandby(1); cluster.TransitionToActive(0); canceledOne = StandbyCheckpointer.GetCanceledCount() > 0; } NUnit.Framework.Assert.IsTrue(canceledOne); }