@Override public void readEntryComplete(int rc, long ledgerId, final long entryId, final ByteBuf buffer, Object ctx) { final ReadContext rctx = (ReadContext) ctx; final LedgerEntryRequest entry = rctx.entry; if (rc != BKException.Code.OK) { entry.logErrorAndReattemptRead(rctx.bookieIndex, rctx.to, "Error: " + BKException.getMessage(rc), rc); return; } heardFromHosts.add(rctx.to); heardFromHostsBitSet.set(rctx.bookieIndex, true); buffer.retain(); if (entry.complete(rctx.bookieIndex, rctx.to, buffer)) { if (!isRecoveryRead) { // do not advance LastAddConfirmed for recovery reads lh.updateLastConfirmed(rctx.getLastAddConfirmed(), 0L); } submitCallback(BKException.Code.OK); } else { buffer.release(); } if (numPendingEntries < 0) { LOG.error("Read too many values for ledger {} : [{}, {}].", ledgerId, startEntryId, endEntryId); } }
@Override synchronized void logErrorAndReattemptRead(int bookieIndex, BookieSocketAddress host, String errMsg, int rc) { super.logErrorAndReattemptRead(bookieIndex, host, errMsg, rc); int replica = writeSet.indexOf(bookieIndex); if (replica == NOT_FOUND) { LOG.error("Received error from a host which is not in the ensemble {} {}.", host, ensemble); return; } erroredReplicas.set(replica); if (isRecoveryRead && (numBookiesMissingEntry >= requiredBookiesMissingEntryForRecovery)) { /* For recovery, report NoSuchEntry as soon as wQ-aQ+1 bookies report that they do not * have the entry */ fail(BKException.Code.NoSuchEntryException); return; } if (!readsOutstanding()) { sendNextRead(); } }
} catch (BKDigestMatchException e) { clientCtx.getClientStats().getReadOpDmCounter().inc(); logErrorAndReattemptRead(bookieIndex, host, "Mac mismatch", BKException.Code.DigestMatchException); return false;
@Override synchronized void logErrorAndReattemptRead(int bookieIndex, BookieSocketAddress host, String errMsg, int rc) { super.logErrorAndReattemptRead(bookieIndex, host, errMsg, rc); // if received all responses or this entry doesn't meet quorum write, complete the request. --numPendings; if (isRecoveryRead && numBookiesMissingEntry >= requiredBookiesMissingEntryForRecovery) { /* For recovery, report NoSuchEntry as soon as wQ-aQ+1 bookies report that they do not * have the entry */ fail(BKException.Code.NoSuchEntryException); } else if (numPendings == 0) { // if received all responses, complete the request. fail(firstError); } }