Search in sources :

Example 11 with MetadataTransaction

use of io.pravega.segmentstore.storage.metadata.MetadataTransaction in project pravega by pravega.

the class SystemJournal method validateSegment.

/**
 * Validate that all information for given segment in given snapshot exists in transaction.
 */
private CompletableFuture<Void> validateSegment(MetadataTransaction txn, String segmentName) {
    return txn.get(segmentName).thenComposeAsync(m -> {
        val segmentMetadata = (SegmentMetadata) m;
        Preconditions.checkState(null != segmentMetadata, "Segment metadata must not be null.");
        val chunkName = new AtomicReference<>(segmentMetadata.getFirstChunk());
        return Futures.loop(() -> chunkName.get() != null, () -> txn.get(chunkName.get()).thenAcceptAsync(mm -> {
            Preconditions.checkState(null != mm, "Chunk metadata must not be null.");
            val chunkMetadata = (ChunkMetadata) mm;
            chunkName.set(chunkMetadata.getNextChunk());
        }, executor), executor);
    }, executor);
}
Also used : lombok.val(lombok.val) SegmentMetadata(io.pravega.segmentstore.storage.metadata.SegmentMetadata) Getter(lombok.Getter) Strings.nullToEmpty(com.google.common.base.Strings.nullToEmpty) Exceptions(io.pravega.common.Exceptions) RequiredArgsConstructor(lombok.RequiredArgsConstructor) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) HashMap(java.util.HashMap) Callable(java.util.concurrent.Callable) CompletableFuture(java.util.concurrent.CompletableFuture) RevisionDataInput(io.pravega.common.io.serialization.RevisionDataInput) AtomicReference(java.util.concurrent.atomic.AtomicReference) Supplier(java.util.function.Supplier) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) SegmentMetadata(io.pravega.segmentstore.storage.metadata.SegmentMetadata) MultiKeySequentialProcessor(io.pravega.common.concurrent.MultiKeySequentialProcessor) ByteArrayInputStream(java.io.ByteArrayInputStream) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Map(java.util.Map) MetadataTransaction(io.pravega.segmentstore.storage.metadata.MetadataTransaction) RevisionDataOutput(io.pravega.common.io.serialization.RevisionDataOutput) VersionedSerializer(io.pravega.common.io.serialization.VersionedSerializer) ChunkMetadata(io.pravega.segmentstore.storage.metadata.ChunkMetadata) NameUtils(io.pravega.shared.NameUtils) Executor(java.util.concurrent.Executor) NonNull(lombok.NonNull) Collection(java.util.Collection) lombok.val(lombok.val) Set(java.util.Set) IOException(java.io.IOException) CompletionException(java.util.concurrent.CompletionException) EqualsAndHashCode(lombok.EqualsAndHashCode) Timer(io.pravega.common.Timer) EOFException(java.io.EOFException) ObjectBuilder(io.pravega.common.ObjectBuilder) AtomicLong(java.util.concurrent.atomic.AtomicLong) List(java.util.List) Slf4j(lombok.extern.slf4j.Slf4j) Strings.emptyToNull(com.google.common.base.Strings.emptyToNull) ByteArraySegment(io.pravega.common.util.ByteArraySegment) ChunkMetadataStore(io.pravega.segmentstore.storage.metadata.ChunkMetadataStore) Builder(lombok.Builder) Data(lombok.Data) Preconditions(com.google.common.base.Preconditions) Collections(java.util.Collections) Futures(io.pravega.common.concurrent.Futures) AtomicReference(java.util.concurrent.atomic.AtomicReference)

Aggregations

Preconditions (com.google.common.base.Preconditions)11 Exceptions (io.pravega.common.Exceptions)11 Timer (io.pravega.common.Timer)11 Futures (io.pravega.common.concurrent.Futures)11 ChunkMetadata (io.pravega.segmentstore.storage.metadata.ChunkMetadata)11 MetadataTransaction (io.pravega.segmentstore.storage.metadata.MetadataTransaction)11 SegmentMetadata (io.pravega.segmentstore.storage.metadata.SegmentMetadata)11 Callable (java.util.concurrent.Callable)11 CompletableFuture (java.util.concurrent.CompletableFuture)11 CompletionException (java.util.concurrent.CompletionException)11 AtomicLong (java.util.concurrent.atomic.AtomicLong)11 Slf4j (lombok.extern.slf4j.Slf4j)11 lombok.val (lombok.val)11 ArrayList (java.util.ArrayList)10 Collections (java.util.Collections)10 List (java.util.List)10 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)9 NameUtils (io.pravega.shared.NameUtils)8 AtomicReference (java.util.concurrent.atomic.AtomicReference)8 MultiKeySequentialProcessor (io.pravega.common.concurrent.MultiKeySequentialProcessor)7