use of com.apple.foundationdb.record.ScanProperties in project fdb-record-layer by FoundationDB.
the class FDBRecordStoreSplitRecordsTest method saveAndCheckSplitSimpleRecord.
private void saveAndCheckSplitSimpleRecord(long recno, String strValue, int numValue) {
FDBStoredRecord<Message> savedRecord = saveAndSplitSimpleRecord(recno, strValue, numValue);
try (FDBRecordContext context = openContext()) {
openSimpleRecordStore(context, TEST_SPLIT_HOOK);
FDBStoredRecord<Message> loadedRecord = recordStore.loadRecord(Tuple.from(recno));
assertEquals(savedRecord, loadedRecord);
List<FDBStoredRecord<Message>> scannedRecords = recordStore.scanRecords(null, ScanProperties.FORWARD_SCAN).asList().join();
assertEquals(Collections.singletonList(savedRecord), scannedRecords);
List<FDBStoredRecord<Message>> scanOneRecord = recordStore.scanRecords(null, new ScanProperties(ExecuteProperties.newBuilder().setReturnedRowLimit(1).setIsolationLevel(IsolationLevel.SERIALIZABLE).build())).asList().join();
assertEquals(Collections.singletonList(savedRecord), scanOneRecord);
List<FDBStoredRecord<Message>> reversedScannedRecords = recordStore.scanRecords(null, ScanProperties.REVERSE_SCAN).asList().join();
assertEquals(Collections.singletonList(savedRecord), reversedScannedRecords);
List<FDBStoredRecord<Message>> reversedScannedOneRecord = recordStore.scanRecords(null, new ScanProperties(ExecuteProperties.newBuilder().setReturnedRowLimit(1).setIsolationLevel(IsolationLevel.SERIALIZABLE).build(), true)).asList().join();
assertEquals(Collections.singletonList(savedRecord), reversedScannedOneRecord);
commit(context);
}
}
use of com.apple.foundationdb.record.ScanProperties in project fdb-record-layer by FoundationDB.
the class ChainedCursorTest method testObeysTimeLimit.
@Test
public void testObeysTimeLimit() {
FDBDatabase database = FDBDatabaseFactory.instance().getDatabase();
try (FDBRecordContext context = database.openContext()) {
ScanProperties props = new ScanProperties(ExecuteProperties.newBuilder().setTimeLimit(4L).setFailOnScanLimitReached(false).build());
RecordCursorIterator<Long> cursor = new ChainedCursor<>(context, (lastKey) -> nextKey(lastKey).thenApply(value -> {
sleep(1L);
return value;
}), (key) -> Tuple.from(key).pack(), (prevContinuation) -> Tuple.fromBytes(prevContinuation).getLong(0), null, props).asIterator();
int count = 0;
while (cursor.hasNext()) {
assertEquals(Long.valueOf(count), cursor.next());
++count;
}
assertEquals(cursor.getNoNextReason(), RecordCursor.NoNextReason.TIME_LIMIT_REACHED);
assertTrue(count < 5, "Too many values returned");
}
}
use of com.apple.foundationdb.record.ScanProperties in project fdb-record-layer by FoundationDB.
the class ChainedCursorTest method testHatesReverse.
@Test
public void testHatesReverse() {
// The chained cursor cannot implement a reverse scan
assertThrows(RecordCoreArgumentException.class, () -> {
FDBDatabase database = FDBDatabaseFactory.instance().getDatabase();
try (FDBRecordContext context = database.openContext()) {
ScanProperties props = new ScanProperties(ExecuteProperties.newBuilder().build(), true);
new ChainedCursor<>(context, (lastKey) -> CompletableFuture.completedFuture(Optional.of(10L)), (key) -> new byte[0], (prevContinuation) -> 10L, null, props);
}
});
}
use of com.apple.foundationdb.record.ScanProperties in project fdb-record-layer by FoundationDB.
the class FDBRecordStoreSplitRecordsTest method testSplitContinuation.
@Test
public void testSplitContinuation() {
try (FDBRecordContext context = openContext()) {
openSimpleRecordStore(context, TEST_SPLIT_HOOK);
commit(context);
}
final String bigValue = Strings.repeat("X", SplitHelper.SPLIT_RECORD_SIZE + 10);
final String smallValue = Strings.repeat("Y", 5);
final List<FDBStoredRecord<Message>> createdRecords = new ArrayList<>();
createdRecords.add(saveAndSplitSimpleRecord(1L, smallValue, 1));
createdRecords.add(saveAndSplitSimpleRecord(2L, smallValue, 2));
createdRecords.add(saveAndSplitSimpleRecord(3L, bigValue, 3));
createdRecords.add(saveAndSplitSimpleRecord(4L, smallValue, 4));
createdRecords.add(saveAndSplitSimpleRecord(5L, bigValue, 5));
createdRecords.add(saveAndSplitSimpleRecord(6L, bigValue, 6));
createdRecords.add(saveAndSplitSimpleRecord(7L, smallValue, 7));
createdRecords.add(saveAndSplitSimpleRecord(8L, smallValue, 8));
createdRecords.add(saveAndSplitSimpleRecord(9L, smallValue, 9));
// Scan one record at a time using continuations
final List<FDBStoredRecord<Message>> scannedRecords = new ArrayList<>();
try (FDBRecordContext context = openContext()) {
openSimpleRecordStore(context, TEST_SPLIT_HOOK);
RecordCursorIterator<FDBStoredRecord<Message>> messageCursor = recordStore.scanRecords(null, new ScanProperties(ExecuteProperties.newBuilder().setReturnedRowLimit(1).setIsolationLevel(IsolationLevel.SERIALIZABLE).build())).asIterator();
while (messageCursor.hasNext()) {
scannedRecords.add(messageCursor.next());
messageCursor = recordStore.scanRecords(messageCursor.getContinuation(), new ScanProperties(ExecuteProperties.newBuilder().setReturnedRowLimit(1).setIsolationLevel(IsolationLevel.SERIALIZABLE).build())).asIterator();
}
commit(context);
}
assertEquals(createdRecords, scannedRecords);
}
use of com.apple.foundationdb.record.ScanProperties in project fdb-record-layer by FoundationDB.
the class SplitHelperTest method scanSingleRecord.
private FDBRawRecord scanSingleRecord(@Nonnull FDBRecordContext context, boolean reverse, @Nonnull Tuple key, @Nullable FDBStoredSizes expectedSizes, @Nullable byte[] expectedContents, @Nullable FDBRecordVersion version) {
final ScanProperties scanProperties = reverse ? ScanProperties.REVERSE_SCAN : ScanProperties.FORWARD_SCAN;
KeyValueCursor kvCursor = KeyValueCursor.Builder.withSubspace(subspace).setContext(context).setRange(TupleRange.allOf(key)).setScanProperties(scanProperties).build();
SplitHelper.KeyValueUnsplitter kvUnsplitter = new SplitHelper.KeyValueUnsplitter(context, subspace, kvCursor, false, null, scanProperties);
RecordCursorResult<FDBRawRecord> result = kvUnsplitter.getNext();
if (expectedSizes == null || expectedContents == null) {
assertThat(result.hasNext(), is(false));
assertEquals(RecordCursor.NoNextReason.SOURCE_EXHAUSTED, result.getNoNextReason());
return null;
} else {
assertThat(result.hasNext(), is(true));
final FDBRawRecord rawRecord = result.get();
result = kvUnsplitter.getNext();
assertThat(result.hasNext(), is(false));
assertEquals(RecordCursor.NoNextReason.SOURCE_EXHAUSTED, result.getNoNextReason());
assertNotNull(rawRecord);
assertEquals(key, rawRecord.getPrimaryKey());
assertArrayEquals(expectedContents, rawRecord.getRawRecord());
assertEquals(expectedSizes.getKeyCount(), rawRecord.getKeyCount());
assertEquals(expectedSizes.getKeySize(), rawRecord.getKeySize());
assertEquals(expectedSizes.getValueSize(), rawRecord.getValueSize());
boolean isSplit = rawRecord.getKeyCount() - (rawRecord.isVersionedInline() ? 1 : 0) != 1;
assertEquals(rawRecord.getKeyCount() - (rawRecord.isVersionedInline() ? 1 : 0) != 1, expectedSizes.isSplit());
assertEquals(version != null, expectedSizes.isVersionedInline());
return rawRecord;
}
}
Aggregations