Search in sources :

Example 1 with RecoveryData

use of org.apache.bookkeeper.proto.checksum.DigestManager.RecoveryData in project bookkeeper by apache.

the class PendingReadLacOp method readLacComplete.

@Override
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 {
            // 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: " + lh.metadata.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.info("While readLac ledger: " + ledgerId + " did not hear success responses from all of ensemble");
        cb.getLacComplete(lastSeenError, maxLac);
    }
}
Also used : BKDigestMatchException(org.apache.bookkeeper.client.BKException.BKDigestMatchException) RecoveryData(org.apache.bookkeeper.proto.checksum.DigestManager.RecoveryData)

Example 2 with RecoveryData

use of org.apache.bookkeeper.proto.checksum.DigestManager.RecoveryData in project bookkeeper by apache.

the class ReadLastConfirmedOp method readEntryComplete.

public synchronized void readEntryComplete(final int rc, final long ledgerId, final long entryId, final ByteBuf buffer, final Object ctx) {
    int bookieIndex = (Integer) ctx;
    // add the response to coverage set
    coverageSet.addBookie(bookieIndex, rc);
    numResponsesPending--;
    boolean heardValidResponse = false;
    if (rc == BKException.Code.OK) {
        try {
            RecoveryData recoveryData = lh.macManager.verifyDigestAndReturnLastConfirmed(buffer);
            if (recoveryData.getLastAddConfirmed() > maxRecoveredData.getLastAddConfirmed()) {
                maxRecoveredData = recoveryData;
            }
            heardValidResponse = true;
        } catch (BKDigestMatchException e) {
            // Too bad, this bookie didn't give us a valid answer, we
            // still might be able to recover though so continue
            LOG.error("Mac mismatch for ledger: " + ledgerId + ", entry: " + entryId + " while reading last entry from bookie: " + lh.metadata.currentEnsemble.get(bookieIndex));
        }
    }
    if (rc == BKException.Code.NoSuchLedgerExistsException || rc == BKException.Code.NoSuchEntryException) {
        // this still counts as a valid response, e.g., if the client crashed without writing any entry
        heardValidResponse = true;
    }
    if (rc == BKException.Code.UnauthorizedAccessException && !completed) {
        cb.readLastConfirmedDataComplete(rc, maxRecoveredData);
        completed = true;
    }
    if (!heardValidResponse && BKException.Code.OK != rc) {
        lastSeenError = rc;
    }
    // other return codes dont count as valid responses
    if (heardValidResponse && coverageSet.checkCovered() && !completed) {
        completed = true;
        if (LOG.isDebugEnabled()) {
            LOG.debug("Read Complete with enough validResponses for ledger: {}, entry: {}", ledgerId, entryId);
        }
        cb.readLastConfirmedDataComplete(BKException.Code.OK, maxRecoveredData);
        return;
    }
    if (numResponsesPending == 0 && !completed) {
        // Have got all responses back but was still not enough, just fail the operation
        LOG.error("While readLastConfirmed ledger: {} did not hear success responses from all quorums", ledgerId);
        cb.readLastConfirmedDataComplete(lastSeenError, maxRecoveredData);
    }
}
Also used : BKDigestMatchException(org.apache.bookkeeper.client.BKException.BKDigestMatchException) RecoveryData(org.apache.bookkeeper.proto.checksum.DigestManager.RecoveryData)

Example 3 with RecoveryData

use of org.apache.bookkeeper.proto.checksum.DigestManager.RecoveryData in project bookkeeper by apache.

the class TryReadLastConfirmedOp method readEntryComplete.

@Override
public void readEntryComplete(int rc, long ledgerId, long entryId, ByteBuf buffer, Object ctx) {
    if (LOG.isTraceEnabled()) {
        LOG.trace("TryReadLastConfirmed received response for (lid={}, eid={}) : {}", ledgerId, entryId, rc);
    }
    int bookieIndex = (Integer) ctx;
    numResponsesPending--;
    if (BKException.Code.OK == rc) {
        try {
            RecoveryData recoveryData = lh.macManager.verifyDigestAndReturnLastConfirmed(buffer);
            if (LOG.isTraceEnabled()) {
                LOG.trace("Received lastAddConfirmed (lac={}, length={}) from bookie({}) for (lid={}).", recoveryData.getLastAddConfirmed(), recoveryData.getLength(), bookieIndex, ledgerId);
            }
            if (recoveryData.getLastAddConfirmed() > maxRecoveredData.getLastAddConfirmed()) {
                maxRecoveredData = recoveryData;
                // callback immediately
                cb.readLastConfirmedDataComplete(BKException.Code.OK, maxRecoveredData);
            }
            hasValidResponse = true;
        } catch (BKException.BKDigestMatchException e) {
            LOG.error("Mac mismatch for ledger: " + ledgerId + ", entry: " + entryId + " while reading last entry from bookie: " + lh.metadata.currentEnsemble.get(bookieIndex));
        }
    } else if (BKException.Code.UnauthorizedAccessException == rc && !completed) {
        cb.readLastConfirmedDataComplete(rc, maxRecoveredData);
        completed = true;
    } else if (BKException.Code.NoSuchLedgerExistsException == rc || BKException.Code.NoSuchEntryException == rc) {
        hasValidResponse = true;
    }
    if (numResponsesPending == 0 && !completed) {
        if (!hasValidResponse) {
            // no success called
            cb.readLastConfirmedDataComplete(BKException.Code.LedgerRecoveryException, maxRecoveredData);
        } else {
            // callback
            cb.readLastConfirmedDataComplete(BKException.Code.OK, maxRecoveredData);
        }
        completed = true;
    }
}
Also used : RecoveryData(org.apache.bookkeeper.proto.checksum.DigestManager.RecoveryData)

Aggregations

RecoveryData (org.apache.bookkeeper.proto.checksum.DigestManager.RecoveryData)3 BKDigestMatchException (org.apache.bookkeeper.client.BKException.BKDigestMatchException)2