use of io.pravega.segmentstore.server.logs.operations.Operation in project pravega by pravega.
the class SegmentAggregator method reconcile.
private CompletableFuture<FlushResult> reconcile(TimeoutTimer timer) {
assert this.state.get() == AggregatorState.Reconciling : "reconcile cannot be called if state == " + this.state;
ReconciliationState rc = this.reconciliationState.get();
assert rc != null : "reconciliationState is null";
SegmentProperties storageInfo = rc.getStorageInfo();
long traceId = LoggerHelpers.traceEnterWithContext(log, this.traceObjectId, "reconcile", rc);
// Process each Operation in sequence, as long as its starting offset is less than ReconciliationState.getStorageInfo().getLength()
FlushResult result = new FlushResult();
AtomicBoolean exceededStorageLength = new AtomicBoolean(false);
return Futures.loop(() -> this.operations.size() > 0 && !exceededStorageLength.get(), () -> {
StorageOperation op = this.operations.getFirst();
return reconcileOperation(op, storageInfo, timer).thenApply(partialFlushResult -> {
if (op.getLastStreamSegmentOffset() >= storageInfo.getLength()) {
// This operation crosses the boundary of StorageLength. It has been reconciled,
// and as such it is the last operation that we need to inspect.
exceededStorageLength.set(true);
}
log.info("{}: Reconciled {} ({}).", this.traceObjectId, op, partialFlushResult);
return partialFlushResult;
});
}, result::withFlushResult, this.executor).thenApply(v -> {
updateMetadata(storageInfo);
this.reconciliationState.set(null);
setState(AggregatorState.Writing);
LoggerHelpers.traceLeave(log, this.traceObjectId, "reconcile", traceId, result);
return result;
});
}
Aggregations