Search in sources :

Example 16 with Timer

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);
}
Also used : ObjectClosedException(io.pravega.common.ObjectClosedException) IllegalContainerStateException(io.pravega.segmentstore.server.IllegalContainerStateException) SneakyThrows(lombok.SneakyThrows) Retry(io.pravega.common.util.Retry) StorageMetadataCheckpointOperation(io.pravega.segmentstore.server.logs.operations.StorageMetadataCheckpointOperation) ProbeOperation(io.pravega.segmentstore.server.logs.operations.ProbeOperation) Exceptions(io.pravega.common.Exceptions) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) CompletableFuture(java.util.concurrent.CompletableFuture) LogAddress(io.pravega.segmentstore.storage.LogAddress) StreamingException(io.pravega.segmentstore.contracts.StreamingException) AtomicReference(java.util.concurrent.atomic.AtomicReference) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) UpdateableContainerMetadata(io.pravega.segmentstore.server.UpdateableContainerMetadata) SequencedItemList(io.pravega.common.util.SequencedItemList) Duration(java.time.Duration) AbstractService(com.google.common.util.concurrent.AbstractService) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) Operation(io.pravega.segmentstore.server.logs.operations.Operation) DataLogDisabledException(io.pravega.segmentstore.storage.DataLogDisabledException) LoggerHelpers(io.pravega.common.LoggerHelpers) Services(io.pravega.common.concurrent.Services) ContainerOfflineException(io.pravega.segmentstore.server.ContainerOfflineException) DurableDataLog(io.pravega.segmentstore.storage.DurableDataLog) Iterator(java.util.Iterator) TimeoutTimer(io.pravega.common.TimeoutTimer) MetadataCheckpointOperation(io.pravega.segmentstore.server.logs.operations.MetadataCheckpointOperation) Set(java.util.Set) OperationLog(io.pravega.segmentstore.server.OperationLog) CompletionException(java.util.concurrent.CompletionException) ThreadSafe(javax.annotation.concurrent.ThreadSafe) GuardedBy(javax.annotation.concurrent.GuardedBy) Timer(io.pravega.common.Timer) Collectors(java.util.stream.Collectors) List(java.util.List) Slf4j(lombok.extern.slf4j.Slf4j) Preconditions(com.google.common.base.Preconditions) VisibleForTesting(com.google.common.annotations.VisibleForTesting) ReadIndex(io.pravega.segmentstore.server.ReadIndex) DataCorruptionException(io.pravega.segmentstore.server.DataCorruptionException) DurableDataLogFactory(io.pravega.segmentstore.storage.DurableDataLogFactory) Collections(java.util.Collections) Futures(io.pravega.common.concurrent.Futures) LogAddress(io.pravega.segmentstore.storage.LogAddress) StorageMetadataCheckpointOperation(io.pravega.segmentstore.server.logs.operations.StorageMetadataCheckpointOperation) TimeoutTimer(io.pravega.common.TimeoutTimer)

Example 17 with Timer

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());
}
Also used : Timer(io.pravega.common.Timer) Test(org.junit.Test)

