Пример #1
0
        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));
        }
Пример #2
0
        public virtual void TestCorruptInprogressNode()
        {
            URI                      uri  = BKJMUtil.CreateJournalURI("/hdfsjournal-corruptInprogress");
            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.FinalizeLogSegment(1, 100);
            @out = bkjm.StartLogSegment(101, NameNodeLayoutVersion.CurrentLayoutVersion);
            @out.Close();
            bkjm.Close();
            string inprogressZNode = bkjm.InprogressZNode(101);

            zkc.SetData(inprogressZNode, Sharpen.Runtime.GetBytesForString("WholeLottaJunk"),
                        -1);
            bkjm = new BookKeeperJournalManager(conf, uri, nsi);
            try
            {
                bkjm.RecoverUnfinalizedSegments();
                NUnit.Framework.Assert.Fail("Should have failed. There should be no way of creating"
                                            + " an empty inprogess znode");
            }
            catch (IOException e)
            {
                // correct behaviour
                NUnit.Framework.Assert.IsTrue("Exception different than expected", e.Message.Contains
                                                  ("has no field named"));
            }
            finally
            {
                bkjm.Close();
            }
        }
Пример #3
0
        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();
        }
Пример #4
0
        /// <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);
        }