/// <summary> /// Find out how many transactions we can read from a /// FileJournalManager, starting at a given transaction ID. /// </summary> /// <param name="jm">The journal manager</param> /// <param name="fromTxId">Transaction ID to start at</param> /// <param name="inProgressOk">Should we consider edit logs that are not finalized?</param> /// <returns>The number of transactions</returns> /// <exception cref="System.IO.IOException"/> internal static long GetNumberOfTransactions(FileJournalManager jm, long fromTxId , bool inProgressOk, bool abortOnGap) { long numTransactions = 0; long txId = fromTxId; PriorityQueue <EditLogInputStream> allStreams = new PriorityQueue <EditLogInputStream >(64, JournalSet.EditLogInputStreamComparator); jm.SelectInputStreams(allStreams, fromTxId, inProgressOk); EditLogInputStream elis = null; try { while ((elis = allStreams.Poll()) != null) { try { elis.SkipUntil(txId); while (true) { FSEditLogOp op = elis.ReadOp(); if (op == null) { break; } if (abortOnGap && (op.GetTransactionId() != txId)) { Log.Info("getNumberOfTransactions: detected gap at txId " + fromTxId); return(numTransactions); } txId = op.GetTransactionId() + 1; numTransactions++; } } finally { IOUtils.Cleanup(Log, elis); } } } finally { IOUtils.Cleanup(Log, Sharpen.Collections.ToArray(allStreams, new EditLogInputStream [0])); } return(numTransactions); }
/// <exception cref="System.IO.IOException"/> private static EditLogInputStream GetJournalInputStream(JournalManager jm, long txId , bool inProgressOk) { PriorityQueue <EditLogInputStream> allStreams = new PriorityQueue <EditLogInputStream >(64, JournalSet.EditLogInputStreamComparator); jm.SelectInputStreams(allStreams, txId, inProgressOk); EditLogInputStream elis = null; EditLogInputStream ret; try { while ((elis = allStreams.Poll()) != null) { if (elis.GetFirstTxId() > txId) { break; } if (elis.GetLastTxId() < txId) { elis.Close(); continue; } elis.SkipUntil(txId); ret = elis; elis = null; return(ret); } } finally { IOUtils.Cleanup(Log, Sharpen.Collections.ToArray(allStreams, new EditLogInputStream [0])); IOUtils.Cleanup(Log, elis); } return(null); }