use of io.pravega.segmentstore.storage.Storage in project pravega by pravega.
the class SegmentAggregator method flush.
// endregion
// region Flushing and Merging
/**
* Flushes the contents of the Aggregator to the Storage.
*
* @param timeout Timeout for the operation.
* @return A CompletableFuture that, when completed, will contain a summary of the flush operation. If any errors
* occurred during the flush, the Future will be completed with the appropriate exception.
*/
CompletableFuture<FlushResult> flush(Duration timeout) {
ensureInitializedAndNotClosed();
if (this.metadata.isDeleted()) {
// Segment has been deleted; don't do anything else.
return CompletableFuture.completedFuture(new FlushResult());
}
long traceId = LoggerHelpers.traceEnterWithContext(log, this.traceObjectId, "flush");
TimeoutTimer timer = new TimeoutTimer(timeout);
CompletableFuture<FlushResult> result;
try {
switch(this.state.get()) {
case Writing:
result = flushNormally(timer);
break;
case ReconciliationNeeded:
result = beginReconciliation(timer).thenComposeAsync(v -> reconcile(timer), this.executor);
break;
case Reconciling:
result = reconcile(timer);
break;
// $CASES-OMITTED$
default:
result = Futures.failedFuture(new IllegalStateException(String.format("Unexpected state for SegmentAggregator (%s) for segment '%s'.", this.state, this.metadata.getName())));
break;
}
} catch (Exception ex) {
// Convert synchronous errors into async errors - it's easier to handle on the receiving end.
result = Futures.failedFuture(ex);
}
return result.thenApply(r -> {
LoggerHelpers.traceLeave(log, this.traceObjectId, "flush", traceId, r);
return r;
});
}
use of io.pravega.segmentstore.storage.Storage in project pravega by pravega.
the class StorageWriter method flush.
// endregion
// region Stage Execution
/**
* Flushes eligible operations to Storage, if necessary. Does not perform any mergers.
*/
private CompletableFuture<Void> flush(Void ignored) {
checkRunning();
long traceId = LoggerHelpers.traceEnterWithContext(log, this.traceObjectId, "flush");
// Flush everything we can flush.
val flushFutures = this.aggregators.values().stream().filter(SegmentAggregator::mustFlush).map(a -> a.flush(this.config.getFlushTimeout())).collect(Collectors.toList());
return Futures.allOfWithResults(flushFutures).thenAcceptAsync(flushResults -> {
FlushStageResult result = new FlushStageResult();
flushResults.forEach(result::withFlushResult);
if (result.getFlushedBytes() + result.getMergedBytes() + result.count > 0) {
logStageEvent("Flush", result);
}
LoggerHelpers.traceLeave(log, this.traceObjectId, "flush", traceId);
}, this.executor);
}
Aggregations