Search in sources :

Example 1 with BKException

use of org.apache.bookkeeper.client.api.BKException in project pravega by pravega.

the class BookKeeperLog method handleWriteException.

/**
 * Handles an exception after a Write operation, converts it to a Pravega Exception and completes the given future
 * exceptionally using it.
 *
 * @param ex The exception from BookKeeper client.
 * @param write The Write that failed.
 */
@VisibleForTesting
static void handleWriteException(Throwable ex, Write write, BookKeeperLog bookKeeperLog) {
    try {
        int code = Code.UnexpectedConditionException;
        if (ex instanceof BKException) {
            BKException bKException = (BKException) ex;
            code = bKException.getCode();
        }
        switch(code) {
            case Code.LedgerFencedException:
                // We were fenced out.
                ex = new DataLogWriterNotPrimaryException("BookKeeperLog is not primary anymore.", ex);
                break;
            case Code.NotEnoughBookiesException:
                // Insufficient Bookies to complete the operation. This is a retryable exception.
                ex = new DataLogNotAvailableException("BookKeeperLog is not available.", ex);
                break;
            case Code.LedgerClosedException:
                // LedgerClosed can happen because we just rolled over the ledgers or because BookKeeper closed a ledger
                // due to some error. In either case, this is a retryable exception.
                ex = new WriteFailureException("Active Ledger is closed.", ex);
                break;
            case Code.WriteException:
                // Write-related failure or current Ledger closed. This is a retryable exception.
                ex = new WriteFailureException("Unable to write to active Ledger.", ex);
                break;
            case Code.ClientClosedException:
                // The BookKeeper client was closed externally. We cannot restart it here. We should close.
                ex = new ObjectClosedException(bookKeeperLog, ex);
                break;
            default:
                // All the other kind of exceptions go in the same bucket.
                ex = new DurableDataLogException("General exception while accessing BookKeeper.", ex);
        }
    } finally {
        write.fail(ex, !isRetryable(ex));
    }
}
Also used : DurableDataLogException(io.pravega.segmentstore.storage.DurableDataLogException) DataLogWriterNotPrimaryException(io.pravega.segmentstore.storage.DataLogWriterNotPrimaryException) DataLogNotAvailableException(io.pravega.segmentstore.storage.DataLogNotAvailableException) WriteFailureException(io.pravega.segmentstore.storage.WriteFailureException) ObjectClosedException(io.pravega.common.ObjectClosedException) BKException(org.apache.bookkeeper.client.api.BKException) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Aggregations

VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 ObjectClosedException (io.pravega.common.ObjectClosedException)1 DataLogNotAvailableException (io.pravega.segmentstore.storage.DataLogNotAvailableException)1 DataLogWriterNotPrimaryException (io.pravega.segmentstore.storage.DataLogWriterNotPrimaryException)1 DurableDataLogException (io.pravega.segmentstore.storage.DurableDataLogException)1 WriteFailureException (io.pravega.segmentstore.storage.WriteFailureException)1 BKException (org.apache.bookkeeper.client.api.BKException)1