Skip to content

Commit

Permalink
Use that for indexing by record instead of trying to recover TupleRan…
Browse files Browse the repository at this point in the history
…ge's from unbuilt Range's.
  • Loading branch information
MMcM committed Apr 11, 2024
1 parent 6c59ebc commit 5a9b5e0
Showing 1 changed file with 10 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -125,9 +124,7 @@ private CompletableFuture<Void> 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<FDBRecordStore> maybePresetRangeFuture =
Expand Down Expand Up @@ -172,12 +169,9 @@ private CompletableFuture<Boolean> 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<FDBStoredRecord<Message>> cursor =
store.scanRecords(tupleRange, null, scanProperties);
store.scanRecordsKeyRange(keyRange, null, scanProperties);

final AtomicReference<RecordCursorResult<FDBStoredRecord<Message>>> lastResult = new AtomicReference<>(RecordCursorResult.exhausted());
final AtomicBoolean hasMore = new AtomicBoolean(true);
Expand All @@ -189,20 +183,20 @@ private CompletableFuture<Boolean> 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<Boolean> postIterateRangeOnly(List<IndexingRangeSet> targetRangeSets, boolean hasMore,
AtomicReference<RecordCursorResult<FDBStoredRecord<Message>>> 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);
}
}
Expand Down

0 comments on commit 5a9b5e0

Please sign in to comment.