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;
}
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);
}
});
}
Aggregations