Source:
private boolean tryReadingFaultyEntries(LedgerHandle lh, LedgerFragment ledgerFragment) { ConcurrentSkipListSet<Long> entriesUnableToReadForThisLedger = unableToReadEntriesForReplication .getIfPresent(lh.getId()); if (entriesUnableToReadForThisLedger == null) { return true; } long firstEntryIdOfFragment = ledgerFragment.getFirstEntryId(); long lastEntryIdOfFragment = ledgerFragment.getLastKnownEntryId(); NavigableSet<Long> entriesOfThisFragmentUnableToRead = entriesUnableToReadForThisLedger .subSet(firstEntryIdOfFragment, true, lastEntryIdOfFragment, true); if (entriesOfThisFragmentUnableToRead.isEmpty()) { return true; } final CountDownLatch numEntriesToRead = new CountDownLatch(entriesOfThisFragmentUnableToRead.size()); final AtomicInteger returnRCValue = new AtomicInteger(BKException.Code.OK); for (long entryIdToRead : entriesOfThisFragmentUnableToRead) { lh.asyncReadEntries(entryIdToRead, entryIdToRead, (rc, ledHan, seq, ctx) -> { long thisEntryId = (Long) ctx; if (rc == BKException.Code.OK) { entriesUnableToReadForThisLedger.remove(thisEntryId); } else { LOG.error("Received error: while trying to read entry in ReplicationWorker", rc); returnRCValue.compareAndSet(BKException.Code.OK, rc); } numEntriesToRead.countDown(); }, entryIdToRead); } try { numEntriesToRead.await(); } catch (InterruptedException e) { LOG.error("Got interrupted exception while trying to read entries", e); return false; } return (returnRCValue.get() == BKException.Code.OK); }

Target:
private boolean tryReadingFaultyEntries(LedgerHandle lh, LedgerFragment ledgerFragment) { long ledgerId = lh.getId(); ConcurrentSkipListSet<Long> entriesUnableToReadForThisLedger = unableToReadEntriesForReplication .getIfPresent(ledgerId); if (entriesUnableToReadForThisLedger == null) { return true; } long firstEntryIdOfFragment = ledgerFragment.getFirstEntryId(); long lastEntryIdOfFragment = ledgerFragment.getLastKnownEntryId(); NavigableSet<Long> entriesOfThisFragmentUnableToRead = entriesUnableToReadForThisLedger .subSet(firstEntryIdOfFragment, true, lastEntryIdOfFragment, true); if (entriesOfThisFragmentUnableToRead.isEmpty()) { return true; } final CountDownLatch multiReadComplete = new CountDownLatch(1); final AtomicInteger numOfResponsesToWaitFor = new AtomicInteger(entriesOfThisFragmentUnableToRead.size()); final AtomicInteger returnRCValue = new AtomicInteger(BKException.Code.OK); for (long entryIdToRead : entriesOfThisFragmentUnableToRead) { if (multiReadComplete.getCount() == 0) { break; } lh.asyncReadEntries(entryIdToRead, entryIdToRead, (rc, ledHan, seq, ctx) -> { long thisEntryId = (Long) ctx; if (rc == BKException.Code.OK) { entriesUnableToReadForThisLedger.remove(thisEntryId); if (numOfResponsesToWaitFor.decrementAndGet() == 0) { multiReadComplete.countDown(); } } else { LOG.error("Received error: while trying to read entry: of ledger: in ReplicationWorker", rc, entryIdToRead, ledgerId); returnRCValue.compareAndSet(BKException.Code.OK, rc); multiReadComplete.countDown(); } }, entryIdToRead); } try { multiReadComplete.await(); } catch (InterruptedException e) { LOG.error("Got interrupted exception while trying to read entries", e); Thread.currentThread().interrupt(); return false; } return (returnRCValue.get() == BKException.Code.OK); }