Search in sources :

Example 16 with AbortEvent

use of io.pravega.shared.controller.event.AbortEvent in project pravega by pravega.

the class AbortRequestHandler method processEvent.

@Override
public CompletableFuture<Void> processEvent(AbortEvent event) {
    String scope = event.getScope();
    String stream = event.getStream();
    int epoch = event.getEpoch();
    UUID txId = event.getTxid();
    long requestId = event.getRequestId();
    if (requestId == 0L) {
        requestId = ControllerService.nextRequestId();
    }
    Timer timer = new Timer();
    OperationContext context = streamMetadataStore.createStreamContext(scope, stream, requestId);
    log.info(requestId, "Aborting transaction {} on stream {}/{}", event.getTxid(), event.getScope(), event.getStream());
    return Futures.toVoid(streamMetadataStore.getSegmentsInEpoch(event.getScope(), event.getStream(), epoch, context, executor).thenApply(segments -> segments.stream().map(StreamSegmentRecord::segmentId).collect(Collectors.toList())).thenCompose(segments -> streamMetadataTasks.notifyTxnAbort(scope, stream, segments, txId, context.getRequestId())).thenCompose(x -> streamMetadataStore.abortTransaction(scope, stream, txId, context, executor)).whenComplete((result, error) -> {
        if (error != null) {
            log.warn(context.getRequestId(), "Failed aborting transaction {} on stream {}/{}", event.getTxid(), event.getScope(), event.getStream());
            TransactionMetrics.getInstance().abortTransactionFailed(scope, stream);
        } else {
            log.info(context.getRequestId(), "Successfully aborted transaction {} on stream {}/{}", event.getTxid(), event.getScope(), event.getStream());
            if (processedEvents != null) {
                processedEvents.offer(event);
            }
            TransactionMetrics.getInstance().abortTransaction(scope, stream, timer.getElapsed());
        }
    }));
}
Also used : OperationContext(io.pravega.controller.store.stream.OperationContext) ControllerService(io.pravega.controller.server.ControllerService) OperationContext(io.pravega.controller.store.stream.OperationContext) SerializedRequestHandler(io.pravega.controller.eventProcessor.impl.SerializedRequestHandler) TransactionMetrics(io.pravega.controller.metrics.TransactionMetrics) StreamSegmentRecord(io.pravega.controller.store.stream.records.StreamSegmentRecord) LoggerFactory(org.slf4j.LoggerFactory) BlockingQueue(java.util.concurrent.BlockingQueue) CompletableFuture(java.util.concurrent.CompletableFuture) UUID(java.util.UUID) Timer(io.pravega.common.Timer) Collectors(java.util.stream.Collectors) TagLogger(io.pravega.common.tracing.TagLogger) AbortEvent(io.pravega.shared.controller.event.AbortEvent) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) StreamMetadataTasks(io.pravega.controller.task.Stream.StreamMetadataTasks) VisibleForTesting(com.google.common.annotations.VisibleForTesting) StreamMetadataStore(io.pravega.controller.store.stream.StreamMetadataStore) Futures(io.pravega.common.concurrent.Futures) StreamSegmentRecord(io.pravega.controller.store.stream.records.StreamSegmentRecord) Timer(io.pravega.common.Timer) UUID(java.util.UUID)

Example 17 with AbortEvent

use of io.pravega.shared.controller.event.AbortEvent in project pravega by pravega.

the class ControllerEventProcessors method initialize.

