use of io.pravega.segmentstore.server.logs.operations.MetadataCheckpointOperation in project pravega by pravega.
the class DurableLog method truncate.
@Override
public CompletableFuture<Void> truncate(long upToSequenceNumber, Duration timeout) {
ensureRunning();
Preconditions.checkArgument(this.metadata.isValidTruncationPoint(upToSequenceNumber), "Invalid Truncation Point. Must refer to a MetadataCheckpointOperation.");
// The SequenceNumber we were given points directly to a MetadataCheckpointOperation. We must not remove it!
// Instead, it must be the first operation that does survive, so we need to adjust our SeqNo to the one just
// before it.
long actualTruncationSequenceNumber = upToSequenceNumber - 1;
// Find the closest Truncation Marker (that does not exceed it).
LogAddress truncationFrameAddress = this.metadata.getClosestTruncationMarker(actualTruncationSequenceNumber);
if (truncationFrameAddress == null) {
// Nothing to truncate.
return CompletableFuture.completedFuture(null);
}
TimeoutTimer timer = new TimeoutTimer(timeout);
log.info("{}: Truncate (OperationSequenceNumber = {}, DataFrameAddress = {}).", this.traceObjectId, upToSequenceNumber, truncationFrameAddress);
// info will be readily available upon recovery without delay.
return add(new StorageMetadataCheckpointOperation(), timer.getRemaining()).thenComposeAsync(v -> this.durableDataLog.truncate(truncationFrameAddress, timer.getRemaining()), this.executor).thenRunAsync(() -> {
// Truncate InMemory Transaction Log.
int count = this.inMemoryOperationLog.truncate(actualTruncationSequenceNumber);
// Remove old truncation markers.
this.metadata.removeTruncationMarkers(actualTruncationSequenceNumber);
this.operationProcessor.getMetrics().operationLogTruncate(count);
}, this.executor);
}
Aggregations