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));
}
}
Aggregations