Search in sources :

Example 6 with InvalidStreamException

use of io.pravega.client.stream.InvalidStreamException in project pravega by pravega.

the class ControllerImpl method sealStream.

@Override
public CompletableFuture<Boolean> sealStream(final String scope, final String streamName) {
    Exceptions.checkNotClosed(closed.get(), this);
    Exceptions.checkNotNullOrEmpty(scope, "scope");
    Exceptions.checkNotNullOrEmpty(streamName, "streamName");
    long traceId = LoggerHelpers.traceEnter(log, "sealStream", scope, streamName);
    final CompletableFuture<UpdateStreamStatus> result = this.retryConfig.runAsync(() -> {
        RPCAsyncCallback<UpdateStreamStatus> callback = new RPCAsyncCallback<>();
        client.sealStream(ModelHelper.createStreamInfo(scope, streamName), callback);
        return callback.getFuture();
    }, this.executor);
    return result.thenApply(x -> {
        switch(x.getStatus()) {
            case FAILURE:
                log.warn("Failed to seal stream: {}", streamName);
                throw new ControllerFailureException("Failed to seal stream: " + streamName);
            case SCOPE_NOT_FOUND:
                log.warn("Scope not found: {}", scope);
                throw new InvalidStreamException("Scope does not exist: " + scope);
            case STREAM_NOT_FOUND:
                log.warn("Stream does not exist: {}", streamName);
                throw new InvalidStreamException("Stream does not exist: " + streamName);
            case SUCCESS:
                log.info("Successfully sealed stream: {}", streamName);
                return true;
            case UNRECOGNIZED:
            default:
                throw new ControllerFailureException("Unknown return status scealing stream " + streamName + " " + x.getStatus());
        }
    }).whenComplete((x, e) -> {
        if (e != null) {
            log.warn("sealStream failed: ", e);
        }
        LoggerHelpers.traceLeave(log, "sealStream", traceId);
    });
}
Also used : StreamCut(io.pravega.client.stream.StreamCut) ManagedChannel(io.grpc.ManagedChannel) Retry(io.pravega.common.util.Retry) NegotiationType(io.grpc.netty.NegotiationType) MoreCallCredentials(io.grpc.auth.MoreCallCredentials) StreamConfiguration(io.pravega.client.stream.StreamConfiguration) PingTxnRequest(io.pravega.controller.stream.api.grpc.v1.Controller.PingTxnRequest) SegmentRanges(io.pravega.controller.stream.api.grpc.v1.Controller.SegmentRanges) GetSegmentsRequest(io.pravega.controller.stream.api.grpc.v1.Controller.GetSegmentsRequest) StreamObserver(io.grpc.stub.StreamObserver) Stream(io.pravega.client.stream.Stream) Map(java.util.Map) Collectors.summarizingInt(java.util.stream.Collectors.summarizingInt) PravegaNodeUri(io.pravega.shared.protocol.netty.PravegaNodeUri) Transaction(io.pravega.client.stream.Transaction) DeleteScopeStatus(io.pravega.controller.stream.api.grpc.v1.Controller.DeleteScopeStatus) CreateStreamStatus(io.pravega.controller.stream.api.grpc.v1.Controller.CreateStreamStatus) Collection(java.util.Collection) Set(java.util.Set) CompletionException(java.util.concurrent.CompletionException) UUID(java.util.UUID) NavigableMap(java.util.NavigableMap) Collectors(java.util.stream.Collectors) List(java.util.List) SSLException(javax.net.ssl.SSLException) Slf4j(lombok.extern.slf4j.Slf4j) CreateTxnResponse(io.pravega.controller.stream.api.grpc.v1.Controller.CreateTxnResponse) PingTxnStatus(io.pravega.controller.stream.api.grpc.v1.Controller.PingTxnStatus) Futures(io.pravega.common.concurrent.Futures) Segment(io.pravega.client.segment.impl.Segment) CreateScopeStatus(io.pravega.controller.stream.api.grpc.v1.Controller.CreateScopeStatus) ScaleStatusRequest(io.pravega.controller.stream.api.grpc.v1.Controller.ScaleStatusRequest) Exceptions(io.pravega.common.Exceptions) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ScaleStatusResponse(io.pravega.controller.stream.api.grpc.v1.Controller.ScaleStatusResponse) ScopeInfo(io.pravega.controller.stream.api.grpc.v1.Controller.ScopeInfo) TxnState(io.pravega.controller.stream.api.grpc.v1.Controller.TxnState) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) SuccessorResponse(io.pravega.controller.stream.api.grpc.v1.Controller.SuccessorResponse) PingFailedException(io.pravega.client.stream.PingFailedException) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Strings(com.google.common.base.Strings) NodeUri(io.pravega.controller.stream.api.grpc.v1.Controller.NodeUri) ScaleRequest(io.pravega.controller.stream.api.grpc.v1.Controller.ScaleRequest) CreateTxnRequest(io.pravega.controller.stream.api.grpc.v1.Controller.CreateTxnRequest) StreamInfo(io.pravega.controller.stream.api.grpc.v1.Controller.StreamInfo) DeleteStreamStatus(io.pravega.controller.stream.api.grpc.v1.Controller.DeleteStreamStatus) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) ControllerServiceGrpc(io.pravega.controller.stream.api.grpc.v1.ControllerServiceGrpc) ScaleResponse(io.pravega.controller.stream.api.grpc.v1.Controller.ScaleResponse) LoggerHelpers(io.pravega.common.LoggerHelpers) Futures.getAndHandleExceptions(io.pravega.common.concurrent.Futures.getAndHandleExceptions) lombok.val(lombok.val) SegmentRange(io.pravega.controller.stream.api.grpc.v1.Controller.SegmentRange) File(java.io.File) StatusRuntimeException(io.grpc.StatusRuntimeException) NettyChannelBuilder(io.grpc.netty.NettyChannelBuilder) TimeUnit(java.util.concurrent.TimeUnit) ManagedChannelBuilder(io.grpc.ManagedChannelBuilder) TreeMap(java.util.TreeMap) UpdateStreamStatus(io.pravega.controller.stream.api.grpc.v1.Controller.UpdateStreamStatus) TxnStatus(io.pravega.controller.stream.api.grpc.v1.Controller.TxnStatus) SslContextBuilder(io.netty.handler.ssl.SslContextBuilder) InvalidStreamException(io.pravega.client.stream.InvalidStreamException) Preconditions(com.google.common.base.Preconditions) RoundRobinLoadBalancerFactory(io.grpc.util.RoundRobinLoadBalancerFactory) SegmentsAtTime(io.pravega.controller.stream.api.grpc.v1.Controller.SegmentsAtTime) VisibleForTesting(com.google.common.annotations.VisibleForTesting) TxnFailedException(io.pravega.client.stream.TxnFailedException) TxnRequest(io.pravega.controller.stream.api.grpc.v1.Controller.TxnRequest) ArrayDeque(java.util.ArrayDeque) SegmentValidityResponse(io.pravega.controller.stream.api.grpc.v1.Controller.SegmentValidityResponse) Collections(java.util.Collections) GrpcSslContexts(io.grpc.netty.GrpcSslContexts) UpdateStreamStatus(io.pravega.controller.stream.api.grpc.v1.Controller.UpdateStreamStatus) InvalidStreamException(io.pravega.client.stream.InvalidStreamException)

