use of com.apple.foundationdb.KeyValue in project fdb-record-layer by FoundationDB.
the class RangeSetTest method checkIncreasing.
private void checkIncreasing() {
List<KeyValue> kvs = db.readAsync(tr -> tr.getRange(rsSubspace.range()).asList()).join();
byte[] last = null;
for (KeyValue kv : kvs) {
byte[] key = rsSubspace.unpack(kv.getKey()).getBytes(0);
assertTrue(compareUnsigned(key, kv.getValue()) < 0, "Key " + printable(key) + " is not less than value " + printable(kv.getValue()));
if (last != null) {
assertTrue(compareUnsigned(last, key) <= 0, "Last value " + printable(last) + " is after key " + printable(key));
}
last = kv.getValue();
}
}
use of com.apple.foundationdb.KeyValue 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.KeyValue in project fdb-record-layer by FoundationDB.
the class KeyValueCursorTest method simpleScanLimit.
@Test
public void simpleScanLimit() {
fdb.run(context -> {
RecordScanLimiter limiter = RecordScanLimiterFactory.enforce(2);
KeyValueCursor cursor = KeyValueCursor.Builder.withSubspace(subspace).setContext(context).setRange(TupleRange.ALL).setScanProperties(forwardScanWithLimiter(limiter)).build();
assertEquals(2, (int) cursor.getCount().join());
RecordCursorResult<KeyValue> result = cursor.getNext();
assertThat("no next reason should be SCAN_LIMIT_REACHED", result.getNoNextReason(), equalTo(RecordCursor.NoNextReason.SCAN_LIMIT_REACHED));
return null;
});
}
use of com.apple.foundationdb.KeyValue in project fdb-record-layer by FoundationDB.
the class KeyValueCursorTest method inclusiveRange.
@Test
public void inclusiveRange() {
fdb.run(context -> {
KeyValueCursor cursor = KeyValueCursor.Builder.withSubspace(subspace).setContext(context).setLow(Tuple.from(3, 3), EndpointType.RANGE_INCLUSIVE).setHigh(Tuple.from(4, 2), EndpointType.RANGE_INCLUSIVE).setContinuation(null).setScanProperties(ScanProperties.FORWARD_SCAN).build();
assertEquals(Arrays.asList(Tuple.from(3L, 3L), Tuple.from(3L, 4L), Tuple.from(4L, 0L), Tuple.from(4L, 1L), Tuple.from(4L, 2L)), cursor.map(KeyValue::getValue).map(Tuple::fromBytes).asList().join());
cursor = KeyValueCursor.Builder.withSubspace(subspace).setContext(context).setLow(Tuple.from(3, 3), EndpointType.RANGE_INCLUSIVE).setHigh(Tuple.from(4, 2), EndpointType.RANGE_INCLUSIVE).setContinuation(null).setScanProperties(new ScanProperties(ExecuteProperties.newBuilder().setReturnedRowLimit(2).build())).build();
assertEquals(Arrays.asList(Tuple.from(3L, 3L), Tuple.from(3L, 4L)), cursor.map(KeyValue::getValue).map(Tuple::fromBytes).asList().join());
cursor = KeyValueCursor.Builder.withSubspace(subspace).setContext(context).setLow(Tuple.from(3, 3), EndpointType.RANGE_INCLUSIVE).setHigh(Tuple.from(4, 2), EndpointType.RANGE_INCLUSIVE).setContinuation(cursor.getNext().getContinuation().toBytes()).setScanProperties(ScanProperties.FORWARD_SCAN).build();
assertEquals(Arrays.asList(Tuple.from(4L, 0L), Tuple.from(4L, 1L), Tuple.from(4L, 2L)), cursor.map(KeyValue::getValue).map(Tuple::fromBytes).asList().join());
return null;
});
}
use of com.apple.foundationdb.KeyValue in project fdb-record-layer by FoundationDB.
the class KeyValueCursorTest method exclusiveRange.
@Test
public void exclusiveRange() {
fdb.run(context -> {
KeyValueCursor cursor = KeyValueCursor.Builder.withSubspace(subspace).setContext(context).setLow(Tuple.from(3, 3), EndpointType.RANGE_EXCLUSIVE).setHigh(Tuple.from(4, 2), EndpointType.RANGE_EXCLUSIVE).setContinuation(null).setScanProperties(ScanProperties.FORWARD_SCAN).build();
assertEquals(Arrays.asList(Tuple.from(3L, 4L), Tuple.from(4L, 0L), Tuple.from(4L, 1L)), cursor.map(KeyValue::getValue).map(Tuple::fromBytes).asList().join());
cursor = KeyValueCursor.Builder.withSubspace(subspace).setContext(context).setLow(Tuple.from(3, 3), EndpointType.RANGE_EXCLUSIVE).setHigh(Tuple.from(4, 2), EndpointType.RANGE_EXCLUSIVE).setContinuation(null).setScanProperties(new ScanProperties(ExecuteProperties.newBuilder().setReturnedRowLimit(2).build())).build();
assertEquals(Arrays.asList(Tuple.from(3L, 4L), Tuple.from(4L, 0L)), cursor.map(KeyValue::getValue).map(Tuple::fromBytes).asList().join());
cursor = KeyValueCursor.Builder.withSubspace(subspace).setContext(context).setLow(Tuple.from(3, 3), EndpointType.RANGE_EXCLUSIVE).setHigh(Tuple.from(4, 2), EndpointType.RANGE_EXCLUSIVE).setContinuation(cursor.getNext().getContinuation().toBytes()).setScanProperties(ScanProperties.FORWARD_SCAN).build();
assertEquals(Collections.singletonList(Tuple.from(4L, 1L)), cursor.map(KeyValue::getValue).map(Tuple::fromBytes).asList().join());
return null;
});
}
Aggregations