Search in sources :

Example 1 with BTreeIndex

use of io.pravega.common.util.btree.BTreeIndex in project pravega by pravega.

the class SegmentAttributeBTreeIndex method get.

@Override
public CompletableFuture<Map<AttributeId, Long>> get(@NonNull Collection<AttributeId> keys, @NonNull Duration timeout) {
    ensureInitialized();
    if (keys.isEmpty()) {
        // Nothing to do.
        return CompletableFuture.completedFuture(Collections.emptyMap());
    }
    // Keep two lists, one of keys (in some order) and one of serialized keys (in the same order).
    val keyList = new ArrayList<AttributeId>(keys.size());
    val serializedKeys = new ArrayList<ByteArraySegment>(keys.size());
    for (AttributeId key : keys) {
        keyList.add(key);
        serializedKeys.add(this.keySerializer.serialize(key));
    }
    // segment file (see READ_RETRY Javadoc).
    return READ_RETRY.runAsync(() -> this.index.get(serializedKeys, timeout), this.executor).thenApply(entries -> {
        assert entries.size() == keys.size() : "Unexpected number of entries returned by the index search.";
        // The index search result is a list of values in the same order as the keys we passed in, so we need
        // to use the list index to match them.
        Map<AttributeId, Long> result = new HashMap<>();
        for (int i = 0; i < keyList.size(); i++) {
            ByteArraySegment v = entries.get(i);
            if (v != null) {
                // BTreeIndex will return null if a key is not present; however we exclude that from our result.
                result.put(keyList.get(i), deserializeValue(v));
            }
        }
        return result;
    }).exceptionally(this::handleIndexOperationException);
}
Also used : lombok.val(lombok.val) Storage(io.pravega.segmentstore.storage.Storage) StreamSegmentNotExistsException(io.pravega.segmentstore.contracts.StreamSegmentNotExistsException) SneakyThrows(lombok.SneakyThrows) Retry(io.pravega.common.util.Retry) RequiredArgsConstructor(lombok.RequiredArgsConstructor) SegmentProperties(io.pravega.segmentstore.contracts.SegmentProperties) StreamSegmentSealedException(io.pravega.segmentstore.contracts.StreamSegmentSealedException) SegmentHandle(io.pravega.segmentstore.storage.SegmentHandle) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) BufferView(io.pravega.common.util.BufferView) Duration(java.time.Duration) Map(java.util.Map) Attributes(io.pravega.segmentstore.contracts.Attributes) NonNull(lombok.NonNull) Collection(java.util.Collection) CompletionException(java.util.concurrent.CompletionException) GuardedBy(javax.annotation.concurrent.GuardedBy) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) List(java.util.List) Slf4j(lombok.extern.slf4j.Slf4j) ByteArraySegment(io.pravega.common.util.ByteArraySegment) PageEntry(io.pravega.common.util.btree.PageEntry) StreamSegmentExistsException(io.pravega.segmentstore.contracts.StreamSegmentExistsException) BadOffsetException(io.pravega.segmentstore.contracts.BadOffsetException) Futures(io.pravega.common.concurrent.Futures) CacheManager(io.pravega.segmentstore.server.CacheManager) Getter(lombok.Getter) Exceptions(io.pravega.common.Exceptions) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) AtomicReference(java.util.concurrent.atomic.AtomicReference) Function(java.util.function.Function) Supplier(java.util.function.Supplier) CacheStorage(io.pravega.segmentstore.storage.cache.CacheStorage) ArrayList(java.util.ArrayList) SegmentMetadata(io.pravega.segmentstore.server.SegmentMetadata) BTreeIndex(io.pravega.common.util.btree.BTreeIndex) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) CacheFullException(io.pravega.segmentstore.storage.cache.CacheFullException) AttributeIterator(io.pravega.segmentstore.server.AttributeIterator) StreamSegmentTruncatedException(io.pravega.segmentstore.contracts.StreamSegmentTruncatedException) NameUtils(io.pravega.shared.NameUtils) AttributeIndex(io.pravega.segmentstore.server.AttributeIndex) TimeoutTimer(io.pravega.common.TimeoutTimer) SequenceInputStream(java.io.SequenceInputStream) AttributeId(io.pravega.segmentstore.contracts.AttributeId) lombok.val(lombok.val) AsyncIterator(io.pravega.common.util.AsyncIterator) Maps(com.google.common.collect.Maps) Preconditions(com.google.common.base.Preconditions) VisibleForTesting(com.google.common.annotations.VisibleForTesting) IllegalDataFormatException(io.pravega.common.util.IllegalDataFormatException) DataCorruptionException(io.pravega.segmentstore.server.DataCorruptionException) AllArgsConstructor(lombok.AllArgsConstructor) Collections(java.util.Collections) InputStream(java.io.InputStream) ByteArraySegment(io.pravega.common.util.ByteArraySegment) AttributeId(io.pravega.segmentstore.contracts.AttributeId) ArrayList(java.util.ArrayList) Map(java.util.Map) HashMap(java.util.HashMap)

Aggregations

VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 Preconditions (com.google.common.base.Preconditions)1 Maps (com.google.common.collect.Maps)1 Exceptions (io.pravega.common.Exceptions)1 TimeoutTimer (io.pravega.common.TimeoutTimer)1 Futures (io.pravega.common.concurrent.Futures)1 AsyncIterator (io.pravega.common.util.AsyncIterator)1 BufferView (io.pravega.common.util.BufferView)1 ByteArraySegment (io.pravega.common.util.ByteArraySegment)1 IllegalDataFormatException (io.pravega.common.util.IllegalDataFormatException)1 Retry (io.pravega.common.util.Retry)1 BTreeIndex (io.pravega.common.util.btree.BTreeIndex)1 PageEntry (io.pravega.common.util.btree.PageEntry)1 AttributeId (io.pravega.segmentstore.contracts.AttributeId)1 Attributes (io.pravega.segmentstore.contracts.Attributes)1 BadOffsetException (io.pravega.segmentstore.contracts.BadOffsetException)1 SegmentProperties (io.pravega.segmentstore.contracts.SegmentProperties)1 StreamSegmentExistsException (io.pravega.segmentstore.contracts.StreamSegmentExistsException)1 StreamSegmentNotExistsException (io.pravega.segmentstore.contracts.StreamSegmentNotExistsException)1 StreamSegmentSealedException (io.pravega.segmentstore.contracts.StreamSegmentSealedException)1