use of io.pravega.controller.server.WireCommandFailedException.Reason.ConnectionDropped in project pravega by pravega.
the class PravegaTablesStoreHelper method exceptionalCallback.
private <T> Supplier<CompletableFuture<T>> exceptionalCallback(Supplier<CompletableFuture<T>> future, Supplier<String> errorMessageSupplier, boolean throwOriginalOnCFE, long requestId) {
return () -> CompletableFuture.completedFuture(null).thenComposeAsync(v -> future.get(), executor).exceptionally(t -> {
String errorMessage = errorMessageSupplier.get();
Throwable cause = Exceptions.unwrap(t);
Throwable toThrow;
if (cause instanceof WireCommandFailedException) {
WireCommandFailedException wcfe = (WireCommandFailedException) cause;
switch(wcfe.getReason()) {
case ConnectionDropped:
case ConnectionFailed:
toThrow = throwOriginalOnCFE ? wcfe : StoreException.create(StoreException.Type.CONNECTION_ERROR, wcfe, errorMessage);
break;
case UnknownHost:
toThrow = StoreException.create(StoreException.Type.CONNECTION_ERROR, wcfe, errorMessage);
break;
case PreconditionFailed:
toThrow = StoreException.create(StoreException.Type.ILLEGAL_STATE, wcfe, errorMessage);
break;
case AuthFailed:
authToken.set(authHelper.retrieveMasterToken());
toThrow = StoreException.create(StoreException.Type.CONNECTION_ERROR, wcfe, errorMessage);
break;
case SegmentDoesNotExist:
toThrow = StoreException.create(StoreException.Type.DATA_CONTAINER_NOT_FOUND, wcfe, errorMessage);
break;
case TableSegmentNotEmpty:
toThrow = StoreException.create(StoreException.Type.DATA_CONTAINS_ELEMENTS, wcfe, errorMessage);
break;
case TableKeyDoesNotExist:
toThrow = StoreException.create(StoreException.Type.DATA_NOT_FOUND, wcfe, errorMessage);
break;
case TableKeyBadVersion:
toThrow = StoreException.create(StoreException.Type.WRITE_CONFLICT, wcfe, errorMessage);
break;
default:
toThrow = StoreException.create(StoreException.Type.UNKNOWN, wcfe, errorMessage);
}
} else if (cause instanceof HostStoreException) {
log.warn(requestId, "Host Store exception {}", cause.getMessage());
toThrow = StoreException.create(StoreException.Type.CONNECTION_ERROR, cause, errorMessage);
} else {
log.warn(requestId, "exception of unknown type thrown {} ", errorMessage, cause);
toThrow = StoreException.create(StoreException.Type.UNKNOWN, cause, errorMessage);
}
throw new CompletionException(toThrow);
});
}
Aggregations