Example 18 with Timer

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));
}
Also used : SCALE_POLICY_RATE(io.pravega.segmentstore.contracts.Attributes.SCALE_POLICY_RATE) Arrays(java.util.Arrays) READ(io.pravega.auth.AuthHandler.Permissions.READ) StreamSegmentNotExistsException(io.pravega.segmentstore.contracts.StreamSegmentNotExistsException) SEGMENT_CREATE_LATENCY(io.pravega.shared.MetricsNames.SEGMENT_CREATE_LATENCY) AuthHandler(io.pravega.auth.AuthHandler) SegmentIsTruncated(io.pravega.shared.protocol.netty.WireCommands.SegmentIsTruncated) CREATION_TIME(io.pravega.segmentstore.contracts.Attributes.CREATION_TIME) MetricsNames.nameFromSegment(io.pravega.shared.MetricsNames.nameFromSegment) GetStreamSegmentInfo(io.pravega.shared.protocol.netty.WireCommands.GetStreamSegmentInfo) ReadResultEntryContents(io.pravega.segmentstore.contracts.ReadResultEntryContents) Duration(java.time.Duration) Map(java.util.Map) SegmentCreated(io.pravega.shared.protocol.netty.WireCommands.SegmentCreated) StreamSegmentStore(io.pravega.segmentstore.contracts.StreamSegmentStore) Attributes(io.pravega.segmentstore.contracts.Attributes) CancellationException(java.util.concurrent.CancellationException) ContainerNotFoundException(io.pravega.segmentstore.contracts.ContainerNotFoundException) Slf4j(lombok.extern.slf4j.Slf4j) CreateSegment(io.pravega.shared.protocol.netty.WireCommands.CreateSegment) SealSegment(io.pravega.shared.protocol.netty.WireCommands.SealSegment) SegmentSealed(io.pravega.shared.protocol.netty.WireCommands.SegmentSealed) EndOfStreamSegment(io.pravega.segmentstore.contracts.ReadResultEntryType.EndOfStreamSegment) SegmentAttribute(io.pravega.shared.protocol.netty.WireCommands.SegmentAttribute) SEGMENT_READ_LATENCY(io.pravega.shared.MetricsNames.SEGMENT_READ_LATENCY) Exceptions(io.pravega.common.Exceptions) BadAttributeUpdateException(io.pravega.segmentstore.contracts.BadAttributeUpdateException) GetSegmentAttribute(io.pravega.shared.protocol.netty.WireCommands.GetSegmentAttribute) ArrayList(java.util.ArrayList) READ_UPDATE(io.pravega.auth.AuthHandler.Permissions.READ_UPDATE) SegmentRead(io.pravega.shared.protocol.netty.WireCommands.SegmentRead) AccessLevel(lombok.AccessLevel) Future(io.pravega.segmentstore.contracts.ReadResultEntryType.Future) FailingRequestProcessor(io.pravega.shared.protocol.netty.FailingRequestProcessor) StreamHelpers(io.pravega.common.io.StreamHelpers) StreamSegmentTruncatedException(io.pravega.segmentstore.contracts.StreamSegmentTruncatedException) StatsLogger(io.pravega.shared.metrics.StatsLogger) OpStatsLogger(io.pravega.shared.metrics.OpStatsLogger) lombok.val(lombok.val) SEGMENT_WRITE_EVENTS(io.pravega.shared.MetricsNames.SEGMENT_WRITE_EVENTS) IOException(java.io.IOException) WireCommands(io.pravega.shared.protocol.netty.WireCommands) WrongHost(io.pravega.shared.protocol.netty.WireCommands.WrongHost) SegmentDeleted(io.pravega.shared.protocol.netty.WireCommands.SegmentDeleted) CreateTransaction(io.pravega.shared.protocol.netty.WireCommands.CreateTransaction) Truncated(io.pravega.segmentstore.contracts.ReadResultEntryType.Truncated) SegmentTruncated(io.pravega.shared.protocol.netty.WireCommands.SegmentTruncated) RequestProcessor(io.pravega.shared.protocol.netty.RequestProcessor) OperationUnsupported(io.pravega.shared.protocol.netty.WireCommands.OperationUnsupported) Preconditions(com.google.common.base.Preconditions) TransactionInfo(io.pravega.shared.protocol.netty.WireCommands.TransactionInfo) AbortTransaction(io.pravega.shared.protocol.netty.WireCommands.AbortTransaction) AuthenticationException(io.pravega.common.auth.AuthenticationException) Cache(io.pravega.segmentstore.contracts.ReadResultEntryType.Cache) SneakyThrows(lombok.SneakyThrows) ByteBuffer(java.nio.ByteBuffer) AttributeUpdate(io.pravega.segmentstore.contracts.AttributeUpdate) StreamSegmentSealedException(io.pravega.segmentstore.contracts.StreamSegmentSealedException) UpdateSegmentAttribute(io.pravega.shared.protocol.netty.WireCommands.UpdateSegmentAttribute) UpdateSegmentPolicy(io.pravega.shared.protocol.netty.WireCommands.UpdateSegmentPolicy) SegmentStatsRecorder(io.pravega.segmentstore.server.host.stat.SegmentStatsRecorder) CommitTransaction(io.pravega.shared.protocol.netty.WireCommands.CommitTransaction) Collection(java.util.Collection) UUID(java.util.UUID) Math.min(java.lang.Math.min) StreamSegmentNameUtils(io.pravega.shared.segment.StreamSegmentNameUtils) MetricsProvider(io.pravega.shared.metrics.MetricsProvider) List(java.util.List) StreamSegmentExistsException(io.pravega.segmentstore.contracts.StreamSegmentExistsException) PassingTokenVerifier(io.pravega.segmentstore.server.host.delegationtoken.PassingTokenVerifier) BadOffsetException(io.pravega.segmentstore.contracts.BadOffsetException) DelegationTokenVerifier(io.pravega.segmentstore.server.host.delegationtoken.DelegationTokenVerifier) Math.max(java.lang.Math.max) SegmentIsSealed(io.pravega.shared.protocol.netty.WireCommands.SegmentIsSealed) ReadResult(io.pravega.segmentstore.contracts.ReadResult) TransactionAborted(io.pravega.shared.protocol.netty.WireCommands.TransactionAborted) DeleteSegment(io.pravega.shared.protocol.netty.WireCommands.DeleteSegment) SegmentPolicyUpdated(io.pravega.shared.protocol.netty.WireCommands.SegmentPolicyUpdated) Getter(lombok.Getter) NoSuchSegment(io.pravega.shared.protocol.netty.WireCommands.NoSuchSegment) CompletableFuture(java.util.concurrent.CompletableFuture) GetTransactionInfo(io.pravega.shared.protocol.netty.WireCommands.GetTransactionInfo) DynamicLogger(io.pravega.shared.metrics.DynamicLogger) SEGMENT_WRITE_BYTES(io.pravega.shared.MetricsNames.SEGMENT_WRITE_BYTES) ReadResultEntry(io.pravega.segmentstore.contracts.ReadResultEntry) SEGMENT_READ_BYTES(io.pravega.shared.MetricsNames.SEGMENT_READ_BYTES) SCALE_POLICY_TYPE(io.pravega.segmentstore.contracts.Attributes.SCALE_POLICY_TYPE) TransactionCommitted(io.pravega.shared.protocol.netty.WireCommands.TransactionCommitted) TYPE_PLUS_LENGTH_SIZE(io.pravega.shared.protocol.netty.WireCommands.TYPE_PLUS_LENGTH_SIZE) StreamSegmentInfo(io.pravega.shared.protocol.netty.WireCommands.StreamSegmentInfo) TransactionCreated(io.pravega.shared.protocol.netty.WireCommands.TransactionCreated) TruncateSegment(io.pravega.shared.protocol.netty.WireCommands.TruncateSegment) ReadSegment(io.pravega.shared.protocol.netty.WireCommands.ReadSegment) SegmentAlreadyExists(io.pravega.shared.protocol.netty.WireCommands.SegmentAlreadyExists) LoggerHelpers(io.pravega.common.LoggerHelpers) StreamSegmentMergedException(io.pravega.segmentstore.contracts.StreamSegmentMergedException) Timer(io.pravega.common.Timer) SegmentAttributeUpdated(io.pravega.shared.protocol.netty.WireCommands.SegmentAttributeUpdated) VisibleForTesting(com.google.common.annotations.VisibleForTesting) AttributeUpdateType(io.pravega.segmentstore.contracts.AttributeUpdateType) Collections(java.util.Collections) Timer(io.pravega.common.Timer)

