/// <exception cref="System.IO.IOException"/> public void Apply(JournalSet.JournalAndStream jas) { if (jas.IsActive()) { jas.GetCurrentStream().Flush(); } }
/// <exception cref="System.IO.IOException"/> public void Apply(JournalSet.JournalAndStream jas) { if (jas.IsActive()) { jas.GetCurrentStream().WriteRaw(data, offset, length); } }
/// <exception cref="System.IO.IOException"/> public void Apply(JournalSet.JournalAndStream jas) { if (jas.IsActive()) { jas.GetCurrentStream().Create(layoutVersion); } }
public virtual void TestSaveImageWhileSyncInProgress() { Configuration conf = GetConf(); NameNode.InitMetrics(conf, HdfsServerConstants.NamenodeRole.Namenode); DFSTestUtil.FormatNameNode(conf); FSNamesystem namesystem = FSNamesystem.LoadFromDisk(conf); try { FSImage fsimage = namesystem.GetFSImage(); FSEditLog editLog = fsimage.GetEditLog(); JournalSet.JournalAndStream jas = editLog.GetJournals()[0]; EditLogFileOutputStream spyElos = Org.Mockito.Mockito.Spy((EditLogFileOutputStream )jas.GetCurrentStream()); jas.SetCurrentStreamForTests(spyElos); AtomicReference <Exception> deferredException = new AtomicReference <Exception>(); CountDownLatch waitToEnterFlush = new CountDownLatch(1); Sharpen.Thread doAnEditThread = new _Thread_371(namesystem, deferredException, waitToEnterFlush ); Answer <Void> blockingFlush = new _Answer_388(doAnEditThread, waitToEnterFlush); // Signal to main thread that the edit thread is in the racy section Org.Mockito.Mockito.DoAnswer(blockingFlush).When(spyElos).Flush(); doAnEditThread.Start(); // Wait for the edit thread to get to the logsync unsynchronized section Log.Info("Main thread: waiting to enter flush..."); waitToEnterFlush.Await(); NUnit.Framework.Assert.IsNull(deferredException.Get()); Log.Info("Main thread: detected that logSync is in unsynchronized section."); Log.Info("Trying to enter safe mode."); Log.Info("This should block for " + BlockTime + "sec, since flush will sleep that long" ); long st = Time.Now(); namesystem.SetSafeMode(HdfsConstants.SafeModeAction.SafemodeEnter); long et = Time.Now(); Log.Info("Entered safe mode"); // Make sure we really waited for the flush to complete! NUnit.Framework.Assert.IsTrue(et - st > (BlockTime - 1) * 1000); // Once we're in safe mode, save namespace. namesystem.SaveNamespace(); Log.Info("Joining on edit thread..."); doAnEditThread.Join(); NUnit.Framework.Assert.IsNull(deferredException.Get()); // We did 3 edits: begin, txn, and end NUnit.Framework.Assert.AreEqual(3, VerifyEditLogs(namesystem, fsimage, NNStorage. GetFinalizedEditsFileName(1, 3), 1)); // after the save, just the one "begin" NUnit.Framework.Assert.AreEqual(1, VerifyEditLogs(namesystem, fsimage, NNStorage. GetInProgressEditsFileName(4), 4)); } finally { Log.Info("Closing nn"); if (namesystem != null) { namesystem.Close(); } } }
/// <exception cref="System.IO.IOException"/> public void Apply(JournalSet.JournalAndStream jas) { if (jas.IsActive()) { jas.CloseStream(); jas.GetManager().FinalizeLogSegment(firstTxId, lastTxId); } }
private EditLogFileOutputStream SpyOnStream(JournalSet.JournalAndStream jas) { EditLogFileOutputStream elos = (EditLogFileOutputStream)jas.GetCurrentStream(); EditLogFileOutputStream spyElos = Org.Mockito.Mockito.Spy(elos); jas.SetCurrentStreamForTests(spyElos); return(spyElos); }
internal virtual void Remove(JournalManager j) { JournalSet.JournalAndStream jasToRemove = null; foreach (JournalSet.JournalAndStream jas in journals) { if (jas.GetManager().Equals(j)) { jasToRemove = jas; break; } } if (jasToRemove != null) { jasToRemove.Abort(); journals.Remove(jasToRemove); } }
public virtual void TestSingleRequiredFailedEditsDirOnSetReadyToFlush() { // Set one of the edits dirs to be required. string[] editsDirs = cluster.GetConfiguration(0).GetTrimmedStrings(DFSConfigKeys. DfsNamenodeNameDirKey); ShutDownMiniCluster(); Configuration conf = new HdfsConfiguration(); conf.Set(DFSConfigKeys.DfsNamenodeEditsDirRequiredKey, editsDirs[0]); conf.SetInt(DFSConfigKeys.DfsNamenodeEditsDirMinimumKey, 0); conf.SetInt(DFSConfigKeys.DfsNamenodeCheckedVolumesMinimumKey, 0); SetUpMiniCluster(conf, true); NUnit.Framework.Assert.IsTrue(DoAnEdit()); // Invalidated the one required edits journal. InvalidateEditsDirAtIndex(0, false, false); JournalSet.JournalAndStream nonRequiredJas = GetJournalAndStream(1); EditLogFileOutputStream nonRequiredSpy = SpyOnStream(nonRequiredJas); // The NN has not terminated (no ExitException thrown) // ..and that the other stream is active. NUnit.Framework.Assert.IsTrue(nonRequiredJas.IsActive()); try { DoAnEdit(); NUnit.Framework.Assert.Fail("A single failure of a required journal should have halted the NN" ); } catch (RemoteException re) { NUnit.Framework.Assert.IsTrue(re.GetClassName().Contains("ExitException")); GenericTestUtils.AssertExceptionContains("setReadyToFlush failed for required journal" , re); } // Since the required directory failed setReadyToFlush, and that // directory was listed prior to the non-required directory, // we should not call setReadyToFlush on the non-required // directory. Regression test for HDFS-2874. Org.Mockito.Mockito.Verify(nonRequiredSpy, Org.Mockito.Mockito.Never()).SetReadyToFlush (); NUnit.Framework.Assert.IsFalse(nonRequiredJas.IsActive()); }
/// <summary> /// Replace the journal at index <code>index</code> with one that throws an /// exception on flush. /// </summary> /// <param name="index">the index of the journal to take offline.</param> /// <returns>the original <code>EditLogOutputStream</code> of the journal.</returns> /// <exception cref="System.IO.IOException"/> private void InvalidateEditsDirAtIndex(int index, bool failOnFlush, bool failOnWrite ) { JournalSet.JournalAndStream jas = GetJournalAndStream(index); EditLogFileOutputStream spyElos = SpyOnStream(jas); if (failOnWrite) { Org.Mockito.Mockito.DoThrow(new IOException("fail on write()")).When(spyElos).Write ((FSEditLogOp)Matchers.Any()); } if (failOnFlush) { Org.Mockito.Mockito.DoThrow(new IOException("fail on flush()")).When(spyElos).Flush (); } else { Org.Mockito.Mockito.DoThrow(new IOException("fail on setReadyToFlush()")).When(spyElos ).SetReadyToFlush(); } }
/// <exception cref="System.IO.IOException"/> public void Apply(JournalSet.JournalAndStream jas) { jas.GetManager().RecoverUnfinalizedSegments(); }
/// <exception cref="System.IO.IOException"/> public void Apply(JournalSet.JournalAndStream jas) { jas.GetManager().PurgeLogsOlderThan(minTxIdToKeep); }
internal virtual void Add(JournalManager j, bool required, bool shared) { JournalSet.JournalAndStream jas = new JournalSet.JournalAndStream(j, required, shared ); journals.AddItem(jas); }
/// <exception cref="System.IO.IOException"/> public void Apply(JournalSet.JournalAndStream jas) { jas.GetManager().SetOutputBufferCapacity(size); }
/// <exception cref="System.IO.IOException"/> public void Apply(JournalSet.JournalAndStream jas) { jas.Abort(); }
/// <exception cref="System.IO.IOException"/> public void Apply(JournalSet.JournalAndStream jas) { jas.CloseStream(); }
/// <exception cref="System.IO.IOException"/> public void Apply(JournalSet.JournalAndStream jas) { jas.StartLogSegment(txId, layoutVersion); }