use of com.apple.foundationdb.record.ScanProperties in project fdb-record-layer by FoundationDB.
the class UnionIntersectionTest method unevenInterleavedIndexScan.
@ValueSource(ints = { 1, 2, 3, 4, 5 })
@ParameterizedTest(name = "unevenInterleavedIndexScan() [{0}]")
public void unevenInterleavedIndexScan(int innerLimit) throws Exception {
final ScanProperties scanProperties = new ScanProperties(ExecuteProperties.newBuilder().setReturnedRowLimit(innerLimit).build());
final ScanComparisons zeros = new ScanComparisons(Collections.singletonList(new Comparisons.SimpleComparison(Comparisons.Type.EQUALS, 0)), Collections.emptySet());
final ScanComparisons others = new ScanComparisons(Collections.singletonList(new Comparisons.SimpleComparison(Comparisons.Type.EQUALS, 1)), Collections.emptySet());
verifyUnionWithInnerLimits(cont -> recordStore.scanIndexRecords("MySimpleRecord$num_value_3_indexed", IndexScanType.BY_VALUE, zeros.toTupleRange(), cont, scanProperties).map(rec -> (FDBRecord<Message>) rec), cont -> recordStore.scanIndexRecords("MySimpleRecord$num_value_3_indexed", IndexScanType.BY_VALUE, others.toTupleRange(), cont, scanProperties).map(rec -> (FDBRecord<Message>) rec), LongStream.range(0L, 100L).iterator());
}
use of com.apple.foundationdb.record.ScanProperties in project fdb-record-layer by FoundationDB.
the class UnionIntersectionTest method interleavedIndexScan.
@ValueSource(ints = { 1, 2, 3, 4, 5 })
@ParameterizedTest(name = "interleavedIndexScan() [{0}]")
public void interleavedIndexScan(int innerLimit) throws Exception {
final ScanProperties scanProperties = new ScanProperties(ExecuteProperties.newBuilder().setReturnedRowLimit(innerLimit).build());
final ScanComparisons evenComparisons = new ScanComparisons(Collections.singletonList(new Comparisons.SimpleComparison(Comparisons.Type.EQUALS, "even")), Collections.emptySet());
final ScanComparisons oddComparisons = new ScanComparisons(Collections.singletonList(new Comparisons.SimpleComparison(Comparisons.Type.EQUALS, "odd")), Collections.emptySet());
verifyUnionWithInnerLimits(cont -> recordStore.scanIndexRecords("MySimpleRecord$str_value_indexed", IndexScanType.BY_VALUE, evenComparisons.toTupleRange(), cont, scanProperties).map(rec -> (FDBRecord<Message>) rec), cont -> recordStore.scanIndexRecords("MySimpleRecord$str_value_indexed", IndexScanType.BY_VALUE, oddComparisons.toTupleRange(), cont, scanProperties).map(rec -> (FDBRecord<Message>) rec), LongStream.range(0L, 100L).iterator());
}
use of com.apple.foundationdb.record.ScanProperties in project fdb-record-layer by FoundationDB.
the class SplitHelperTest method scanContinuations.
@MethodSource("limitsAndReverseArgs")
@ParameterizedTest(name = "scanContinuations [returnLimit = {0}, readLimit = {1}, reverse = {2}]")
public void scanContinuations(final int returnLimit, final int readLimit, final boolean reverse) throws Exception {
List<FDBRawRecord> rawRecords = writeDummyRecords();
if (reverse) {
rawRecords = Lists.reverse(rawRecords);
}
final Iterator<FDBRawRecord> expectedRecordIterator = rawRecords.iterator();
try (FDBRecordContext context = openContext()) {
byte[] continuation = null;
do {
final ExecuteProperties executeProperties = ExecuteProperties.newBuilder().setReturnedRowLimit(returnLimit).setScannedRecordsLimit(readLimit).build();
ScanProperties scanProperties = new ScanProperties(executeProperties, reverse);
RecordCursor<KeyValue> kvCursor = KeyValueCursor.Builder.withSubspace(subspace).setContext(context).setRange(TupleRange.ALL).setScanProperties(scanProperties.with(ExecuteProperties::clearRowAndTimeLimits).with(ExecuteProperties::clearState)).setContinuation(continuation).build();
RecordCursorIterator<FDBRawRecord> recordCursor = new SplitHelper.KeyValueUnsplitter(context, subspace, kvCursor, false, null, scanProperties.with(ExecuteProperties::clearReturnedRowLimit)).limitRowsTo(returnLimit).asIterator();
int retrieved = 0;
int rowsScanned = 0;
while (recordCursor.hasNext()) {
assertThat(retrieved, lessThan(returnLimit));
assertThat(rowsScanned, lessThanOrEqualTo(readLimit));
FDBRawRecord nextRecord = recordCursor.next();
assertNotNull(nextRecord);
assertThat(expectedRecordIterator.hasNext(), is(true));
FDBRawRecord expectedRecord = expectedRecordIterator.next();
assertEquals(expectedRecord, nextRecord);
rowsScanned += nextRecord.getKeyCount();
retrieved += 1;
}
if (retrieved > 0) {
continuation = recordCursor.getContinuation();
if (retrieved >= returnLimit) {
assertEquals(RecordCursor.NoNextReason.RETURN_LIMIT_REACHED, recordCursor.getNoNextReason());
assertNotNull(continuation);
} else if (rowsScanned > readLimit) {
assertEquals(RecordCursor.NoNextReason.SCAN_LIMIT_REACHED, recordCursor.getNoNextReason());
assertNotNull(continuation);
} else if (rowsScanned < readLimit) {
assertEquals(RecordCursor.NoNextReason.SOURCE_EXHAUSTED, recordCursor.getNoNextReason());
} else {
// If we read exactly as many records as is allowed by the read record limit, then
// this probably means that we hit SCAN_LIMIT_REACHED, but it's also possible to
// hit SOURCE_EXHAUSTED if we hit the record read limit at exactly the same time
// as we needed to do another speculative read to determine if a split record
// continues or not.
assertEquals(readLimit, rowsScanned);
assertThat(recordCursor.getNoNextReason(), is(oneOf(RecordCursor.NoNextReason.SCAN_LIMIT_REACHED, RecordCursor.NoNextReason.SOURCE_EXHAUSTED)));
if (!recordCursor.getNoNextReason().isSourceExhausted()) {
assertNotNull(recordCursor.getContinuation());
}
}
} else {
assertNull(recordCursor.getContinuation());
continuation = null;
}
} while (continuation != null);
commit(context);
}
}
use of com.apple.foundationdb.record.ScanProperties in project fdb-record-layer by FoundationDB.
the class SplitHelperTest method scanMultipleRecords.
@ParameterizedTest(name = "scanMultipleRecords [reverse = {0}]")
@BooleanSource
public void scanMultipleRecords(boolean reverse) throws Exception {
final ScanProperties scanProperties = reverse ? ScanProperties.REVERSE_SCAN : ScanProperties.FORWARD_SCAN;
List<FDBRawRecord> rawRecords = writeDummyRecords();
try (FDBRecordContext context = openContext()) {
KeyValueCursor kvCursor = KeyValueCursor.Builder.withSubspace(subspace).setContext(context).setRange(TupleRange.ALL).setScanProperties(scanProperties).build();
List<FDBRawRecord> readRecords = new SplitHelper.KeyValueUnsplitter(context, subspace, kvCursor, false, null, scanProperties).asList().get();
if (reverse) {
readRecords = Lists.reverse(readRecords);
}
assertEquals(rawRecords.size(), readRecords.size());
for (int i = 0; i < rawRecords.size(); i++) {
assertEquals(rawRecords.get(i), readRecords.get(i));
}
assertEquals(rawRecords, readRecords);
commit(context);
}
}
use of com.apple.foundationdb.record.ScanProperties in project fdb-record-layer by FoundationDB.
the class SortCursorTests method memorySortContinuations.
@Test
public void memorySortContinuations() throws Exception {
final Function<byte[], RecordCursor<FDBQueriedRecord<Message>>> scanRecords = continuation -> {
final ExecuteProperties executeProperties = ExecuteProperties.newBuilder().setScannedRecordsLimit(20).build();
return recordStore.scanRecords(null, null, EndpointType.TREE_START, EndpointType.TREE_END, continuation, new ScanProperties(executeProperties)).map(FDBQueriedRecord::stored);
};
final MemoryAdapterBase adapter = new MemoryAdapterBase() {
@Override
public int getMaxRecordCountInMemory() {
return 10;
}
};
List<Integer> resultNums = new ArrayList<>();
byte[] continuation = null;
int transactionCount = 0;
do {
try (FDBRecordContext context = openContext()) {
openSimpleRecordStore(context);
try (RecordCursor<FDBQueriedRecord<Message>> cursor = MemorySortCursor.create(adapter, scanRecords, timer, continuation)) {
while (true) {
RecordCursorResult<FDBQueriedRecord<Message>> result = cursor.getNext();
if (result.hasNext()) {
int num2 = TestRecords1Proto.MySimpleRecord.newBuilder().mergeFrom(result.get().getRecord()).getNumValue2();
resultNums.add(num2);
} else {
continuation = result.getContinuation().toBytes();
break;
}
}
}
transactionCount++;
}
} while (continuation != null);
assertEquals(110, transactionCount);
assertEquals(sortedNums, resultNums);
}
Aggregations