use of io.pravega.shared.protocol.netty.WireCommands.TransactionCommitted 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