in bookkeeper-server/src/main/java/org/apache/bookkeeper/client/PendingReadLacOp.java [80:162]
public void readLacComplete(int rc, long ledgerId, final ByteBuf lacBuffer, final ByteBuf lastEntryBuffer,
Object ctx) {
int bookieIndex = (Integer) ctx;
// add the response to coverage set
coverageSet.addBookie(bookieIndex, rc);
numResponsesPending--;
boolean heardValidResponse = false;
if (completed) {
return;
}
if (rc == BKException.Code.OK) {
try {
// Each bookie may have two store LAC in two places.
// One is in-memory copy in FileInfo and other is
// piggy-backed LAC on the last entry.
// This routine picks both of them and compares to return
// the latest Lac.
// lacBuffer and lastEntryBuffer are optional in the protocol.
// So check if they exist before processing them.
// Extract lac from FileInfo on the ledger.
if (lacBuffer != null && lacBuffer.readableBytes() > 0) {
long lac = lh.macManager.verifyDigestAndReturnLac(lacBuffer);
if (lac > maxLac) {
maxLac = lac;
}
}
// Extract lac from last entry on the disk
if (lastEntryBuffer != null && lastEntryBuffer.readableBytes() > 0) {
RecoveryData recoveryData = lh.macManager.verifyDigestAndReturnLastConfirmed(lastEntryBuffer);
long recoveredLac = recoveryData.getLastAddConfirmed();
if (recoveredLac > maxLac) {
maxLac = recoveredLac;
}
}
heardValidResponse = true;
} catch (BKDigestMatchException e) {
// Too bad, this bookie did not give us a valid answer, we
// still might be able to recover. So, continue
LOG.error("Mac mismatch while reading ledger: " + ledgerId + " LAC from bookie: "
+ currentEnsemble.get(bookieIndex));
rc = BKException.Code.DigestMatchException;
}
}
if (rc == BKException.Code.NoSuchLedgerExistsException || rc == BKException.Code.NoSuchEntryException) {
heardValidResponse = true;
}
if (rc == BKException.Code.UnauthorizedAccessException && !completed) {
cb.getLacComplete(rc, maxLac);
completed = true;
return;
}
if (!heardValidResponse && BKException.Code.OK != rc) {
lastSeenError = rc;
}
// We don't consider a success until we have coverage set responses.
if (heardValidResponse
&& coverageSet.checkCovered()
&& !completed) {
completed = true;
if (LOG.isDebugEnabled()) {
LOG.debug("Read LAC complete with enough validResponse for ledger: {} LAC: {}", ledgerId, maxLac);
}
cb.getLacComplete(BKException.Code.OK, maxLac);
return;
}
if (numResponsesPending == 0 && !completed) {
LOG.error(
"While readLac ledger: {} did not hear success responses from all of ensemble, coverageSet is: {}",
ledgerId, coverageSet);
cb.getLacComplete(lastSeenError, maxLac);
}
}