private void initialize() {
    // region Create commit event processor
    EventProcessorGroupConfig commitReadersConfig = EventProcessorGroupConfigImpl.builder().streamName(config.getCommitStreamName()).readerGroupName(config.getCommitReaderGroupName()).eventProcessorCount(config.getCommitReaderGroupSize()).checkpointConfig(CheckpointConfig.none()).build();
    EventProcessorConfig<CommitEvent> commitConfig = EventProcessorConfig.<CommitEvent>builder().config(commitReadersConfig).decider(ExceptionHandler.DEFAULT_EXCEPTION_HANDLER).serializer(COMMIT_EVENT_SERIALIZER).supplier(() -> new ConcurrentEventProcessor<>(commitRequestHandler, executor)).minRebalanceIntervalMillis(rebalanceIntervalMillis).build();
    log.debug("Creating commit event processors");
    Retry.indefinitelyWithExpBackoff(DELAY, MULTIPLIER, MAX_DELAY, e -> log.warn("Error creating commit event processor group", e)).run(() -> {
        commitEventProcessors = system.createEventProcessorGroup(commitConfig, checkpointStore, rebalanceExecutor);
        return null;
    });
    // endregion
    // region Create abort event processor
    EventProcessorGroupConfig abortReadersConfig = EventProcessorGroupConfigImpl.builder().streamName(config.getAbortStreamName()).readerGroupName(config.getAbortReaderGroupName()).eventProcessorCount(config.getAbortReaderGroupSize()).checkpointConfig(CheckpointConfig.none()).build();
    EventProcessorConfig<AbortEvent> abortConfig = EventProcessorConfig.<AbortEvent>builder().config(abortReadersConfig).decider(ExceptionHandler.DEFAULT_EXCEPTION_HANDLER).serializer(ABORT_EVENT_SERIALIZER).supplier(() -> new ConcurrentEventProcessor<>(abortRequestHandler, executor)).minRebalanceIntervalMillis(rebalanceIntervalMillis).build();
    log.debug("Creating abort event processors");
    Retry.indefinitelyWithExpBackoff(DELAY, MULTIPLIER, MAX_DELAY, e -> log.warn("Error creating commit event processor group", e)).run(() -> {
        abortEventProcessors = system.createEventProcessorGroup(abortConfig, checkpointStore, rebalanceExecutor);
        return null;
    });
    // endregion
    // region Create request event processor
    EventProcessorGroupConfig requestReadersConfig = EventProcessorGroupConfigImpl.builder().streamName(config.getRequestStreamName()).readerGroupName(config.getRequestReaderGroupName()).eventProcessorCount(1).checkpointConfig(CheckpointConfig.none()).build();
    EventProcessorConfig<ControllerEvent> requestConfig = EventProcessorConfig.builder().config(requestReadersConfig).decider(ExceptionHandler.DEFAULT_EXCEPTION_HANDLER).serializer(CONTROLLER_EVENT_SERIALIZER).supplier(() -> new ConcurrentEventProcessor<>(streamRequestHandler, executor)).minRebalanceIntervalMillis(rebalanceIntervalMillis).build();
    log.debug("Creating stream request event processors");
    Retry.indefinitelyWithExpBackoff(DELAY, MULTIPLIER, MAX_DELAY, e -> log.warn("Error creating request event processor group", e)).run(() -> {
        requestEventProcessors = system.createEventProcessorGroup(requestConfig, checkpointStore, rebalanceExecutor);
        return null;
    });
    // endregion
    // region Create KVtable event processor
    EventProcessorGroupConfig kvtReadersConfig = EventProcessorGroupConfigImpl.builder().streamName(config.getKvtStreamName()).readerGroupName(config.getKvtReaderGroupName()).eventProcessorCount(1).checkpointConfig(CheckpointConfig.none()).build();
    EventProcessorConfig<ControllerEvent> kvtRequestConfig = EventProcessorConfig.builder().config(kvtReadersConfig).decider(ExceptionHandler.DEFAULT_EXCEPTION_HANDLER).serializer(CONTROLLER_EVENT_SERIALIZER).supplier(() -> new ConcurrentEventProcessor<>(kvtRequestHandler, executor)).minRebalanceIntervalMillis(rebalanceIntervalMillis).build();
    log.debug("Creating kvt request event processors");
    Retry.indefinitelyWithExpBackoff(DELAY, MULTIPLIER, MAX_DELAY, e -> log.warn("Error creating request event processor group", e)).run(() -> {
        kvtRequestEventProcessors = system.createEventProcessorGroup(kvtRequestConfig, checkpointStore, rebalanceExecutor);
        return null;
    });
    // endregion
    log.info("Awaiting start of event processors...");
    commitEventProcessors.awaitRunning();
    log.info("Commit event processor started.");
    abortEventProcessors.awaitRunning();
    log.info("Abort event processor started.");
    requestEventProcessors.awaitRunning();
    log.info("Stream request event processor started.");
    kvtRequestEventProcessors.awaitRunning();
    log.info("KVT request event processor started.");
}
Also used : CommitEvent(io.pravega.shared.controller.event.CommitEvent) Retry(io.pravega.common.util.Retry) ReaderGroupManagerImpl(io.pravega.client.admin.impl.ReaderGroupManagerImpl) TimeoutException(java.util.concurrent.TimeoutException) CheckpointStore(io.pravega.controller.store.checkpoint.CheckpointStore) StreamConfiguration(io.pravega.client.stream.StreamConfiguration) CheckpointStoreException(io.pravega.controller.store.checkpoint.CheckpointStoreException) CheckpointConfig(io.pravega.controller.eventProcessor.CheckpointConfig) ClientFactoryImpl(io.pravega.client.stream.impl.ClientFactoryImpl) Position(io.pravega.client.stream.Position) AbortRequestHandler(io.pravega.controller.server.eventProcessor.requesthandlers.AbortRequestHandler) AutoScaleTask(io.pravega.controller.server.eventProcessor.requesthandlers.AutoScaleTask) Duration(java.time.Duration) Map(java.util.Map) RETRYABLE_PREDICATE(io.pravega.controller.util.RetryHelper.RETRYABLE_PREDICATE) ExceptionHandler(io.pravega.controller.eventProcessor.ExceptionHandler) RetryHelper.withRetriesAsync(io.pravega.controller.util.RetryHelper.withRetriesAsync) EventProcessorConfig(io.pravega.controller.eventProcessor.EventProcessorConfig) SealStreamTask(io.pravega.controller.server.eventProcessor.requesthandlers.SealStreamTask) CreateTableTask(io.pravega.controller.server.eventProcessor.requesthandlers.kvtable.CreateTableTask) Set(java.util.Set) CompletionException(java.util.concurrent.CompletionException) ScaleOperationTask(io.pravega.controller.server.eventProcessor.requesthandlers.ScaleOperationTask) DeleteTableTask(io.pravega.controller.server.eventProcessor.requesthandlers.kvtable.DeleteTableTask) Collectors(java.util.stream.Collectors) ControllerEvent(io.pravega.shared.controller.event.ControllerEvent) KVTableMetadataStore(io.pravega.controller.store.kvtable.KVTableMetadataStore) Slf4j(lombok.extern.slf4j.Slf4j) List(java.util.List) ConcurrentEventProcessor(io.pravega.controller.eventProcessor.impl.ConcurrentEventProcessor) EventProcessorSystemImpl(io.pravega.controller.eventProcessor.impl.EventProcessorSystemImpl) Config(io.pravega.controller.util.Config) UpdateStreamTask(io.pravega.controller.server.eventProcessor.requesthandlers.UpdateStreamTask) CreateReaderGroupTask(io.pravega.controller.server.eventProcessor.requesthandlers.CreateReaderGroupTask) StreamMetadataStore(io.pravega.controller.store.stream.StreamMetadataStore) Futures(io.pravega.common.concurrent.Futures) DeleteScopeTask(io.pravega.controller.server.eventProcessor.requesthandlers.DeleteScopeTask) TruncateStreamTask(io.pravega.controller.server.eventProcessor.requesthandlers.TruncateStreamTask) Getter(lombok.Getter) Exceptions(io.pravega.common.Exceptions) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) EventProcessorGroupConfigImpl(io.pravega.controller.eventProcessor.impl.EventProcessorGroupConfigImpl) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) Supplier(java.util.function.Supplier) ArrayList(java.util.ArrayList) TableRequestHandler(io.pravega.controller.server.eventProcessor.requesthandlers.kvtable.TableRequestHandler) BucketStore(io.pravega.controller.store.stream.BucketStore) AbortEvent(io.pravega.shared.controller.event.AbortEvent) EventSerializer(io.pravega.controller.eventProcessor.EventSerializer) AbstractIdleService(com.google.common.util.concurrent.AbstractIdleService) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) StreamMetadataTasks(io.pravega.controller.task.Stream.StreamMetadataTasks) UpdateReaderGroupTask(io.pravega.controller.server.eventProcessor.requesthandlers.UpdateReaderGroupTask) LoggerHelpers(io.pravega.common.LoggerHelpers) ConnectionPool(io.pravega.client.connection.impl.ConnectionPool) TableMetadataTasks(io.pravega.controller.task.KeyValueTable.TableMetadataTasks) FailoverSweeper(io.pravega.controller.fault.FailoverSweeper) ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair) EventProcessorGroupConfig(io.pravega.controller.eventProcessor.EventProcessorGroupConfig) TimeUnit(java.util.concurrent.TimeUnit) AtomicLong(java.util.concurrent.atomic.AtomicLong) PositionImpl(io.pravega.client.stream.impl.PositionImpl) EventProcessorSystem(io.pravega.controller.eventProcessor.EventProcessorSystem) StreamTransactionMetadataTasks(io.pravega.controller.task.Stream.StreamTransactionMetadataTasks) DeleteStreamTask(io.pravega.controller.server.eventProcessor.requesthandlers.DeleteStreamTask) EventProcessorGroup(io.pravega.controller.eventProcessor.EventProcessorGroup) StreamRequestHandler(io.pravega.controller.server.eventProcessor.requesthandlers.StreamRequestHandler) Preconditions(com.google.common.base.Preconditions) VisibleForTesting(com.google.common.annotations.VisibleForTesting) ExecutorServiceHelpers(io.pravega.common.concurrent.ExecutorServiceHelpers) CommitRequestHandler(io.pravega.controller.server.eventProcessor.requesthandlers.CommitRequestHandler) DeleteReaderGroupTask(io.pravega.controller.server.eventProcessor.requesthandlers.DeleteReaderGroupTask) Collections(java.util.Collections) EventProcessorGroupConfig(io.pravega.controller.eventProcessor.EventProcessorGroupConfig) CommitEvent(io.pravega.shared.controller.event.CommitEvent) AbortEvent(io.pravega.shared.controller.event.AbortEvent) ControllerEvent(io.pravega.shared.controller.event.ControllerEvent)

