Esempio n. 1
0
        /// <exception cref="System.IO.IOException"/>
        private IList <EditLogLedgerMetadata> GetLedgerList(long fromTxId, bool inProgressOk
                                                            )
        {
            IList <EditLogLedgerMetadata> ledgers = new AList <EditLogLedgerMetadata>();

            try
            {
                IList <string> ledgerNames = zkc.GetChildren(ledgerPath, false);
                foreach (string ledgerName in ledgerNames)
                {
                    if (!inProgressOk && ledgerName.Contains(BkjmEditInprogress))
                    {
                        continue;
                    }
                    string legderMetadataPath = ledgerPath + "/" + ledgerName;
                    try
                    {
                        EditLogLedgerMetadata editLogLedgerMetadata = EditLogLedgerMetadata.Read(zkc, legderMetadataPath
                                                                                                 );
                        if (editLogLedgerMetadata.GetLastTxId() != HdfsConstants.InvalidTxid && editLogLedgerMetadata
                            .GetLastTxId() < fromTxId)
                        {
                            // exclude already read closed edits, but include inprogress edits
                            // as this will be handled in caller
                            continue;
                        }
                        ledgers.AddItem(editLogLedgerMetadata);
                    }
                    catch (KeeperException.NoNodeException)
                    {
                        Log.Warn("ZNode: " + legderMetadataPath + " might have finalized and deleted." +
                                 " So ignoring NoNodeException.");
                    }
                }
            }
            catch (KeeperException e)
            {
                throw new IOException("Exception reading ledger list from zk", e);
            }
            catch (Exception ie)
            {
                Sharpen.Thread.CurrentThread().Interrupt();
                throw new IOException("Interrupted getting list of ledgers from zk", ie);
            }
            ledgers.Sort(EditLogLedgerMetadata.Comparator);
            return(ledgers);
        }
Esempio n. 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);
        }