Example 7 with InvalidStreamException

use of io.pravega.client.stream.InvalidStreamException in project pravega by pravega.

the class ControllerImpl method abortTransaction.

@Override
public CompletableFuture<Void> abortTransaction(final Stream stream, final UUID txId) {
    Exceptions.checkNotClosed(closed.get(), this);
    Preconditions.checkNotNull(stream, "stream");
    Preconditions.checkNotNull(txId, "txId");
    long traceId = LoggerHelpers.traceEnter(log, "abortTransaction", stream, txId);
    final long requestId = requestIdGenerator.get();
    log.info(requestId, "Abort transaction {} invoked on stream {}", txId, stream);
    final CompletableFuture<TxnStatus> result = this.retryConfig.runAsync(() -> {
        RPCAsyncCallback<TxnStatus> callback = new RPCAsyncCallback<>(traceId, "abortTransaction", stream, txId);
        new ControllerClientTagger(client, timeoutMillis).withTag(requestId, ABORT_TRANSACTION, stream.getScope(), stream.getStreamName(), txId.toString()).abortTransaction(TxnRequest.newBuilder().setStreamInfo(ModelHelper.createStreamInfo(stream.getScope(), stream.getStreamName())).setTxnId(ModelHelper.decode(txId)).build(), callback);
        return callback.getFuture();
    }, this.executor);
    return result.thenApplyAsync(txnStatus -> {
        LoggerHelpers.traceLeave(log, "abortTransaction", traceId, stream, txId);
        if (txnStatus.getStatus().equals(TxnStatus.Status.STREAM_NOT_FOUND)) {
            log.warn(requestId, "Stream {} not found while trying to abort transaction {}", stream, txId);
            throw new InvalidStreamException("Stream no longer exists: " + stream);
        }
        if (txnStatus.getStatus().equals(TxnStatus.Status.TRANSACTION_NOT_FOUND)) {
            log.warn(requestId, "transaction {} not found on stream {}", txId, stream);
            throw Exceptions.sneakyThrow(new TxnFailedException("Transaction was already either committed or aborted"));
        }
        if (txnStatus.getStatus().equals(TxnStatus.Status.SUCCESS)) {
            return null;
        }
        log.warn(requestId, "Unable to abort transaction {} on stream {}, abort status is {} ", txId, stream, txnStatus.getStatus());
        throw new RuntimeException("Error aborting transaction: " + txnStatus.getStatus());
    }, this.executor);
}
Also used : StatusRuntimeException(io.grpc.StatusRuntimeException) TxnFailedException(io.pravega.client.stream.TxnFailedException) TxnStatus(io.pravega.controller.stream.api.grpc.v1.Controller.TxnStatus) PingTxnStatus(io.pravega.controller.stream.api.grpc.v1.Controller.PingTxnStatus) InvalidStreamException(io.pravega.client.stream.InvalidStreamException)

