Search in sources :

Example 1 with CommitTransaction

use of io.pravega.shared.protocol.netty.WireCommands.CommitTransaction in project pravega by pravega.

the class MockController method commitTxSegment.

private CompletableFuture<Void> commitTxSegment(UUID txId, Segment segment) {
    CompletableFuture<Void> result = new CompletableFuture<>();
    FailingReplyProcessor replyProcessor = new FailingReplyProcessor() {

        @Override
        public void connectionDropped() {
            result.completeExceptionally(new ConnectionClosedException());
        }

        @Override
        public void wrongHost(WrongHost wrongHost) {
            result.completeExceptionally(new UnsupportedOperationException());
        }

        @Override
        public void transactionCommitted(TransactionCommitted transactionCommitted) {
            result.complete(null);
        }

        @Override
        public void transactionAborted(TransactionAborted transactionAborted) {
            result.completeExceptionally(new TxnFailedException("Transaction already aborted."));
        }

        @Override
        public void processingFailure(Exception error) {
            result.completeExceptionally(error);
        }

        @Override
        public void authTokenCheckFailed(WireCommands.AuthTokenCheckFailed authTokenCheckFailed) {
            result.completeExceptionally(new AuthenticationException(authTokenCheckFailed.toString()));
        }
    };
    sendRequestOverNewConnection(new CommitTransaction(idGenerator.get(), segment.getScopedName(), txId, ""), replyProcessor, result);
    return result;
}
Also used : AuthenticationException(io.pravega.common.auth.AuthenticationException) FailingReplyProcessor(io.pravega.shared.protocol.netty.FailingReplyProcessor) TransactionAborted(io.pravega.shared.protocol.netty.WireCommands.TransactionAborted) ConnectionClosedException(io.pravega.client.stream.impl.ConnectionClosedException) WrongHost(io.pravega.shared.protocol.netty.WireCommands.WrongHost) AuthenticationException(io.pravega.common.auth.AuthenticationException) TxnFailedException(io.pravega.client.stream.TxnFailedException) ConnectionClosedException(io.pravega.client.stream.impl.ConnectionClosedException) TransactionCommitted(io.pravega.shared.protocol.netty.WireCommands.TransactionCommitted) CommitTransaction(io.pravega.shared.protocol.netty.WireCommands.CommitTransaction) CompletableFuture(java.util.concurrent.CompletableFuture) TxnFailedException(io.pravega.client.stream.TxnFailedException)

Example 2 with CommitTransaction

use of io.pravega.shared.protocol.netty.WireCommands.CommitTransaction in project pravega by pravega.

the class PravegaRequestProcessor method commitTransaction.

