Beispiel #1
0
        /// <summary>
        /// Find the id of the last edit log transaction writen to a edit log
        /// ledger.
        /// </summary>
        /// <exception cref="System.IO.IOException"/>
        /// <exception cref="Org.Apache.Hadoop.Contrib.Bkjournal.BookKeeperJournalManager.SegmentEmptyException
        ///     "/>
        private long RecoverLastTxId(EditLogLedgerMetadata l, bool fence)
        {
            LedgerHandle lh = null;

            try
            {
                if (fence)
                {
                    lh = bkc.OpenLedger(l.GetLedgerId(), BookKeeper.DigestType.Mac, Sharpen.Runtime.GetBytesForString
                                            (digestpw, Charsets.Utf8));
                }
                else
                {
                    lh = bkc.OpenLedgerNoRecovery(l.GetLedgerId(), BookKeeper.DigestType.Mac, Sharpen.Runtime.GetBytesForString
                                                      (digestpw, Charsets.Utf8));
                }
            }
            catch (BKException bke)
            {
                throw new IOException("Exception opening ledger for " + l, bke);
            }
            catch (Exception ie)
            {
                Sharpen.Thread.CurrentThread().Interrupt();
                throw new IOException("Interrupted opening ledger for " + l, ie);
            }
            BookKeeperEditLogInputStream @in = null;

            try
            {
                long lastAddConfirmed = lh.GetLastAddConfirmed();
                if (lastAddConfirmed == -1)
                {
                    throw new BookKeeperJournalManager.SegmentEmptyException();
                }
                @in = new BookKeeperEditLogInputStream(lh, l, lastAddConfirmed);
                long        endTxId = HdfsConstants.InvalidTxid;
                FSEditLogOp op      = @in.ReadOp();
                while (op != null)
                {
                    if (endTxId == HdfsConstants.InvalidTxid || op.GetTransactionId() == endTxId + 1)
                    {
                        endTxId = op.GetTransactionId();
                    }
                    op = @in.ReadOp();
                }
                return(endTxId);
            }
            finally
            {
                if (@in != null)
                {
                    @in.Close();
                }
            }
        }
Beispiel #2
0
        /// <summary>Construct BookKeeper edit log input stream.</summary>
        /// <remarks>
        /// Construct BookKeeper edit log input stream.
        /// Starts reading from firstBookKeeperEntry. This allows the stream
        /// to take a shortcut during recovery, as it doesn't have to read
        /// every edit log transaction to find out what the last one is.
        /// </remarks>
        /// <exception cref="System.IO.IOException"/>
        internal BookKeeperEditLogInputStream(LedgerHandle lh, EditLogLedgerMetadata metadata
                                              , long firstBookKeeperEntry)
        {
            this.lh         = lh;
            this.firstTxId  = metadata.GetFirstTxId();
            this.lastTxId   = metadata.GetLastTxId();
            this.logVersion = metadata.GetDataLayoutVersion();
            this.inProgress = metadata.IsInProgress();
            if (firstBookKeeperEntry < 0 || firstBookKeeperEntry > lh.GetLastAddConfirmed())
            {
                throw new IOException("Invalid first bk entry to read: " + firstBookKeeperEntry +
                                      ", LAC: " + lh.GetLastAddConfirmed());
            }
            BufferedInputStream bin = new BufferedInputStream(new BookKeeperEditLogInputStream.LedgerInputStream
                                                                  (lh, firstBookKeeperEntry));

            tracker = new FSEditLogLoader.PositionTrackingInputStream(bin);
            DataInputStream @in = new DataInputStream(tracker);

            reader = new FSEditLogOp.Reader(@in, tracker, logVersion);
        }
Beispiel #3
0
 /// <summary>Construct ledger input stream</summary>
 /// <param name="lh">the ledger handle to read from</param>
 /// <param name="firstBookKeeperEntry">ledger entry to start reading from</param>
 /// <exception cref="System.IO.IOException"/>
 internal LedgerInputStream(LedgerHandle lh, long firstBookKeeperEntry)
 {
     this.lh     = lh;
     readEntries = firstBookKeeperEntry;
     maxEntry    = lh.GetLastAddConfirmed();
 }