/// <exception cref="System.IO.IOException"/> internal static void FlushAndCheckLength(EditLogFileOutputStream elos, long expectedLength ) { elos.SetReadyToFlush(); elos.FlushAndSync(true); NUnit.Framework.Assert.AreEqual(expectedLength, elos.GetFile().Length()); }
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(); } } }
private EditLogFileOutputStream SpyOnStream(JournalSet.JournalAndStream jas) { EditLogFileOutputStream elos = (EditLogFileOutputStream)jas.GetCurrentStream(); EditLogFileOutputStream spyElos = Org.Mockito.Mockito.Spy(elos); jas.SetCurrentStreamForTests(spyElos); return(spyElos); }
static TestSecurityTokenEditLog() { // This test creates NUM_THREADS threads and each thread does // 2 * NUM_TRANSACTIONS Transactions concurrently. // No need to fsync for the purposes of tests. This makes // the tests run much faster. EditLogFileOutputStream.SetShouldSkipFsyncForTesting(true); }
public virtual void TestEditLogFileOutputStreamCloseAbort() { // abort after a close should just ignore EditLogFileOutputStream editLogStream = new EditLogFileOutputStream(conf, TestEdits , 0); editLogStream.Close(); editLogStream.Abort(); }
public virtual void SetUp() { Called.Clear(); Configuration conf = new HdfsConfiguration(); conf.Set(DFSConfigKeys.DfsNamenodeInodeAttributesProviderKey, typeof(TestINodeAttributeProvider.MyAuthorizationProvider ).FullName); conf.SetBoolean(DFSConfigKeys.DfsNamenodeAclsEnabledKey, true); EditLogFileOutputStream.SetShouldSkipFsyncForTesting(true); miniDFS = new MiniDFSCluster.Builder(conf).Build(); }
public virtual void TestEditLogFileOutputStreamAbortAbort() { // abort after a close should just ignore EditLogFileOutputStream editLogStream = null; try { editLogStream = new EditLogFileOutputStream(conf, TestEdits, 0); editLogStream.Abort(); editLogStream.Abort(); } finally { IOUtils.Cleanup(null, editLogStream); } }
public virtual void TestEditLogFileOutputStreamCloseClose() { // close after a close should result in an IOE EditLogFileOutputStream editLogStream = new EditLogFileOutputStream(conf, TestEdits , 0); editLogStream.Close(); try { editLogStream.Close(); } catch (IOException ioe) { string msg = StringUtils.StringifyException(ioe); NUnit.Framework.Assert.IsTrue(msg, msg.Contains("Trying to use aborted output stream" )); } }
public virtual void TestRawWrites() { EditLogFileOutputStream elos = new EditLogFileOutputStream(conf, TestEdits, 0); try { byte[] small = new byte[] { 1, 2, 3, 4, 5, 8, 7 }; elos.Create(NameNodeLayoutVersion.CurrentLayoutVersion); // The first (small) write we make extends the file by 1 MB due to // preallocation. elos.WriteRaw(small, 0, small.Length); FlushAndCheckLength(elos, MinPreallocationLength); // The next small write we make goes into the area that was already // preallocated. elos.WriteRaw(small, 0, small.Length); FlushAndCheckLength(elos, MinPreallocationLength); // Now we write enough bytes so that we exceed the minimum preallocated // length. int BigWriteLength = 3 * MinPreallocationLength; byte[] buf = new byte[4096]; for (int i = 0; i < buf.Length; i++) { buf[i] = 0; } int total = BigWriteLength; while (total > 0) { int toWrite = (total > buf.Length) ? buf.Length : total; elos.WriteRaw(buf, 0, toWrite); total -= toWrite; } FlushAndCheckLength(elos, 4 * MinPreallocationLength); } finally { if (elos != null) { elos.Close(); } } }
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()); }
/// <exception cref="System.IO.IOException"/> public override EditLogOutputStream StartLogSegment(long txid, int layoutVersion) { lock (this) { try { currentInProgress = NNStorage.GetInProgressEditsFile(sd, txid); EditLogOutputStream stm = new EditLogFileOutputStream(conf, currentInProgress, outputBufferCapacity ); stm.Create(layoutVersion); return(stm); } catch (IOException e) { Log.Warn("Unable to start log segment " + txid + " at " + currentInProgress + ": " + e.GetLocalizedMessage()); errorReporter.ReportErrorOnFile(currentInProgress); throw; } } }
/// <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(); } }
public static void DisableFsync() { // No need to fsync for the purposes of tests. This makes // the tests run much faster. EditLogFileOutputStream.SetShouldSkipFsyncForTesting(true); }
/// <exception cref="System.IO.IOException"/> internal static void RunEditLogTest(TestNameNodeRecovery.EditLogTestSetup elts) { FilePath TestLogName = new FilePath(TestDir, "test_edit_log"); FSEditLogOp.OpInstanceCache cache = new FSEditLogOp.OpInstanceCache(); EditLogFileOutputStream elfos = null; EditLogFileInputStream elfis = null; try { elfos = new EditLogFileOutputStream(new Configuration(), TestLogName, 0); elfos.Create(NameNodeLayoutVersion.CurrentLayoutVersion); elts.AddTransactionsToLog(elfos, cache); elfos.SetReadyToFlush(); elfos.FlushAndSync(true); elfos.Close(); elfos = null; elfis = new EditLogFileInputStream(TestLogName); elfis.SetMaxOpSize(elts.GetMaxOpSize()); // reading through normally will get you an exception ICollection <long> validTxIds = elts.GetValidTxIds(); FSEditLogOp op = null; long prevTxId = 0; try { while (true) { op = elfis.NextOp(); if (op == null) { break; } Log.Debug("read txid " + op.txid); if (!validTxIds.Contains(op.GetTransactionId())) { NUnit.Framework.Assert.Fail("read txid " + op.GetTransactionId() + ", which we did not expect to find." ); } validTxIds.Remove(op.GetTransactionId()); prevTxId = op.GetTransactionId(); } if (elts.GetLastValidTxId() != -1) { NUnit.Framework.Assert.Fail("failed to throw IoException as expected"); } } catch (IOException) { if (elts.GetLastValidTxId() == -1) { NUnit.Framework.Assert.Fail("expected all transactions to be valid, but got exception " + "on txid " + prevTxId); } else { NUnit.Framework.Assert.AreEqual(prevTxId, elts.GetLastValidTxId()); } } if (elts.GetLastValidTxId() != -1) { // let's skip over the bad transaction op = null; prevTxId = 0; try { while (true) { op = elfis.NextValidOp(); if (op == null) { break; } prevTxId = op.GetTransactionId(); NUnit.Framework.Assert.IsTrue(validTxIds.Remove(op.GetTransactionId())); } } catch (Exception e) { NUnit.Framework.Assert.Fail("caught IOException while trying to skip over bad " + "transaction. message was " + e.Message + "\nstack trace\n" + StringUtils.StringifyException (e)); } } // We should have read every valid transaction. NUnit.Framework.Assert.IsTrue(validTxIds.IsEmpty()); } finally { IOUtils.Cleanup(Log, elfos, elfis); } }
static TestNameNodeRecovery() { recoverStartOpt.SetForce(MetaRecoveryContext.ForceAll); EditLogFileOutputStream.SetShouldSkipFsyncForTesting(true); }
static TestFileJournalManager() { // No need to fsync for the purposes of tests. This makes // the tests run much faster. EditLogFileOutputStream.SetShouldSkipFsyncForTesting(true); }