Example 18 with AbortEvent

use of io.pravega.shared.controller.event.AbortEvent in project pravega by pravega.

the class TxnSweeper method failOverAbortingTxn.

private CompletableFuture<Void> failOverAbortingTxn(String failedHost, int epoch, TxnResource txn) {
    String scope = txn.getScope();
    String stream = txn.getStream();
    UUID txnId = txn.getTxnId();
    log.info("Host = {}, failing over aborting transaction {}/{}/{}", failedHost, scope, stream, txnId);
    return transactionMetadataTasks.writeAbortEvent(new AbortEvent(scope, stream, epoch, txnId, ControllerService.nextRequestId())).thenComposeAsync(status -> streamMetadataStore.removeTxnFromIndex(failedHost, txn, true), executor);
}
Also used : UUID(java.util.UUID) AbortEvent(io.pravega.shared.controller.event.AbortEvent)

Aggregations

AbortEvent (io.pravega.shared.controller.event.AbortEvent)18 UUID (java.util.UUID)15 CommitEvent (io.pravega.shared.controller.event.CommitEvent)14 Test (org.junit.Test)12 StreamMetadataStore (io.pravega.controller.store.stream.StreamMetadataStore)11 VersionedTransactionData (io.pravega.controller.store.stream.VersionedTransactionData)10 StreamConfiguration (io.pravega.client.stream.StreamConfiguration)9 GrpcAuthHelper (io.pravega.controller.server.security.auth.GrpcAuthHelper)9 CompletableFuture (java.util.concurrent.CompletableFuture)9 ScalingPolicy (io.pravega.client.stream.ScalingPolicy)8 List (java.util.List)8 Futures (io.pravega.common.concurrent.Futures)7 EventStreamWriterMock (io.pravega.controller.mocks.EventStreamWriterMock)7 TxnStatus (io.pravega.controller.store.stream.TxnStatus)7 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)7 Config (io.pravega.controller.util.Config)6 EventStreamWriter (io.pravega.client.stream.EventStreamWriter)5 EventWriterConfig (io.pravega.client.stream.EventWriterConfig)5 Exceptions (io.pravega.common.Exceptions)5 TransactionMetrics (io.pravega.controller.metrics.TransactionMetrics)5