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);
}
Aggregations