Example 8 with InvalidStreamException

use of io.pravega.client.stream.InvalidStreamException in project pravega by pravega.

the class DeleteScopeTask method deleteScopeContent.

public CompletableFuture<Void> deleteScopeContent(String scopeName, OperationContext context, long requestId) {
    Map<String, String> readerGroupMap = new HashMap<>();
    Iterator<Stream> iterator = listStreams(scopeName, context).asIterator();
    // Seal and delete streams and add entry to RGList
    while (iterator.hasNext()) {
        Stream stream = iterator.next();
        Timer timer = new Timer();
        if (stream.getStreamName().startsWith(READER_GROUP_STREAM_PREFIX)) {
            readerGroupMap.put(stream.getStreamName().substring(READER_GROUP_STREAM_PREFIX.length()), stream.getStreamName());
        }
        log.debug("Processing seal and delete stream for Stream {}", stream);
        Futures.getThrowingException(Futures.exceptionallyExpecting(streamMetadataTasks.sealStream(scopeName, stream.getStreamName(), requestId), e -> {
            Throwable unwrap = Exceptions.unwrap(e);
            // ignore failures if the stream doesn't exist or we are unable to seal it.
            return unwrap instanceof InvalidStreamException || unwrap instanceof ControllerFailureException;
        }, Controller.UpdateStreamStatus.Status.STREAM_NOT_FOUND).thenCompose(sealed -> {
            ControllerService.reportSealStreamMetrics(scopeName, stream.getStreamName(), sealed, timer.getElapsed());
            return CompletableFuture.completedFuture(null);
        }).thenCompose(x -> streamMetadataTasks.deleteStream(stream.getScope(), stream.getStreamName(), requestId).thenCompose(status -> {
            ControllerService.reportDeleteStreamMetrics(scopeName, stream.getStreamName(), status, timer.getElapsed());
            return CompletableFuture.completedFuture(null);
        })));
    }
    // Delete ReaderGroups
    for (Map.Entry<String, String> rgMapEntry : readerGroupMap.entrySet()) {
        log.debug("Processing delete ReaderGroup for {}", rgMapEntry.getKey());
        Timer timer = new Timer();
        Futures.getThrowingException(streamMetadataTasks.getReaderGroupConfig(scopeName, rgMapEntry.getKey(), requestId).thenCompose(conf -> streamMetadataTasks.deleteReaderGroup(scopeName, rgMapEntry.getKey(), conf.getConfig().getReaderGroupId(), requestId).thenCompose(status -> {
            ControllerService.reportDeleteReaderGroupMetrics(scopeName, rgMapEntry.getValue(), status, timer.getElapsed());
            return CompletableFuture.completedFuture(null);
        })));
    }
    // Delete KVTs
    Iterator<KeyValueTableInfo> kvtIterator = listKVTs(scopeName, requestId, context).asIterator();
    while (kvtIterator.hasNext()) {
        String kvt = kvtIterator.next().getKeyValueTableName();
        Timer timer = new Timer();
        log.debug("Processing delete kvt for {}", kvt);
        Futures.getThrowingException(kvtMetadataTasks.deleteKeyValueTable(scopeName, kvt, context.getRequestId()).thenCompose(status -> {
            ControllerService.reportDeleteKVTableMetrics(scopeName, kvt, status, timer.getElapsed());
            return CompletableFuture.completedFuture(null);
        }));
    }
    return streamMetadataStore.deleteScopeRecursive(scopeName, context, executor).thenApply(status -> {
        log.debug("Recursive Delete Scope returned with a status {}", status);
        return null;
    });
}
Also used : OperationContext(io.pravega.controller.store.stream.OperationContext) StreamImpl(io.pravega.client.stream.impl.StreamImpl) Exceptions(io.pravega.common.Exceptions) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) Function(java.util.function.Function) TagLogger(io.pravega.common.tracing.TagLogger) KeyValueTableInfo(io.pravega.client.admin.KeyValueTableInfo) Stream(io.pravega.client.stream.Stream) Map(java.util.Map) ControllerFailureException(io.pravega.client.control.impl.ControllerFailureException) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) StreamMetadataTasks(io.pravega.controller.task.Stream.StreamMetadataTasks) Controller(io.pravega.controller.stream.api.grpc.v1.Controller) ControllerService(io.pravega.controller.server.ControllerService) Iterator(java.util.Iterator) Collection(java.util.Collection) DeleteScopeEvent(io.pravega.shared.controller.event.DeleteScopeEvent) AsyncIterator(io.pravega.common.util.AsyncIterator) UUID(java.util.UUID) Timer(io.pravega.common.Timer) TableMetadataTasks(io.pravega.controller.task.KeyValueTable.TableMetadataTasks) Collectors(java.util.stream.Collectors) KVTableMetadataStore(io.pravega.controller.store.kvtable.KVTableMetadataStore) READER_GROUP_STREAM_PREFIX(io.pravega.shared.NameUtils.READER_GROUP_STREAM_PREFIX) AbstractMap(java.util.AbstractMap) List(java.util.List) ContinuationTokenAsyncIterator(io.pravega.common.util.ContinuationTokenAsyncIterator) InvalidStreamException(io.pravega.client.stream.InvalidStreamException) Preconditions(com.google.common.base.Preconditions) StreamMetadataStore(io.pravega.controller.store.stream.StreamMetadataStore) Futures(io.pravega.common.concurrent.Futures) HashMap(java.util.HashMap) InvalidStreamException(io.pravega.client.stream.InvalidStreamException) KeyValueTableInfo(io.pravega.client.admin.KeyValueTableInfo) Timer(io.pravega.common.Timer) ControllerFailureException(io.pravega.client.control.impl.ControllerFailureException) Stream(io.pravega.client.stream.Stream) HashMap(java.util.HashMap) Map(java.util.Map) AbstractMap(java.util.AbstractMap)

