/// <exception cref="System.IO.IOException"/> internal static void DoMerge(CheckpointSignature sig, RemoteEditLogManifest manifest , bool loadImage, FSImage dstImage, FSNamesystem dstNamesystem) { NNStorage dstStorage = dstImage.GetStorage(); dstStorage.SetStorageInfo(sig); if (loadImage) { FilePath file = dstStorage.FindImageFile(NNStorage.NameNodeFile.Image, sig.mostRecentCheckpointTxId ); if (file == null) { throw new IOException("Couldn't find image file at txid " + sig.mostRecentCheckpointTxId + " even though it should have " + "just been downloaded"); } dstNamesystem.WriteLock(); try { dstImage.ReloadFromImageFile(file, dstNamesystem); } finally { dstNamesystem.WriteUnlock(); } dstNamesystem.ImageLoadComplete(); } // error simulation code for junit test CheckpointFaultInjector.GetInstance().DuringMerge(); Checkpointer.RollForwardByApplyingLogs(manifest, dstImage, dstNamesystem); // The following has the side effect of purging old fsimages/edit logs. dstImage.SaveFSImageInAllDirs(dstNamesystem, dstImage.GetLastAppliedTxId()); dstStorage.WriteAll(); }
/// <exception cref="System.IO.IOException"/> private int DownloadImage(NNStorage storage, NamenodeProtocol proxy) { // Load the newly formatted image, using all of the directories // (including shared edits) long imageTxId = proxy.GetMostRecentCheckpointTxId(); long curTxId = proxy.GetTransactionID(); FSImage image = new FSImage(conf); try { image.GetStorage().SetStorageInfo(storage); image.InitEditLog(HdfsServerConstants.StartupOption.Regular); System.Diagnostics.Debug.Assert(image.GetEditLog().IsOpenForRead(), "Expected edit log to be open for read" ); // Ensure that we have enough edits already in the shared directory to // start up from the last checkpoint on the active. if (!skipSharedEditsCheck && !CheckLogsAvailableForRead(image, imageTxId, curTxId )) { return(ErrCodeLogsUnavailable); } image.GetStorage().WriteTransactionIdFileToStorage(curTxId); // Download that checkpoint into our storage directories. MD5Hash hash = TransferFsImage.DownloadImageToStorage(otherHttpAddr, imageTxId, storage , true); image.SaveDigestAndRenameCheckpointImage(NNStorage.NameNodeFile.Image, imageTxId, hash); } catch (IOException ioe) { image.Close(); throw; } return(0); }
public virtual void TestManyLogsWithGaps() { FilePath f = new FilePath(TestEditLog.TestDir + "/manylogswithgaps"); NNStorage storage = TestEditLog.SetupEdits(Sharpen.Collections.SingletonList <URI> (f.ToURI()), 10); Storage.StorageDirectory sd = storage.DirIterator(NNStorage.NameNodeDirType.Edits ).Next(); long startGapTxId = 3 * TestEditLog.TxnsPerRoll + 1; long endGapTxId = 4 * TestEditLog.TxnsPerRoll; FilePath[] files = new FilePath(f, "current").ListFiles(new _FilenameFilter_324(startGapTxId , endGapTxId)); NUnit.Framework.Assert.AreEqual(1, files.Length); NUnit.Framework.Assert.IsTrue(files[0].Delete()); FileJournalManager jm = new FileJournalManager(conf, sd, storage); NUnit.Framework.Assert.AreEqual(startGapTxId - 1, GetNumberOfTransactions(jm, 1, true, true)); NUnit.Framework.Assert.AreEqual(0, GetNumberOfTransactions(jm, startGapTxId, true , true)); // rolled 10 times so there should be 11 files. NUnit.Framework.Assert.AreEqual(11 * TestEditLog.TxnsPerRoll - endGapTxId, GetNumberOfTransactions (jm, endGapTxId + 1, true, true)); }
/// <summary> /// Ensure that during downgrade the NN fails to load a fsimage with newer /// format. /// </summary> /// <exception cref="System.IO.IOException"/> public virtual void TestRejectNewFsImage() { Configuration conf = new Configuration(); MiniDFSCluster cluster = null; try { cluster = new MiniDFSCluster.Builder(conf).NumDataNodes(0).Build(); cluster.WaitActive(); DistributedFileSystem fs = cluster.GetFileSystem(); fs.SetSafeMode(HdfsConstants.SafeModeAction.SafemodeEnter); fs.SaveNamespace(); fs.SetSafeMode(HdfsConstants.SafeModeAction.SafemodeLeave); NNStorage storage = Org.Mockito.Mockito.Spy(cluster.GetNameNode().GetFSImage().GetStorage ()); int futureVersion = NameNodeLayoutVersion.CurrentLayoutVersion - 1; Org.Mockito.Mockito.DoReturn(futureVersion).When(storage).GetServiceLayoutVersion (); storage.WriteAll(); cluster.RestartNameNode(0, true, "-rollingUpgrade", "downgrade"); } finally { if (cluster != null) { cluster.Shutdown(); } } }
public virtual void SetUp() { conf = new HdfsConfiguration(); startOpt.SetClusterId(null); storage = new NNStorage(conf, Sharpen.Collections.EmptyList <URI>(), Sharpen.Collections .EmptyList <URI>()); }
public virtual void TestClientSideException() { Configuration conf = new HdfsConfiguration(); MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf).NumDataNodes(0).Build(); NNStorage mockStorage = Org.Mockito.Mockito.Mock <NNStorage>(); IList <FilePath> localPath = Collections.SingletonList(new FilePath("/xxxxx-does-not-exist/blah" )); try { Uri fsName = DFSUtil.GetInfoServer(cluster.GetNameNode().GetServiceRpcAddress(), conf, DFSUtil.GetHttpClientScheme(conf)).ToURL(); string id = "getimage=1&txid=0"; TransferFsImage.GetFileClient(fsName, id, localPath, mockStorage, false); NUnit.Framework.Assert.Fail("Didn't get an exception!"); } catch (IOException ioe) { Org.Mockito.Mockito.Verify(mockStorage).ReportErrorOnFile(localPath[0]); NUnit.Framework.Assert.IsTrue("Unexpected exception: " + StringUtils.StringifyException (ioe), ioe.Message.Contains("Unable to download to any storage")); } finally { cluster.Shutdown(); } }
public virtual void TestExcludeInProgressStreams() { FilePath f = new FilePath(TestEditLog.TestDir + "/excludeinprogressstreams"); // Don't close the edit log once the files have been set up. NNStorage storage = TestEditLog.SetupEdits(Sharpen.Collections.SingletonList <URI> (f.ToURI()), 10, false); Storage.StorageDirectory sd = storage.DirIterator(NNStorage.NameNodeDirType.Edits ).Next(); FileJournalManager jm = new FileJournalManager(conf, sd, storage); // If we exclude the in-progess stream, we should only have 100 tx. NUnit.Framework.Assert.AreEqual(100, GetNumberOfTransactions(jm, 1, false, false) ); EditLogInputStream elis = GetJournalInputStream(jm, 90, false); try { FSEditLogOp lastReadOp = null; while ((lastReadOp = elis.ReadOp()) != null) { NUnit.Framework.Assert.IsTrue(lastReadOp.GetTransactionId() <= 100); } } finally { IOUtils.Cleanup(Log, elis); } }
public virtual void TestSharedEditsMissingLogs() { RemoveStandbyNameDirs(); CheckpointSignature sig = nn0.GetRpcServer().RollEditLog(); NUnit.Framework.Assert.AreEqual(3, sig.GetCurSegmentTxId()); // Should have created edits_1-2 in shared edits dir URI editsUri = cluster.GetSharedEditsDir(0, 1); FilePath editsDir = new FilePath(editsUri); FilePath editsSegment = new FilePath(new FilePath(editsDir, "current"), NNStorage .GetFinalizedEditsFileName(1, 2)); GenericTestUtils.AssertExists(editsSegment); // Delete the segment. NUnit.Framework.Assert.IsTrue(editsSegment.Delete()); // Trying to bootstrap standby should now fail since the edit // logs aren't available in the shared dir. GenericTestUtils.LogCapturer logs = GenericTestUtils.LogCapturer.CaptureLogs(LogFactory .GetLog(typeof(BootstrapStandby))); try { int rc = BootstrapStandby.Run(new string[] { "-force" }, cluster.GetConfiguration (1)); NUnit.Framework.Assert.AreEqual(BootstrapStandby.ErrCodeLogsUnavailable, rc); } finally { logs.StopCapturing(); } GenericTestUtils.AssertMatches(logs.GetOutput(), "FATAL.*Unable to read transaction ids 1-3 from the configured shared" ); }
/// <exception cref="System.IO.IOException"/> public override void FinalizeLogSegment(long firstTxId, long lastTxId) { lock (this) { FilePath inprogressFile = NNStorage.GetInProgressEditsFile(sd, firstTxId); FilePath dstFile = NNStorage.GetFinalizedEditsFile(sd, firstTxId, lastTxId); Log.Info("Finalizing edits file " + inprogressFile + " -> " + dstFile); Preconditions.CheckState(!dstFile.Exists(), "Can't finalize edits file " + inprogressFile + " since finalized file " + "already exists"); try { NativeIO.RenameTo(inprogressFile, dstFile); } catch (IOException e) { errorReporter.ReportErrorOnFile(dstFile); throw new InvalidOperationException("Unable to finalize edits file " + inprogressFile , e); } if (inprogressFile.Equals(currentInProgress)) { currentInProgress = null; } } }
/// <summary>verify that edits log and fsimage are in different directories and of a correct size /// </summary> private void VerifyDifferentDirs(FSImage img, long expectedImgSize, long expectedEditsSize ) { Storage.StorageDirectory sd = null; for (IEnumerator <Storage.StorageDirectory> it = img.GetStorage().DirIterator(); it .HasNext();) { sd = it.Next(); if (sd.GetStorageDirType().IsOfType(NNStorage.NameNodeDirType.Image)) { img.GetStorage(); FilePath imf = NNStorage.GetStorageFile(sd, NNStorage.NameNodeFile.Image, 0); Log.Info("--image file " + imf.GetAbsolutePath() + "; len = " + imf.Length() + "; expected = " + expectedImgSize); NUnit.Framework.Assert.AreEqual(expectedImgSize, imf.Length()); } else { if (sd.GetStorageDirType().IsOfType(NNStorage.NameNodeDirType.Edits)) { img.GetStorage(); FilePath edf = NNStorage.GetStorageFile(sd, NNStorage.NameNodeFile.Edits, 0); Log.Info("-- edits file " + edf.GetAbsolutePath() + "; len = " + edf.Length() + "; expected = " + expectedEditsSize); NUnit.Framework.Assert.AreEqual(expectedEditsSize, edf.Length()); } else { NUnit.Framework.Assert.Fail("Image/Edits directories are not different"); } } } }
/// <summary> /// Confirm that FSImage files in all StorageDirectory are the same, /// and non-empty, and there are the expected number of them. /// </summary> /// <param name="fsn">- the FSNamesystem being checked.</param> /// <param name="numImageDirs">- the configured number of StorageDirectory of type IMAGE. /// </param> /// <returns>- the md5 hash of the most recent FSImage files, which must all be the same. /// </returns> /// <exception cref="System.Exception"> /// if image files are empty or different, /// if less than two StorageDirectory are provided, or if the /// actual number of StorageDirectory is less than configured. /// </exception> public static string CheckImages(FSNamesystem fsn, int numImageDirs) { NNStorage stg = fsn.GetFSImage().GetStorage(); //any failed StorageDirectory is removed from the storageDirs list NUnit.Framework.Assert.AreEqual("Some StorageDirectories failed Upgrade", numImageDirs , stg.GetNumStorageDirs(NNStorage.NameNodeDirType.Image)); NUnit.Framework.Assert.IsTrue("Not enough fsimage copies in MiniDFSCluster " + "to test parallel write" , numImageDirs > 1); // List of "current/" directory from each SD IList <FilePath> dirs = FSImageTestUtil.GetCurrentDirs(stg, NNStorage.NameNodeDirType .Image); // across directories, all files with same names should be identical hashes FSImageTestUtil.AssertParallelFilesAreIdentical(dirs, Sharpen.Collections.EmptySet <string>()); FSImageTestUtil.AssertSameNewestImage(dirs); // Return the hash of the newest image file Storage.StorageDirectory firstSd = stg.DirIterator(NNStorage.NameNodeDirType.Image ).Next(); FilePath latestImage = FSImageTestUtil.FindLatestImageFile(firstSd); string md5 = FSImageTestUtil.GetImageFileMD5IgnoringTxId(latestImage); System.Console.Error.WriteLine("md5 of " + latestImage + ": " + md5); return(md5); }
public virtual void TestDoPreUpgradeIOError() { FilePath storageDir = new FilePath(TestEditLog.TestDir, "preupgradeioerror"); IList <URI> editUris = Sharpen.Collections.SingletonList(storageDir.ToURI()); NNStorage storage = TestEditLog.SetupEdits(editUris, 5); Storage.StorageDirectory sd = storage.DirIterator(NNStorage.NameNodeDirType.Edits ).Next(); NUnit.Framework.Assert.IsNotNull(sd); // Change storage directory so that renaming current to previous.tmp fails. FileUtil.SetWritable(storageDir, false); FileJournalManager jm = null; try { jm = new FileJournalManager(conf, sd, storage); exception.Expect(typeof(IOException)); if (NativeCodeLoader.IsNativeCodeLoaded()) { exception.ExpectMessage("failure in native rename"); } jm.DoPreUpgrade(); } finally { IOUtils.Cleanup(Log, jm); // Restore permissions on storage directory and make sure we can delete. FileUtil.SetWritable(storageDir, true); FileUtil.FullyDelete(storageDir); } }
public virtual void TestStartup() { Configuration conf = new Configuration(); HAUtil.SetAllowStandbyReads(conf, true); MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf).NnTopology(MiniDFSNNTopology .SimpleHATopology()).NumDataNodes(0).Build(); try { // During HA startup, both nodes should be in // standby and we shouldn't have any edits files // in any edits directory! IList <URI> allDirs = Lists.NewArrayList(); Sharpen.Collections.AddAll(allDirs, cluster.GetNameDirs(0)); Sharpen.Collections.AddAll(allDirs, cluster.GetNameDirs(1)); allDirs.AddItem(cluster.GetSharedEditsDir(0, 1)); AssertNoEditFiles(allDirs); // Set the first NN to active, make sure it creates edits // in its own dirs and the shared dir. The standby // should still have no edits! cluster.TransitionToActive(0); AssertEditFiles(cluster.GetNameDirs(0), NNStorage.GetInProgressEditsFileName(1)); AssertEditFiles(Sharpen.Collections.SingletonList(cluster.GetSharedEditsDir(0, 1) ), NNStorage.GetInProgressEditsFileName(1)); AssertNoEditFiles(cluster.GetNameDirs(1)); cluster.GetNameNode(0).GetRpcServer().Mkdirs("/test", FsPermission.CreateImmutable ((short)0x1ed), true); // Restarting the standby should not finalize any edits files // in the shared directory when it starts up! cluster.RestartNameNode(1); AssertEditFiles(cluster.GetNameDirs(0), NNStorage.GetInProgressEditsFileName(1)); AssertEditFiles(Sharpen.Collections.SingletonList(cluster.GetSharedEditsDir(0, 1) ), NNStorage.GetInProgressEditsFileName(1)); AssertNoEditFiles(cluster.GetNameDirs(1)); // Additionally it should not have applied any in-progress logs // at start-up -- otherwise, it would have read half-way into // the current log segment, and on the next roll, it would have to // either replay starting in the middle of the segment (not allowed) // or double-replay the edits (incorrect). NUnit.Framework.Assert.IsNull(NameNodeAdapter.GetFileInfo(cluster.GetNameNode(1), "/test", true)); cluster.GetNameNode(0).GetRpcServer().Mkdirs("/test2", FsPermission.CreateImmutable ((short)0x1ed), true); // If we restart NN0, it'll come back as standby, and we can // transition NN1 to active and make sure it reads edits correctly at this point. cluster.RestartNameNode(0); cluster.TransitionToActive(1); // NN1 should have both the edits that came before its restart, and the edits that // came after its restart. NUnit.Framework.Assert.IsNotNull(NameNodeAdapter.GetFileInfo(cluster.GetNameNode( 1), "/test", true)); NUnit.Framework.Assert.IsNotNull(NameNodeAdapter.GetFileInfo(cluster.GetNameNode( 1), "/test2", true)); } finally { cluster.Shutdown(); } }
public virtual void TestPurgeLogs() { for (int txid = 1; txid <= 5; txid++) { QJMTestUtil.WriteSegment(cluster, qjm, txid, 1, true); } FilePath curDir = cluster.GetCurrentDir(0, QJMTestUtil.Jid); GenericTestUtils.AssertGlobEquals(curDir, "edits_.*", NNStorage.GetFinalizedEditsFileName (1, 1), NNStorage.GetFinalizedEditsFileName(2, 2), NNStorage.GetFinalizedEditsFileName (3, 3), NNStorage.GetFinalizedEditsFileName(4, 4), NNStorage.GetFinalizedEditsFileName (5, 5)); FilePath paxosDir = new FilePath(curDir, "paxos"); GenericTestUtils.AssertExists(paxosDir); // Create new files in the paxos directory, which should get purged too. NUnit.Framework.Assert.IsTrue(new FilePath(paxosDir, "1").CreateNewFile()); NUnit.Framework.Assert.IsTrue(new FilePath(paxosDir, "3").CreateNewFile()); GenericTestUtils.AssertGlobEquals(paxosDir, "\\d+", "1", "3"); // Create some temporary files of the sort that are used during recovery. NUnit.Framework.Assert.IsTrue(new FilePath(curDir, "edits_inprogress_0000000000000000001.epoch=140" ).CreateNewFile()); NUnit.Framework.Assert.IsTrue(new FilePath(curDir, "edits_inprogress_0000000000000000002.empty" ).CreateNewFile()); qjm.PurgeLogsOlderThan(3); // Log purging is asynchronous, so we have to wait for the calls // to be sent and respond before verifying. WaitForAllPendingCalls(qjm.GetLoggerSetForTests()); // Older edits should be purged GenericTestUtils.AssertGlobEquals(curDir, "edits_.*", NNStorage.GetFinalizedEditsFileName (3, 3), NNStorage.GetFinalizedEditsFileName(4, 4), NNStorage.GetFinalizedEditsFileName (5, 5)); // Older paxos files should be purged GenericTestUtils.AssertGlobEquals(paxosDir, "\\d+", "3"); }
/// <summary>Requests that the NameNode download an image from this node.</summary> /// <remarks> /// Requests that the NameNode download an image from this node. Allows for /// optional external cancelation. /// </remarks> /// <param name="fsName">the http address for the remote NN</param> /// <param name="conf">Configuration</param> /// <param name="storage">the storage directory to transfer the image from</param> /// <param name="nnf">the NameNodeFile type of the image</param> /// <param name="txid">the transaction ID of the image to be uploaded</param> /// <param name="canceler">optional canceler to check for abort of upload</param> /// <exception cref="System.IO.IOException">if there is an I/O error or cancellation</exception> public static void UploadImageFromStorage(Uri fsName, Configuration conf, NNStorage storage, NNStorage.NameNodeFile nnf, long txid, Canceler canceler) { Uri url = new Uri(fsName, ImageServlet.PathSpec); long startTime = Time.MonotonicNow(); try { UploadImage(url, conf, storage, nnf, txid, canceler); } catch (TransferFsImage.HttpPutFailedException e) { if (e.GetResponseCode() == HttpServletResponse.ScConflict) { // this is OK - this means that a previous attempt to upload // this checkpoint succeeded even though we thought it failed. Log.Info("Image upload with txid " + txid + " conflicted with a previous image upload to the " + "same NameNode. Continuing...", e); return; } else { throw; } } double xferSec = Math.Max(((float)(Time.MonotonicNow() - startTime)) / 1000.0, 0.001 ); Log.Info("Uploaded image with txid " + txid + " to namenode at " + fsName + " in " + xferSec + " seconds"); }
public virtual void TestInprogressRecoveryAll() { FilePath f1 = new FilePath(TestEditLog.TestDir + "/failalltest0"); FilePath f2 = new FilePath(TestEditLog.TestDir + "/failalltest1"); FilePath f3 = new FilePath(TestEditLog.TestDir + "/failalltest2"); IList <URI> editUris = ImmutableList.Of(f1.ToURI(), f2.ToURI(), f3.ToURI()); // abort after the 5th roll NNStorage storage = TestEditLog.SetupEdits(editUris, 5, new TestEditLog.AbortSpec (5, 0), new TestEditLog.AbortSpec(5, 1), new TestEditLog.AbortSpec(5, 2)); IEnumerator <Storage.StorageDirectory> dirs = storage.DirIterator(NNStorage.NameNodeDirType .Edits); Storage.StorageDirectory sd = dirs.Next(); FileJournalManager jm = new FileJournalManager(conf, sd, storage); NUnit.Framework.Assert.AreEqual(5 * TestEditLog.TxnsPerRoll + TestEditLog.TxnsPerFail , GetNumberOfTransactions(jm, 1, true, false)); sd = dirs.Next(); jm = new FileJournalManager(conf, sd, storage); NUnit.Framework.Assert.AreEqual(5 * TestEditLog.TxnsPerRoll + TestEditLog.TxnsPerFail , GetNumberOfTransactions(jm, 1, true, false)); sd = dirs.Next(); jm = new FileJournalManager(conf, sd, storage); NUnit.Framework.Assert.AreEqual(5 * TestEditLog.TxnsPerRoll + TestEditLog.TxnsPerFail , GetNumberOfTransactions(jm, 1, true, false)); }
public virtual void TestRollbackCommand() { Configuration conf = new HdfsConfiguration(); MiniDFSCluster cluster = null; Path foo = new Path("/foo"); Path bar = new Path("/bar"); try { cluster = new MiniDFSCluster.Builder(conf).NumDataNodes(0).Build(); cluster.WaitActive(); DistributedFileSystem dfs = cluster.GetFileSystem(); DFSAdmin dfsadmin = new DFSAdmin(conf); dfs.Mkdirs(foo); // start rolling upgrade dfs.SetSafeMode(HdfsConstants.SafeModeAction.SafemodeEnter); NUnit.Framework.Assert.AreEqual(0, dfsadmin.Run(new string[] { "-rollingUpgrade", "prepare" })); dfs.SetSafeMode(HdfsConstants.SafeModeAction.SafemodeLeave); // create new directory dfs.Mkdirs(bar); // check NNStorage NNStorage storage = cluster.GetNamesystem().GetFSImage().GetStorage(); CheckNNStorage(storage, 3, -1); } finally { // (startSegment, mkdir, endSegment) if (cluster != null) { cluster.Shutdown(); } } NameNode nn = null; try { nn = NameNode.CreateNameNode(new string[] { "-rollingUpgrade", "rollback" }, conf ); // make sure /foo is still there, but /bar is not INode fooNode = nn.GetNamesystem().GetFSDirectory().GetINode4Write(foo.ToString() ); NUnit.Framework.Assert.IsNotNull(fooNode); INode barNode = nn.GetNamesystem().GetFSDirectory().GetINode4Write(bar.ToString() ); NUnit.Framework.Assert.IsNull(barNode); // check the details of NNStorage NNStorage storage = nn.GetNamesystem().GetFSImage().GetStorage(); // (startSegment, upgrade marker, mkdir, endSegment) CheckNNStorage(storage, 3, 7); } finally { if (nn != null) { nn.Stop(); nn.Join(); } } }
public bool Accept(FilePath dir, string name) { if (name.StartsWith(NNStorage.GetFinalizedEditsFileName(startGapTxId, endGapTxId) )) { return(true); } return(false); }
public virtual void TestEditLogRolling() { // start a cluster Configuration conf = new HdfsConfiguration(); MiniDFSCluster cluster = null; FileSystem fileSys = null; AtomicReference <Exception> caughtErr = new AtomicReference <Exception>(); try { cluster = new MiniDFSCluster.Builder(conf).NumDataNodes(NumDataNodes).Build(); cluster.WaitActive(); fileSys = cluster.GetFileSystem(); NamenodeProtocols nn = cluster.GetNameNode().GetRpcServer(); FSImage fsimage = cluster.GetNamesystem().GetFSImage(); Storage.StorageDirectory sd = fsimage.GetStorage().GetStorageDir(0); StartTransactionWorkers(nn, caughtErr); long previousLogTxId = 1; for (int i = 0; i < NumRolls && caughtErr.Get() == null; i++) { try { Sharpen.Thread.Sleep(20); } catch (Exception) { } Log.Info("Starting roll " + i + "."); CheckpointSignature sig = nn.RollEditLog(); long nextLog = sig.curSegmentTxId; string logFileName = NNStorage.GetFinalizedEditsFileName(previousLogTxId, nextLog - 1); previousLogTxId += VerifyEditLogs(cluster.GetNamesystem(), fsimage, logFileName, previousLogTxId); NUnit.Framework.Assert.AreEqual(previousLogTxId, nextLog); FilePath expectedLog = NNStorage.GetInProgressEditsFile(sd, previousLogTxId); NUnit.Framework.Assert.IsTrue("Expect " + expectedLog + " to exist", expectedLog. Exists()); } } finally { StopTransactionWorkers(); if (caughtErr.Get() != null) { throw new RuntimeException(caughtErr.Get()); } if (fileSys != null) { fileSys.Close(); } if (cluster != null) { cluster.Shutdown(); } } }
/// <summary>This is called when using bootstrapStandby for HA upgrade.</summary> /// <remarks> /// This is called when using bootstrapStandby for HA upgrade. The SBN should /// also create previous directory so that later when it starts, it understands /// that the cluster is in the upgrade state. This function renames the old /// current directory to previous.tmp. /// </remarks> /// <exception cref="System.IO.IOException"/> private bool DoPreUpgrade(NNStorage storage, NamespaceInfo nsInfo) { bool isFormatted = false; IDictionary <Storage.StorageDirectory, Storage.StorageState> dataDirStates = new Dictionary <Storage.StorageDirectory, Storage.StorageState>(); try { isFormatted = FSImage.RecoverStorageDirs(HdfsServerConstants.StartupOption.Upgrade , storage, dataDirStates); if (dataDirStates.Values.Contains(Storage.StorageState.NotFormatted)) { // recoverStorageDirs returns true if there is a formatted directory isFormatted = false; System.Console.Error.WriteLine("The original storage directory is not formatted." ); } } catch (InconsistentFSStateException e) { // if the storage is in a bad state, Log.Warn("The storage directory is in an inconsistent state", e); } finally { storage.UnlockAll(); } // if there is InconsistentFSStateException or the storage is not formatted, // format the storage. Although this format is done through the new // software, since in HA setup the SBN is rolled back through // "-bootstrapStandby", we should still be fine. if (!isFormatted && !Format(storage, nsInfo)) { return(false); } // make sure there is no previous directory FSImage.CheckUpgrade(storage); // Do preUpgrade for each directory for (IEnumerator <Storage.StorageDirectory> it = storage.DirIterator(false); it.HasNext ();) { Storage.StorageDirectory sd = it.Next(); try { NNUpgradeUtil.RenameCurToTmp(sd); } catch (IOException e) { Log.Error("Failed to move aside pre-upgrade storage " + "in image directory " + sd .GetRoot(), e); throw; } } storage.SetStorageInfo(nsInfo); storage.SetBlockPoolID(nsInfo.GetBlockPoolID()); return(true); }
/// <exception cref="System.IO.IOException"/> private void DoUpgrade(NNStorage storage) { for (IEnumerator <Storage.StorageDirectory> it = storage.DirIterator(false); it.HasNext ();) { Storage.StorageDirectory sd = it.Next(); NNUpgradeUtil.DoUpgrade(sd, storage); } }
/// <exception cref="System.IO.IOException"/> private static NNStorage MockStorageForDirs(params Storage.StorageDirectory[] mockDirs ) { NNStorage mockStorage = Org.Mockito.Mockito.Mock <NNStorage>(); Org.Mockito.Mockito.DoAnswer(new _Answer_407(mockDirs)).When(mockStorage).InspectStorageDirs (Org.Mockito.Mockito.AnyObject <FSImageStorageInspector>()); return(mockStorage); }
/// <exception cref="System.IO.IOException"/> internal static void DownloadEditsToStorage(Uri fsName, RemoteEditLog log, NNStorage dstStorage) { System.Diagnostics.Debug.Assert(log.GetStartTxId() > 0 && log.GetEndTxId() > 0, "bad log: " + log); string fileid = ImageServlet.GetParamStringForLog(log, dstStorage); string finalFileName = NNStorage.GetFinalizedEditsFileName(log.GetStartTxId(), log .GetEndTxId()); IList <FilePath> finalFiles = dstStorage.GetFiles(NNStorage.NameNodeDirType.Edits, finalFileName); System.Diagnostics.Debug.Assert(!finalFiles.IsEmpty(), "No checkpoint targets."); foreach (FilePath f in finalFiles) { if (f.Exists() && FileUtil.CanRead(f)) { Log.Info("Skipping download of remote edit log " + log + " since it already is stored locally at " + f); return; } else { if (Log.IsDebugEnabled()) { Log.Debug("Dest file: " + f); } } } long milliTime = Time.MonotonicNow(); string tmpFileName = NNStorage.GetTemporaryEditsFileName(log.GetStartTxId(), log. GetEndTxId(), milliTime); IList <FilePath> tmpFiles = dstStorage.GetFiles(NNStorage.NameNodeDirType.Edits, tmpFileName ); GetFileClient(fsName, fileid, tmpFiles, dstStorage, false); Log.Info("Downloaded file " + tmpFiles[0].GetName() + " size " + finalFiles[0].Length () + " bytes."); CheckpointFaultInjector.GetInstance().BeforeEditsRename(); foreach (Storage.StorageDirectory sd in dstStorage.DirIterable(NNStorage.NameNodeDirType .Edits)) { FilePath tmpFile = NNStorage.GetTemporaryEditsFile(sd, log.GetStartTxId(), log.GetEndTxId (), milliTime); FilePath finalizedFile = NNStorage.GetFinalizedEditsFile(sd, log.GetStartTxId(), log.GetEndTxId()); if (Log.IsDebugEnabled()) { Log.Debug("Renaming " + tmpFile + " to " + finalizedFile); } bool success = tmpFile.RenameTo(finalizedFile); if (!success) { Log.Warn("Unable to rename edits file from " + tmpFile + " to " + finalizedFile); } } }
/// <exception cref="System.Exception"/> private static void WaitForLogRollInSharedDir(MiniDFSCluster cluster, long startTxId ) { URI sharedUri = cluster.GetSharedEditsDir(0, 1); FilePath sharedDir = new FilePath(sharedUri.GetPath(), "current"); FilePath expectedLog = new FilePath(sharedDir, NNStorage.GetInProgressEditsFileName (startTxId)); GenericTestUtils.WaitFor(new _Supplier_153(expectedLog), 100, 10000); }
/// <returns> /// a List which contains the "current" dir for each storage /// directory of the given type. /// </returns> public static IList <FilePath> GetCurrentDirs(NNStorage storage, NNStorage.NameNodeDirType type) { IList <FilePath> ret = Lists.NewArrayList(); foreach (Storage.StorageDirectory sd in storage.DirIterable(type)) { ret.AddItem(sd.GetCurrentDir()); } return(ret); }
/// <exception cref="System.IO.IOException"/> internal virtual bool DoRecovery() { Log.Debug("Performing recovery in " + latestNameSD + " and " + latestEditsSD); bool needToSave = false; FilePath curFile = NNStorage.GetStorageFile(latestNameSD, NNStorage.NameNodeFile. Image); FilePath ckptFile = NNStorage.GetStorageFile(latestNameSD, NNStorage.NameNodeFile .ImageNew); // // If we were in the midst of a checkpoint // if (ckptFile.Exists()) { needToSave = true; if (NNStorage.GetStorageFile(latestEditsSD, NNStorage.NameNodeFile.EditsNew).Exists ()) { // // checkpointing migth have uploaded a new // merged image, but we discard it here because we are // not sure whether the entire merged image was uploaded // before the namenode crashed. // if (!ckptFile.Delete()) { throw new IOException("Unable to delete " + ckptFile); } } else { // // checkpointing was in progress when the namenode // shutdown. The fsimage.ckpt was created and the edits.new // file was moved to edits. We complete that checkpoint by // moving fsimage.new to fsimage. There is no need to // update the fstime file here. renameTo fails on Windows // if the destination file already exists. // if (!ckptFile.RenameTo(curFile)) { if (!curFile.Delete()) { Log.Warn("Unable to delete dir " + curFile + " before rename"); } if (!ckptFile.RenameTo(curFile)) { throw new IOException("Unable to rename " + ckptFile + " to " + curFile); } } } } return(needToSave); }
/// <summary>Find an edits file spanning the given transaction ID range.</summary> /// <remarks> /// Find an edits file spanning the given transaction ID range. /// If no such file exists, an exception is thrown. /// </remarks> /// <exception cref="System.IO.IOException"/> internal virtual FilePath FindFinalizedEditsFile(long startTxId, long endTxId) { FilePath ret = new FilePath(sd.GetCurrentDir(), NNStorage.GetFinalizedEditsFileName (startTxId, endTxId)); if (!ret.Exists()) { throw new IOException("No edits file for range " + startTxId + "-" + endTxId); } return(ret); }
public virtual void TestNoLogs() { TestNNStorageRetentionManager.TestCaseDescription tc = new TestNNStorageRetentionManager.TestCaseDescription (this); tc.AddRoot("/foo1", NNStorage.NameNodeDirType.ImageAndEdits); tc.AddImage("/foo1/current/" + NNStorage.GetImageFileName(100), true); tc.AddImage("/foo1/current/" + NNStorage.GetImageFileName(200), true); tc.AddImage("/foo1/current/" + NNStorage.GetImageFileName(300), false); tc.AddImage("/foo1/current/" + NNStorage.GetImageFileName(400), false); RunTest(tc); }
public virtual void TestChangeWritersLogsInSync() { QJMTestUtil.WriteSegment(cluster, qjm, 1, 3, false); QJMTestUtil.AssertExistsInQuorum(cluster, NNStorage.GetInProgressEditsFileName(1) ); // Make a new QJM qjm = CloseLater(new QuorumJournalManager(conf, cluster.GetQuorumJournalURI(QJMTestUtil .Jid), QJMTestUtil.FakeNsinfo)); qjm.RecoverUnfinalizedSegments(); CheckRecovery(cluster, 1, 3); }
private void CheckJNStorage(FilePath dir, long discardStartTxId, long discardEndTxId ) { FilePath finalizedEdits = new FilePath(dir, NNStorage.GetFinalizedEditsFileName(1 , discardStartTxId - 1)); NUnit.Framework.Assert.IsTrue(finalizedEdits.Exists()); FilePath trashEdits = new FilePath(dir, NNStorage.GetFinalizedEditsFileName(discardStartTxId , discardEndTxId) + ".trash"); NUnit.Framework.Assert.IsTrue(trashEdits.Exists()); }