@Override
public void commitTransaction(CommitTransaction commitTx) {
    String transactionName = StreamSegmentNameUtils.getTransactionNameFromId(commitTx.getSegment(), commitTx.getTxid());
    long requestId = commitTx.getRequestId();
    log.debug("Committing transaction {} ", commitTx);
    if (!verifyToken(commitTx.getSegment(), commitTx.getRequestId(), commitTx.getDelegationToken(), READ_UPDATE, "Commit Transaction")) {
        return;
    }
    // Seal and Merge can execute concurrently, as long as they are invoked in the correct order (first Seal, then Merge).
    // If Seal fails for whatever reason (except already sealed), then Merge will also fail because the txn is not sealed,
    // but invoking them in parallel does provide benefits in terms of reduced latency.
    val seal = segmentStore.sealStreamSegment(transactionName, TIMEOUT).exceptionally(this::ignoreSegmentSealed).thenCompose(v -> recordStatForTransaction(transactionName, commitTx.getSegment()).exceptionally(e -> {
        // gobble up any errors from stat recording so we do not affect rest of the flow.
        log.error("exception while computing stats while merging txn {}", e);
        return null;
    }));
    val merge = segmentStore.mergeTransaction(transactionName, TIMEOUT).thenAccept(v -> connection.send(new TransactionCommitted(requestId, commitTx.getSegment(), commitTx.getTxid())));
    CompletableFuture.allOf(seal, merge).exceptionally(e -> {
        if (Exceptions.unwrap(e) instanceof StreamSegmentMergedException) {
            log.info("Stream segment is already merged '{}'.", transactionName);
            connection.send(new TransactionCommitted(requestId, commitTx.getSegment(), commitTx.getTxid()));
            return null;
        } else {
            return handleException(requestId, transactionName, "Commit transaction", e);
        }
    });
}
Also used : lombok.val(lombok.val) SCALE_POLICY_RATE(io.pravega.segmentstore.contracts.Attributes.SCALE_POLICY_RATE) Arrays(java.util.Arrays) READ(io.pravega.auth.AuthHandler.Permissions.READ) StreamSegmentNotExistsException(io.pravega.segmentstore.contracts.StreamSegmentNotExistsException) SEGMENT_CREATE_LATENCY(io.pravega.shared.MetricsNames.SEGMENT_CREATE_LATENCY) AuthHandler(io.pravega.auth.AuthHandler) SegmentIsTruncated(io.pravega.shared.protocol.netty.WireCommands.SegmentIsTruncated) CREATION_TIME(io.pravega.segmentstore.contracts.Attributes.CREATION_TIME) MetricsNames.nameFromSegment(io.pravega.shared.MetricsNames.nameFromSegment) GetStreamSegmentInfo(io.pravega.shared.protocol.netty.WireCommands.GetStreamSegmentInfo) ReadResultEntryContents(io.pravega.segmentstore.contracts.ReadResultEntryContents) Duration(java.time.Duration) Map(java.util.Map) SegmentCreated(io.pravega.shared.protocol.netty.WireCommands.SegmentCreated) StreamSegmentStore(io.pravega.segmentstore.contracts.StreamSegmentStore) Attributes(io.pravega.segmentstore.contracts.Attributes) CancellationException(java.util.concurrent.CancellationException) ContainerNotFoundException(io.pravega.segmentstore.contracts.ContainerNotFoundException) Slf4j(lombok.extern.slf4j.Slf4j) CreateSegment(io.pravega.shared.protocol.netty.WireCommands.CreateSegment) SealSegment(io.pravega.shared.protocol.netty.WireCommands.SealSegment) SegmentSealed(io.pravega.shared.protocol.netty.WireCommands.SegmentSealed) EndOfStreamSegment(io.pravega.segmentstore.contracts.ReadResultEntryType.EndOfStreamSegment) SegmentAttribute(io.pravega.shared.protocol.netty.WireCommands.SegmentAttribute) SEGMENT_READ_LATENCY(io.pravega.shared.MetricsNames.SEGMENT_READ_LATENCY) Exceptions(io.pravega.common.Exceptions) BadAttributeUpdateException(io.pravega.segmentstore.contracts.BadAttributeUpdateException) GetSegmentAttribute(io.pravega.shared.protocol.netty.WireCommands.GetSegmentAttribute) ArrayList(java.util.ArrayList) READ_UPDATE(io.pravega.auth.AuthHandler.Permissions.READ_UPDATE) SegmentRead(io.pravega.shared.protocol.netty.WireCommands.SegmentRead) AccessLevel(lombok.AccessLevel) Future(io.pravega.segmentstore.contracts.ReadResultEntryType.Future) FailingRequestProcessor(io.pravega.shared.protocol.netty.FailingRequestProcessor) StreamHelpers(io.pravega.common.io.StreamHelpers) StreamSegmentTruncatedException(io.pravega.segmentstore.contracts.StreamSegmentTruncatedException) StatsLogger(io.pravega.shared.metrics.StatsLogger) OpStatsLogger(io.pravega.shared.metrics.OpStatsLogger) lombok.val(lombok.val) SEGMENT_WRITE_EVENTS(io.pravega.shared.MetricsNames.SEGMENT_WRITE_EVENTS) IOException(java.io.IOException) WireCommands(io.pravega.shared.protocol.netty.WireCommands) WrongHost(io.pravega.shared.protocol.netty.WireCommands.WrongHost) SegmentDeleted(io.pravega.shared.protocol.netty.WireCommands.SegmentDeleted) CreateTransaction(io.pravega.shared.protocol.netty.WireCommands.CreateTransaction) Truncated(io.pravega.segmentstore.contracts.ReadResultEntryType.Truncated) SegmentTruncated(io.pravega.shared.protocol.netty.WireCommands.SegmentTruncated) RequestProcessor(io.pravega.shared.protocol.netty.RequestProcessor) OperationUnsupported(io.pravega.shared.protocol.netty.WireCommands.OperationUnsupported) Preconditions(com.google.common.base.Preconditions) TransactionInfo(io.pravega.shared.protocol.netty.WireCommands.TransactionInfo) AbortTransaction(io.pravega.shared.protocol.netty.WireCommands.AbortTransaction) AuthenticationException(io.pravega.common.auth.AuthenticationException) Cache(io.pravega.segmentstore.contracts.ReadResultEntryType.Cache) SneakyThrows(lombok.SneakyThrows) ByteBuffer(java.nio.ByteBuffer) AttributeUpdate(io.pravega.segmentstore.contracts.AttributeUpdate) StreamSegmentSealedException(io.pravega.segmentstore.contracts.StreamSegmentSealedException) UpdateSegmentAttribute(io.pravega.shared.protocol.netty.WireCommands.UpdateSegmentAttribute) UpdateSegmentPolicy(io.pravega.shared.protocol.netty.WireCommands.UpdateSegmentPolicy) SegmentStatsRecorder(io.pravega.segmentstore.server.host.stat.SegmentStatsRecorder) CommitTransaction(io.pravega.shared.protocol.netty.WireCommands.CommitTransaction) Collection(java.util.Collection) UUID(java.util.UUID) Math.min(java.lang.Math.min) StreamSegmentNameUtils(io.pravega.shared.segment.StreamSegmentNameUtils) MetricsProvider(io.pravega.shared.metrics.MetricsProvider) List(java.util.List) StreamSegmentExistsException(io.pravega.segmentstore.contracts.StreamSegmentExistsException) PassingTokenVerifier(io.pravega.segmentstore.server.host.delegationtoken.PassingTokenVerifier) BadOffsetException(io.pravega.segmentstore.contracts.BadOffsetException) DelegationTokenVerifier(io.pravega.segmentstore.server.host.delegationtoken.DelegationTokenVerifier) Math.max(java.lang.Math.max) SegmentIsSealed(io.pravega.shared.protocol.netty.WireCommands.SegmentIsSealed) ReadResult(io.pravega.segmentstore.contracts.ReadResult) TransactionAborted(io.pravega.shared.protocol.netty.WireCommands.TransactionAborted) DeleteSegment(io.pravega.shared.protocol.netty.WireCommands.DeleteSegment) SegmentPolicyUpdated(io.pravega.shared.protocol.netty.WireCommands.SegmentPolicyUpdated) Getter(lombok.Getter) NoSuchSegment(io.pravega.shared.protocol.netty.WireCommands.NoSuchSegment) CompletableFuture(java.util.concurrent.CompletableFuture) GetTransactionInfo(io.pravega.shared.protocol.netty.WireCommands.GetTransactionInfo) DynamicLogger(io.pravega.shared.metrics.DynamicLogger) SEGMENT_WRITE_BYTES(io.pravega.shared.MetricsNames.SEGMENT_WRITE_BYTES) ReadResultEntry(io.pravega.segmentstore.contracts.ReadResultEntry) SEGMENT_READ_BYTES(io.pravega.shared.MetricsNames.SEGMENT_READ_BYTES) SCALE_POLICY_TYPE(io.pravega.segmentstore.contracts.Attributes.SCALE_POLICY_TYPE) TransactionCommitted(io.pravega.shared.protocol.netty.WireCommands.TransactionCommitted) TYPE_PLUS_LENGTH_SIZE(io.pravega.shared.protocol.netty.WireCommands.TYPE_PLUS_LENGTH_SIZE) StreamSegmentInfo(io.pravega.shared.protocol.netty.WireCommands.StreamSegmentInfo) TransactionCreated(io.pravega.shared.protocol.netty.WireCommands.TransactionCreated) TruncateSegment(io.pravega.shared.protocol.netty.WireCommands.TruncateSegment) ReadSegment(io.pravega.shared.protocol.netty.WireCommands.ReadSegment) SegmentAlreadyExists(io.pravega.shared.protocol.netty.WireCommands.SegmentAlreadyExists) LoggerHelpers(io.pravega.common.LoggerHelpers) StreamSegmentMergedException(io.pravega.segmentstore.contracts.StreamSegmentMergedException) Timer(io.pravega.common.Timer) SegmentAttributeUpdated(io.pravega.shared.protocol.netty.WireCommands.SegmentAttributeUpdated) VisibleForTesting(com.google.common.annotations.VisibleForTesting) AttributeUpdateType(io.pravega.segmentstore.contracts.AttributeUpdateType) Collections(java.util.Collections) StreamSegmentMergedException(io.pravega.segmentstore.contracts.StreamSegmentMergedException) TransactionCommitted(io.pravega.shared.protocol.netty.WireCommands.TransactionCommitted)