Aggregations

Timer (io.pravega.common.Timer)18 BadOffsetException (io.pravega.segmentstore.contracts.BadOffsetException)5 CompletableFuture (java.util.concurrent.CompletableFuture)5 VisibleForTesting (com.google.common.annotations.VisibleForTesting)4 Preconditions (com.google.common.base.Preconditions)4 Exceptions (io.pravega.common.Exceptions)4 LoggerHelpers (io.pravega.common.LoggerHelpers)4 Duration (java.time.Duration)4 List (java.util.List)4 AuthHandler (io.pravega.auth.AuthHandler)3 AuthenticationException (io.pravega.common.auth.AuthenticationException)3 AttributeUpdate (io.pravega.segmentstore.contracts.AttributeUpdate)3 AttributeUpdateType (io.pravega.segmentstore.contracts.AttributeUpdateType)3 BadAttributeUpdateException (io.pravega.segmentstore.contracts.BadAttributeUpdateException)3 ContainerNotFoundException (io.pravega.segmentstore.contracts.ContainerNotFoundException)3 StreamSegmentSealedException (io.pravega.segmentstore.contracts.StreamSegmentSealedException)3 ByteBuffer (java.nio.ByteBuffer)3 StreamSegmentExistsException (io.pravega.segmentstore.contracts.StreamSegmentExistsException)2 StreamSegmentNotExistsException (io.pravega.segmentstore.contracts.StreamSegmentNotExistsException)2 StreamSegmentStore (io.pravega.segmentstore.contracts.StreamSegmentStore)2