Example 9 with InvalidStreamException

use of io.pravega.client.stream.InvalidStreamException in project pravega by pravega.

the class ReaderGroupManagerImplTest method testMissingGetReaderGroup.

@Test(expected = ReaderGroupNotFoundException.class)
public void testMissingGetReaderGroup() {
    when(clientFactory.createStateSynchronizer(anyString(), any(Serializer.class), any(Serializer.class), any(SynchronizerConfig.class))).thenThrow(new InvalidStreamException("invalid RG stream"));
    readerGroupManager.getReaderGroup(GROUP_NAME);
}
Also used : SynchronizerConfig(io.pravega.client.state.SynchronizerConfig) InvalidStreamException(io.pravega.client.stream.InvalidStreamException) Serializer(io.pravega.client.stream.Serializer) Test(org.junit.Test)

Example 10 with InvalidStreamException

use of io.pravega.client.stream.InvalidStreamException in project pravega by pravega.

the class ReaderGroupManagerImpl method deleteReaderGroup.

@Override
public void deleteReaderGroup(String groupName) {
    UUID readerGroupId = null;
    ReaderGroupConfig syncConfig = null;
    try {
        @Cleanup StateSynchronizer<ReaderGroupState> synchronizer = clientFactory.createStateSynchronizer(NameUtils.getStreamForReaderGroup(groupName), new ReaderGroupStateUpdatesSerializer(), new ReaderGroupStateInitSerializer(), SynchronizerConfig.builder().build());
        synchronizer.fetchUpdates();
        syncConfig = synchronizer.getState().getConfig();
        readerGroupId = syncConfig.getReaderGroupId();
        if (ReaderGroupConfig.DEFAULT_UUID.equals(syncConfig.getReaderGroupId()) && ReaderGroupConfig.DEFAULT_GENERATION == syncConfig.getGeneration()) {
            // migrate RG case
            try {
                controller.getReaderGroupConfig(scope, groupName).thenCompose(conf -> controller.deleteReaderGroup(scope, groupName, conf.getReaderGroupId())).join();
            } catch (ReaderGroupNotFoundException ex) {
                controller.sealStream(scope, getStreamForReaderGroup(groupName)).thenCompose(b -> controller.deleteStream(scope, getStreamForReaderGroup(groupName))).exceptionally(e -> {
                    log.warn("Failed to delete ReaderGroup Stream {}", getStreamForReaderGroup(groupName), e);
                    throw Exceptions.sneakyThrow(e);
                }).join();
            }
            return;
        }
    } catch (InvalidStreamException ex) {
        log.warn("State-Synchronizer Stream for ReaderGroup {} was not found.", NameUtils.getScopedReaderGroupName(scope, groupName));
        // if the State Synchronizer Stream was deleted, but the RG still exists, get Id from Controller
        readerGroupId = getAndHandleExceptions(controller.getReaderGroupConfig(scope, groupName), RuntimeException::new).getReaderGroupId();
    }
    // normal delete
    getAndHandleExceptions(controller.deleteReaderGroup(scope, groupName, readerGroupId), RuntimeException::new);
}
Also used : ReaderGroupConfig(io.pravega.client.stream.ReaderGroupConfig) StateSynchronizer(io.pravega.client.state.StateSynchronizer) Arrays(java.util.Arrays) ReaderGroupImpl(io.pravega.client.stream.impl.ReaderGroupImpl) Getter(lombok.Getter) SneakyThrows(lombok.SneakyThrows) ConnectionFactory(io.pravega.client.connection.impl.ConnectionFactory) Exceptions(io.pravega.common.Exceptions) Cleanup(lombok.Cleanup) ReaderGroup(io.pravega.client.stream.ReaderGroup) ConnectionPoolImpl(io.pravega.client.connection.impl.ConnectionPoolImpl) ByteBuffer(java.nio.ByteBuffer) NameUtils.getStreamForReaderGroup(io.pravega.shared.NameUtils.getStreamForReaderGroup) Update(io.pravega.client.state.Update) ReaderGroupNotFoundException(io.pravega.client.stream.ReaderGroupNotFoundException) AccessLevel(lombok.AccessLevel) ClientFactoryImpl(io.pravega.client.stream.impl.ClientFactoryImpl) ReaderGroupManager(io.pravega.client.admin.ReaderGroupManager) Map(java.util.Map) Futures.getThrowingException(io.pravega.common.concurrent.Futures.getThrowingException) SynchronizerConfig(io.pravega.client.state.SynchronizerConfig) ReaderGroupConfig(io.pravega.client.stream.ReaderGroupConfig) Serializer(io.pravega.client.stream.Serializer) NameUtils(io.pravega.shared.NameUtils) Futures.getAndHandleExceptions(io.pravega.common.concurrent.Futures.getAndHandleExceptions) IOException(java.io.IOException) UUID(java.util.UUID) InitialUpdate(io.pravega.client.state.InitialUpdate) SegmentWithRange(io.pravega.client.stream.impl.SegmentWithRange) AbstractClientFactoryImpl(io.pravega.client.stream.impl.AbstractClientFactoryImpl) ControllerImplConfig(io.pravega.client.control.impl.ControllerImplConfig) Slf4j(lombok.extern.slf4j.Slf4j) ByteArraySegment(io.pravega.common.util.ByteArraySegment) ConfigMismatchException(io.pravega.client.stream.ConfigMismatchException) ReaderGroupImpl.getEndSegmentsForStreams(io.pravega.client.stream.impl.ReaderGroupImpl.getEndSegmentsForStreams) ControllerImpl(io.pravega.client.control.impl.ControllerImpl) InvalidStreamException(io.pravega.client.stream.InvalidStreamException) VisibleForTesting(com.google.common.annotations.VisibleForTesting) Controller(io.pravega.client.control.impl.Controller) ClientConfig(io.pravega.client.ClientConfig) ReaderGroupState(io.pravega.client.stream.impl.ReaderGroupState) ReaderGroupNotFoundException(io.pravega.client.stream.ReaderGroupNotFoundException) UUID(java.util.UUID) ReaderGroupState(io.pravega.client.stream.impl.ReaderGroupState) Cleanup(lombok.Cleanup) InvalidStreamException(io.pravega.client.stream.InvalidStreamException)

