Search in sources :

Example 1 with ConnectionFailed

use of io.pravega.controller.server.WireCommandFailedException.Reason.ConnectionFailed 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);
    });
}
Also used : TableSegmentKeyVersion(io.pravega.client.tables.impl.TableSegmentKeyVersion) Cache(io.pravega.controller.store.stream.Cache) OperationContext(io.pravega.controller.store.stream.OperationContext) SegmentHelper(io.pravega.controller.server.SegmentHelper) BiFunction(java.util.function.BiFunction) Exceptions(io.pravega.common.Exceptions) LoggerFactory(org.slf4j.LoggerFactory) CompletableFuture(java.util.concurrent.CompletableFuture) HostStoreException(io.pravega.controller.store.host.HostStoreException) BitConverter(io.pravega.common.util.BitConverter) AtomicReference(java.util.concurrent.atomic.AtomicReference) Function(java.util.function.Function) Supplier(java.util.function.Supplier) Unpooled(io.netty.buffer.Unpooled) ArrayList(java.util.ArrayList) TagLogger(io.pravega.common.tracing.TagLogger) ByteBuf(io.netty.buffer.ByteBuf) StoreException(io.pravega.controller.store.stream.StoreException) Map(java.util.Map) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) HashTableIteratorItem(io.pravega.client.tables.impl.HashTableIteratorItem) RetryHelper(io.pravega.controller.util.RetryHelper) Charsets(org.apache.curator.shaded.com.google.common.base.Charsets) TableSegmentKey(io.pravega.client.tables.impl.TableSegmentKey) Predicate(java.util.function.Predicate) Collection(java.util.Collection) AsyncIterator(io.pravega.common.util.AsyncIterator) CompletionException(java.util.concurrent.CompletionException) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) RetriesExhaustedException(io.pravega.common.util.RetriesExhaustedException) StandardCharsets(java.nio.charset.StandardCharsets) ConnectionDropped(io.pravega.controller.server.WireCommandFailedException.Reason.ConnectionDropped) AbstractMap(java.util.AbstractMap) List(java.util.List) ByteArraySegment(io.pravega.common.util.ByteArraySegment) WireCommandFailedException(io.pravega.controller.server.WireCommandFailedException) TableSegmentEntry(io.pravega.client.tables.impl.TableSegmentEntry) ContinuationTokenAsyncIterator(io.pravega.common.util.ContinuationTokenAsyncIterator) ReferenceCountUtil(io.netty.util.ReferenceCountUtil) VisibleForTesting(com.google.common.annotations.VisibleForTesting) Collections(java.util.Collections) Futures(io.pravega.common.concurrent.Futures) ConnectionFailed(io.pravega.controller.server.WireCommandFailedException.Reason.ConnectionFailed) GrpcAuthHelper(io.pravega.controller.server.security.auth.GrpcAuthHelper) HostStoreException(io.pravega.controller.store.host.HostStoreException) CompletionException(java.util.concurrent.CompletionException) WireCommandFailedException(io.pravega.controller.server.WireCommandFailedException)

Aggregations

VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 ByteBuf (io.netty.buffer.ByteBuf)1 Unpooled (io.netty.buffer.Unpooled)1 ReferenceCountUtil (io.netty.util.ReferenceCountUtil)1 HashTableIteratorItem (io.pravega.client.tables.impl.HashTableIteratorItem)1 TableSegmentEntry (io.pravega.client.tables.impl.TableSegmentEntry)1 TableSegmentKey (io.pravega.client.tables.impl.TableSegmentKey)1 TableSegmentKeyVersion (io.pravega.client.tables.impl.TableSegmentKeyVersion)1 Exceptions (io.pravega.common.Exceptions)1 Futures (io.pravega.common.concurrent.Futures)1 TagLogger (io.pravega.common.tracing.TagLogger)1 AsyncIterator (io.pravega.common.util.AsyncIterator)1 BitConverter (io.pravega.common.util.BitConverter)1 ByteArraySegment (io.pravega.common.util.ByteArraySegment)1 ContinuationTokenAsyncIterator (io.pravega.common.util.ContinuationTokenAsyncIterator)1 RetriesExhaustedException (io.pravega.common.util.RetriesExhaustedException)1 SegmentHelper (io.pravega.controller.server.SegmentHelper)1 WireCommandFailedException (io.pravega.controller.server.WireCommandFailedException)1 ConnectionDropped (io.pravega.controller.server.WireCommandFailedException.Reason.ConnectionDropped)1 ConnectionFailed (io.pravega.controller.server.WireCommandFailedException.Reason.ConnectionFailed)1