From 5a9b5e04b7ee9fcd874c73713bc0c3a671d729bb Mon Sep 17 00:00:00 2001 From: Mike McMahon Date: Thu, 11 Apr 2024 10:41:44 -0700 Subject: [PATCH] Use that for indexing by record instead of trying to recover TupleRange's from unbuilt Range's. --- .../IndexingMultiTargetByRecords.java | 26 +++++++------------ 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/fdb-record-layer-core/src/main/java/com/apple/foundationdb/record/provider/foundationdb/IndexingMultiTargetByRecords.java b/fdb-record-layer-core/src/main/java/com/apple/foundationdb/record/provider/foundationdb/IndexingMultiTargetByRecords.java index 53de3fdb66..57f89235b7 100644 --- a/fdb-record-layer-core/src/main/java/com/apple/foundationdb/record/provider/foundationdb/IndexingMultiTargetByRecords.java +++ b/fdb-record-layer-core/src/main/java/com/apple/foundationdb/record/provider/foundationdb/IndexingMultiTargetByRecords.java @@ -23,10 +23,10 @@ import com.apple.foundationdb.Range; import com.apple.foundationdb.annotation.API; import com.apple.foundationdb.async.AsyncUtil; -import com.apple.foundationdb.async.RangeSet; import com.apple.foundationdb.record.ExecuteProperties; import com.apple.foundationdb.record.IndexBuildProto; import com.apple.foundationdb.record.IsolationLevel; +import com.apple.foundationdb.record.KeyRange; import com.apple.foundationdb.record.RecordCursor; import com.apple.foundationdb.record.RecordCursorResult; import com.apple.foundationdb.record.ScanProperties; @@ -35,7 +35,6 @@ import com.apple.foundationdb.record.metadata.Index; import com.apple.foundationdb.record.provider.foundationdb.indexing.IndexingRangeSet; import com.apple.foundationdb.subspace.Subspace; -import com.apple.foundationdb.tuple.ByteArrayUtil; import com.apple.foundationdb.tuple.Tuple; import com.google.protobuf.Message; @@ -125,9 +124,7 @@ private CompletableFuture buildMultiTargetIndex(@Nonnull SubspaceProvider } else { final Range range = tupleRange.toRange(); rangeStart = range.begin; - // tupleRange has an inclusive high endpoint, so end isn't a valid tuple. - // But buildRangeOnly needs to convert missing Ranges back to TupleRanges, so round up. - rangeEnd = ByteArrayUtil.strinc(range.end); + rangeEnd = range.end; } final CompletableFuture maybePresetRangeFuture = @@ -172,12 +169,9 @@ private CompletableFuture buildRangeOnly(@Nonnull FDBRecordStore store, if (range == null) { return AsyncUtil.READY_FALSE; // no more missing ranges - all done } - final Tuple rangeStart = RangeSet.isFirstKey(range.begin) ? null : Tuple.fromBytes(range.begin); - final Tuple rangeEnd = RangeSet.isFinalKey(range.end) ? null : Tuple.fromBytes(range.end); - final TupleRange tupleRange = TupleRange.between(rangeStart, rangeEnd); - + final KeyRange keyRange = new KeyRange(range); RecordCursor> cursor = - store.scanRecords(tupleRange, null, scanProperties); + store.scanRecordsKeyRange(keyRange, null, scanProperties); final AtomicReference>> lastResult = new AtomicReference<>(RecordCursorResult.exhausted()); final AtomicBoolean hasMore = new AtomicBoolean(true); @@ -189,20 +183,20 @@ private CompletableFuture buildRangeOnly(@Nonnull FDBRecordStore store, this::getRecordIfTypeMatch, lastResult, hasMore, recordsScanned, isIdempotent) .thenCompose(ignore -> postIterateRangeOnly(targetRangeSets, hasMore.get(), lastResult, - rangeStart, rangeEnd, scanProperties.isReverse())); + range.begin, range.end, scanProperties.isReverse())); }); } private CompletableFuture postIterateRangeOnly(List targetRangeSets, boolean hasMore, AtomicReference>> lastResult, - Tuple rangeStart, Tuple rangeEnd, boolean isReverse) { + byte[] rangeStart, byte[] rangeEnd, boolean isReverse) { if (isReverse) { - Tuple continuation = hasMore ? lastResult.get().get().getPrimaryKey() : rangeStart; - return insertRanges(targetRangeSets, packOrNull(continuation), packOrNull(rangeEnd)) + byte[] continuation = hasMore ? packOrNull(lastResult.get().get().getPrimaryKey()) : rangeStart; + return insertRanges(targetRangeSets, continuation, rangeEnd) .thenApply(ignore -> hasMore || rangeStart != null); } else { - Tuple continuation = hasMore ? lastResult.get().get().getPrimaryKey() : rangeEnd; - return insertRanges(targetRangeSets, packOrNull(rangeStart), packOrNull(continuation)) + byte[] continuation = hasMore ? packOrNull(lastResult.get().get().getPrimaryKey()) : rangeEnd; + return insertRanges(targetRangeSets, rangeStart, continuation) .thenApply(ignore -> hasMore || rangeEnd != null); } }