use of io.pravega.auth.AuthHandler.Permissions.READ_UPDATE in project pravega by pravega.
the class PravegaRequestProcessor method sealSegment.
@Override
public void sealSegment(SealSegment sealSegment) {
String segment = sealSegment.getSegment();
log.debug("Sealing segment {} ", sealSegment);
if (!verifyToken(segment, sealSegment.getRequestId(), sealSegment.getDelegationToken(), READ_UPDATE, "Seal Segment")) {
return;
}
segmentStore.sealStreamSegment(segment, TIMEOUT).thenAccept(size -> connection.send(new SegmentSealed(sealSegment.getRequestId(), segment))).whenComplete((r, e) -> {
if (e != null) {
handleException(sealSegment.getRequestId(), segment, "Seal segment", e);
} else {
DYNAMIC_LOGGER.freezeCounter(nameFromSegment(SEGMENT_WRITE_BYTES, segment));
DYNAMIC_LOGGER.freezeCounter(nameFromSegment(SEGMENT_WRITE_EVENTS, segment));
if (statsRecorder != null) {
statsRecorder.sealSegment(sealSegment.getSegment());
}
}
});
}
use of io.pravega.auth.AuthHandler.Permissions.READ_UPDATE 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