Aggregations

InvalidStreamException (io.pravega.client.stream.InvalidStreamException)10 Stream (io.pravega.client.stream.Stream)6 Exceptions (io.pravega.common.Exceptions)6 Futures (io.pravega.common.concurrent.Futures)5 CompletableFuture (java.util.concurrent.CompletableFuture)5 VisibleForTesting (com.google.common.annotations.VisibleForTesting)4 Preconditions (com.google.common.base.Preconditions)4 KeyValueTableInfo (io.pravega.client.admin.KeyValueTableInfo)4 TxnFailedException (io.pravega.client.stream.TxnFailedException)4 PingTxnStatus (io.pravega.controller.stream.api.grpc.v1.Controller.PingTxnStatus)4 TxnStatus (io.pravega.controller.stream.api.grpc.v1.Controller.TxnStatus)4 Collection (java.util.Collection)4 List (java.util.List)4 ClientConfig (io.pravega.client.ClientConfig)3 ConnectionPoolImpl (io.pravega.client.connection.impl.ConnectionPoolImpl)3 Controller (io.pravega.client.control.impl.Controller)3 ControllerFailureException (io.pravega.client.control.impl.ControllerFailureException)3 ReaderGroupConfig (io.pravega.client.stream.ReaderGroupConfig)3 ReaderGroupNotFoundException (io.pravega.client.stream.ReaderGroupNotFoundException)3 StreamConfiguration (io.pravega.client.stream.StreamConfiguration)3