* Process old version ledger ranges to fetch start seq id.
*/
void getStartSeqIdToProcessTopicLedgerRanges(
final List<LedgerRange> rangesList, final Version version) {
final LedgerRange range = rangesList.get(0);
if (!range.hasEndSeqIdIncluded()) {
// process topic ledger ranges directly
processTopicLedgerRanges(rangesList, version, START_SEQ_ID);
return;
}
final long ledgerId = range.getLedgerId();
// open the first ledger to compute right start seq id
bk.asyncOpenLedger(ledgerId, DigestType.CRC32, passwd,
new SafeAsynBKCallback.OpenCallback() {
@Override
public void safeOpenComplete(int rc, LedgerHandle ledgerHandle, Object ctx) {
if (rc == BKException.Code.NoSuchLedgerExistsException) {
// process next ledger
processTopicLedgerRanges(rangesList, version, START_SEQ_ID);
return;
} else if (rc != BKException.Code.OK) {
BKException bke = BKException.create(rc);
logger.error("Could not open ledger {} to get start seq id while acquiring topic {} : {}",
va(ledgerId, topic.toStringUtf8(), bke));
cb.operationFailed(ctx, new PubSubException.ServiceDownException(bke));
return;
}
final long numEntriesInLastLedger = ledgerHandle.getLastAddConfirmed() + 1;
// the ledger is closed before, calling close is just a nop operation.
try {
ledgerHandle.close();
} catch (InterruptedException ie) {
// the exception would never be thrown for a read only ledger handle.
} catch (BKException bke) {
// the exception would never be thrown for a read only ledger handle.
}
if (numEntriesInLastLedger <= 0) {
String msg = "No entries found in a have-end-seq-id ledger " + ledgerId
+ " when acquiring topic " + topic.toStringUtf8() + ".";
logger.error(msg);
cb.operationFailed(ctx, new PubSubException.UnexpectedConditionException(msg));
return;
}
long endOfLedger = range.getEndSeqIdIncluded().getLocalComponent();
long startOfLedger = endOfLedger - numEntriesInLastLedger + 1;
processTopicLedgerRanges(rangesList, version, startOfLedger);
}