Aggregations

AuthenticationException (io.pravega.common.auth.AuthenticationException)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 Preconditions (com.google.common.base.Preconditions)1 AuthHandler (io.pravega.auth.AuthHandler)1 READ (io.pravega.auth.AuthHandler.Permissions.READ)1 READ_UPDATE (io.pravega.auth.AuthHandler.Permissions.READ_UPDATE)1 TxnFailedException (io.pravega.client.stream.TxnFailedException)1 ConnectionClosedException (io.pravega.client.stream.impl.ConnectionClosedException)1 Exceptions (io.pravega.common.Exceptions)1 LoggerHelpers (io.pravega.common.LoggerHelpers)1 Timer (io.pravega.common.Timer)1 StreamHelpers (io.pravega.common.io.StreamHelpers)1 AttributeUpdate (io.pravega.segmentstore.contracts.AttributeUpdate)1 AttributeUpdateType (io.pravega.segmentstore.contracts.AttributeUpdateType)1 Attributes (io.pravega.segmentstore.contracts.Attributes)1 CREATION_TIME (io.pravega.segmentstore.contracts.Attributes.CREATION_TIME)1 SCALE_POLICY_RATE (io.pravega.segmentstore.contracts.Attributes.SCALE_POLICY_RATE)1 SCALE_POLICY_TYPE (io.pravega.segmentstore.contracts.Attributes.SCALE_POLICY_TYPE)1 BadAttributeUpdateException (io.pravega.segmentstore.contracts.BadAttributeUpdateException)1 BadOffsetException (io.pravega.segmentstore.contracts.BadOffsetException)1