use of io.pravega.common.Timer 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);
}
use of io.pravega.common.Timer in project pravega by pravega.
the class MetricsProviderTest method testOpStatsData.
/**
* Test Event and Value registered and worked well with OpStats.
*/
@Test
public void testOpStatsData() {
Timer startTime = new Timer();
OpStatsLogger opStatsLogger = statsLogger.createStats("testOpStatsLogger");
// register 2 event: 1 success, 1 fail.
opStatsLogger.reportSuccessEvent(startTime.getElapsed());
opStatsLogger.reportFailEvent(startTime.getElapsed());
opStatsLogger.reportSuccessValue(startTime.getElapsedMillis());
opStatsLogger.reportFailValue(startTime.getElapsedMillis());
opStatsLogger.reportSuccessValue(1);
opStatsLogger.reportFailValue(1);
opStatsLogger.reportSuccessValue(1);
OpStatsData statsData = opStatsLogger.toOpStatsData();
// 2 = 2 event + 2 value
assertEquals(4, statsData.getNumSuccessfulEvents());
assertEquals(3, statsData.getNumFailedEvents());
}
use of io.pravega.common.Timer in project pravega by pravega.
the class PravegaRequestProcessor method readSegment.
// endregion
// region RequestProcessor Implementation
@Override
public void readSegment(ReadSegment readSegment) {
Timer timer = new Timer();
final String segment = readSegment.getSegment();
if (!verifyToken(segment, readSegment.getOffset(), readSegment.getDelegationToken(), READ, "Read Segment")) {
return;
}
final int readSize = min(MAX_READ_SIZE, max(TYPE_PLUS_LENGTH_SIZE, readSegment.getSuggestedLength()));
long trace = LoggerHelpers.traceEnter(log, "readSegment", readSegment);
segmentStore.read(segment, readSegment.getOffset(), readSize, TIMEOUT).thenAccept(readResult -> {
LoggerHelpers.traceLeave(log, "readSegment", trace, readResult);
handleReadResult(readSegment, readResult);
DYNAMIC_LOGGER.incCounterValue(nameFromSegment(SEGMENT_READ_BYTES, segment), readResult.getConsumedLength());
readStreamSegment.reportSuccessEvent(timer.getElapsed());
}).exceptionally(ex -> handleException(readSegment.getOffset(), segment, "Read segment", ex));
}
Aggregations