Search in sources :

Example 1 with AsyncMap

use of io.pravega.common.util.AsyncMap in project pravega by pravega.

the class SegmentStateStore method get.

// endregion
// region AsyncMap implementation
@Override
public CompletableFuture<SegmentState> get(String segmentName, Duration timeout) {
    String stateSegment = StreamSegmentNameUtils.getStateSegmentName(segmentName);
    TimeoutTimer timer = new TimeoutTimer(timeout);
    return this.storage.getStreamSegmentInfo(stateSegment, timer.getRemaining()).thenComposeAsync(sp -> {
        if (sp.getLength() == 0) {
            // Empty state files are treated the same as if they didn't exist.
            return CompletableFuture.completedFuture(null);
        } else {
            return readSegmentState(sp, timer.getRemaining());
        }
    }, this.executor).exceptionally(this::handleSegmentNotExistsException);
}
Also used : Storage(io.pravega.segmentstore.storage.Storage) TimeoutTimer(io.pravega.common.TimeoutTimer) StreamSegmentNotExistsException(io.pravega.segmentstore.contracts.StreamSegmentNotExistsException) Executor(java.util.concurrent.Executor) SneakyThrows(lombok.SneakyThrows) SegmentRollingPolicy(io.pravega.segmentstore.storage.SegmentRollingPolicy) Exceptions(io.pravega.common.Exceptions) IOException(java.io.IOException) CompletableFuture(java.util.concurrent.CompletableFuture) CompletionException(java.util.concurrent.CompletionException) EOFException(java.io.EOFException) StreamSegmentNameUtils(io.pravega.shared.segment.StreamSegmentNameUtils) SegmentProperties(io.pravega.segmentstore.contracts.SegmentProperties) ArrayView(io.pravega.common.util.ArrayView) AsyncMap(io.pravega.common.util.AsyncMap) Duration(java.time.Duration) SerializationException(io.pravega.common.io.SerializationException) Preconditions(com.google.common.base.Preconditions) DataCorruptionException(io.pravega.segmentstore.server.DataCorruptionException) TimeoutTimer(io.pravega.common.TimeoutTimer)

Aggregations

Preconditions (com.google.common.base.Preconditions)1 Exceptions (io.pravega.common.Exceptions)1 TimeoutTimer (io.pravega.common.TimeoutTimer)1 SerializationException (io.pravega.common.io.SerializationException)1 ArrayView (io.pravega.common.util.ArrayView)1 AsyncMap (io.pravega.common.util.AsyncMap)1 SegmentProperties (io.pravega.segmentstore.contracts.SegmentProperties)1 StreamSegmentNotExistsException (io.pravega.segmentstore.contracts.StreamSegmentNotExistsException)1 DataCorruptionException (io.pravega.segmentstore.server.DataCorruptionException)1 SegmentRollingPolicy (io.pravega.segmentstore.storage.SegmentRollingPolicy)1 Storage (io.pravega.segmentstore.storage.Storage)1 StreamSegmentNameUtils (io.pravega.shared.segment.StreamSegmentNameUtils)1 EOFException (java.io.EOFException)1 IOException (java.io.IOException)1 Duration (java.time.Duration)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 CompletionException (java.util.concurrent.CompletionException)1 Executor (java.util.concurrent.Executor)1 SneakyThrows (lombok.SneakyThrows)1