public virtual void TestSimpleRecovery() { NamespaceInfo nsi = NewNSInfo(); BookKeeperJournalManager bkjm = new BookKeeperJournalManager(conf, BKJMUtil.CreateJournalURI ("/hdfsjournal-simplerecovery"), nsi); bkjm.Format(nsi); EditLogOutputStream @out = bkjm.StartLogSegment(1, NameNodeLayoutVersion.CurrentLayoutVersion ); for (long i = 1; i <= 100; i++) { FSEditLogOp op = FSEditLogTestUtil.GetNoOpInstance(); op.SetTransactionId(i); @out.Write(op); } @out.SetReadyToFlush(); @out.Flush(); @out.Abort(); @out.Close(); NUnit.Framework.Assert.IsNull(zkc.Exists(bkjm.FinalizedLedgerZNode(1, 100), false )); NUnit.Framework.Assert.IsNotNull(zkc.Exists(bkjm.InprogressZNode(1), false)); bkjm.RecoverUnfinalizedSegments(); NUnit.Framework.Assert.IsNotNull(zkc.Exists(bkjm.FinalizedLedgerZNode(1, 100), false )); NUnit.Framework.Assert.IsNull(zkc.Exists(bkjm.InprogressZNode(1), false)); }
public virtual void TestNumberOfTransactionsWithGaps() { NamespaceInfo nsi = NewNSInfo(); BookKeeperJournalManager bkjm = new BookKeeperJournalManager(conf, BKJMUtil.CreateJournalURI ("/hdfsjournal-gaps"), nsi); bkjm.Format(nsi); long txid = 1; for (long i = 0; i < 3; i++) { long start = txid; EditLogOutputStream @out = bkjm.StartLogSegment(start, NameNodeLayoutVersion.CurrentLayoutVersion ); for (long j = 1; j <= DefaultSegmentSize; j++) { FSEditLogOp op = FSEditLogTestUtil.GetNoOpInstance(); op.SetTransactionId(txid++); @out.Write(op); } @out.Close(); bkjm.FinalizeLogSegment(start, txid - 1); NUnit.Framework.Assert.IsNotNull(zkc.Exists(bkjm.FinalizedLedgerZNode(start, txid - 1), false)); } zkc.Delete(bkjm.FinalizedLedgerZNode(DefaultSegmentSize + 1, DefaultSegmentSize * 2), -1); long numTrans = bkjm.GetNumberOfTransactions(1, true); NUnit.Framework.Assert.AreEqual(DefaultSegmentSize, numTrans); try { numTrans = bkjm.GetNumberOfTransactions(DefaultSegmentSize + 1, true); NUnit.Framework.Assert.Fail("Should have thrown corruption exception by this point" ); } catch (JournalManager.CorruptionException) { } // if we get here, everything is going good numTrans = bkjm.GetNumberOfTransactions((DefaultSegmentSize * 2) + 1, true); NUnit.Framework.Assert.AreEqual(DefaultSegmentSize, numTrans); }
public virtual void TestNumberOfTransactionsWithInprogressAtEnd() { NamespaceInfo nsi = NewNSInfo(); BookKeeperJournalManager bkjm = new BookKeeperJournalManager(conf, BKJMUtil.CreateJournalURI ("/hdfsjournal-inprogressAtEnd"), nsi); bkjm.Format(nsi); long txid = 1; for (long i = 0; i < 3; i++) { long start = txid; EditLogOutputStream @out = bkjm.StartLogSegment(start, NameNodeLayoutVersion.CurrentLayoutVersion ); for (long j = 1; j <= DefaultSegmentSize; j++) { FSEditLogOp op = FSEditLogTestUtil.GetNoOpInstance(); op.SetTransactionId(txid++); @out.Write(op); } @out.Close(); bkjm.FinalizeLogSegment(start, (txid - 1)); NUnit.Framework.Assert.IsNotNull(zkc.Exists(bkjm.FinalizedLedgerZNode(start, (txid - 1)), false)); } long start_1 = txid; EditLogOutputStream out_1 = bkjm.StartLogSegment(start_1, NameNodeLayoutVersion.CurrentLayoutVersion ); for (long j_1 = 1; j_1 <= DefaultSegmentSize / 2; j_1++) { FSEditLogOp op = FSEditLogTestUtil.GetNoOpInstance(); op.SetTransactionId(txid++); out_1.Write(op); } out_1.SetReadyToFlush(); out_1.Flush(); out_1.Abort(); out_1.Close(); long numTrans = bkjm.GetNumberOfTransactions(1, true); NUnit.Framework.Assert.AreEqual((txid - 1), numTrans); }
public virtual void TestRefinalizeAlreadyFinalizedInprogress() { URI uri = BKJMUtil.CreateJournalURI("/hdfsjournal-refinalizeInprogressLedger"); NamespaceInfo nsi = NewNSInfo(); BookKeeperJournalManager bkjm = new BookKeeperJournalManager(conf, uri, nsi); bkjm.Format(nsi); EditLogOutputStream @out = bkjm.StartLogSegment(1, NameNodeLayoutVersion.CurrentLayoutVersion ); for (long i = 1; i <= 100; i++) { FSEditLogOp op = FSEditLogTestUtil.GetNoOpInstance(); op.SetTransactionId(i); @out.Write(op); } @out.Close(); bkjm.Close(); string inprogressZNode = bkjm.InprogressZNode(1); string finalizedZNode = bkjm.FinalizedLedgerZNode(1, 100); NUnit.Framework.Assert.IsNotNull("inprogress znode doesn't exist", zkc.Exists(inprogressZNode , null)); NUnit.Framework.Assert.IsNull("finalized znode exists", zkc.Exists(finalizedZNode , null)); byte[] inprogressData = zkc.GetData(inprogressZNode, false, null); // finalize bkjm = new BookKeeperJournalManager(conf, uri, nsi); bkjm.RecoverUnfinalizedSegments(); bkjm.Close(); NUnit.Framework.Assert.IsNull("inprogress znode exists", zkc.Exists(inprogressZNode , null)); NUnit.Framework.Assert.IsNotNull("finalized znode doesn't exist", zkc.Exists(finalizedZNode , null)); zkc.Create(inprogressZNode, inprogressData, ZooDefs.Ids.OpenAclUnsafe, CreateMode .Persistent); // should work fine bkjm = new BookKeeperJournalManager(conf, uri, nsi); bkjm.RecoverUnfinalizedSegments(); bkjm.Close(); }
/// <exception cref="System.IO.IOException"/> /// <exception cref="Org.Apache.Zookeeper.KeeperException"/> /// <exception cref="System.Exception"/> private string StartAndFinalizeLogSegment(BookKeeperJournalManager bkjm, int startTxid , int endTxid) { EditLogOutputStream @out = bkjm.StartLogSegment(startTxid, NameNodeLayoutVersion. CurrentLayoutVersion); for (long i = startTxid; i <= endTxid; i++) { FSEditLogOp op = FSEditLogTestUtil.GetNoOpInstance(); op.SetTransactionId(i); @out.Write(op); } @out.Close(); // finalize the inprogress_1 log segment. bkjm.FinalizeLogSegment(startTxid, endTxid); string zkpath1 = bkjm.FinalizedLedgerZNode(startTxid, endTxid); NUnit.Framework.Assert.IsNotNull(zkc.Exists(zkpath1, false)); NUnit.Framework.Assert.IsNull(zkc.Exists(bkjm.InprogressZNode(startTxid), false)); return(zkpath1); }