コード例 #1
0
        /// <exception cref="System.IO.IOException"/>
        public virtual void SelectInputStreams(ICollection <EditLogInputStream> streams, long
                                               fromTxId, bool inProgressOk)
        {
            IList <EditLogLedgerMetadata> currentLedgerList = GetLedgerList(fromTxId, inProgressOk
                                                                            );

            try
            {
                BookKeeperEditLogInputStream elis = null;
                foreach (EditLogLedgerMetadata l in currentLedgerList)
                {
                    long lastTxId = l.GetLastTxId();
                    if (l.IsInProgress())
                    {
                        lastTxId = RecoverLastTxId(l, false);
                    }
                    // Check once again, required in case of InProgress and is case of any
                    // gap.
                    if (fromTxId >= l.GetFirstTxId() && fromTxId <= lastTxId)
                    {
                        LedgerHandle h;
                        if (l.IsInProgress())
                        {
                            // we don't want to fence the current journal
                            h = bkc.OpenLedgerNoRecovery(l.GetLedgerId(), BookKeeper.DigestType.Mac, Sharpen.Runtime.GetBytesForString
                                                             (digestpw, Charsets.Utf8));
                        }
                        else
                        {
                            h = bkc.OpenLedger(l.GetLedgerId(), BookKeeper.DigestType.Mac, Sharpen.Runtime.GetBytesForString
                                                   (digestpw, Charsets.Utf8));
                        }
                        elis = new BookKeeperEditLogInputStream(h, l);
                        elis.SkipTo(fromTxId);
                    }
                    else
                    {
                        // If mismatches then there might be some gap, so we should not check
                        // further.
                        return;
                    }
                    streams.AddItem(elis);
                    if (elis.GetLastTxId() == HdfsConstants.InvalidTxid)
                    {
                        return;
                    }
                    fromTxId = elis.GetLastTxId() + 1;
                }
            }
            catch (BKException e)
            {
                throw new IOException("Could not open ledger for " + fromTxId, e);
            }
            catch (Exception ie)
            {
                Sharpen.Thread.CurrentThread().Interrupt();
                throw new IOException("Interrupted opening ledger for " + fromTxId, ie);
            }
        }
コード例 #2
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();
                }
            }
        }