use of com.apple.foundationdb.record.provider.foundationdb.FDBStoreTimer in project fdb-record-layer by FoundationDB.
the class TextIndexTest method getTimer.
@Nonnull
private static FDBStoreTimer getTimer(@Nonnull FDBRecordStore recordStore) {
final FDBStoreTimer timer = recordStore.getTimer();
assertNotNull(timer, "store has not been initialized with a timer");
return timer;
}
use of com.apple.foundationdb.record.provider.foundationdb.FDBStoreTimer in project fdb-record-layer by FoundationDB.
the class ProbableIntersectionCursorTest method basicIntersection.
/**
* Show that a basic intersection succeeds.
*/
@Test
public void basicIntersection() {
final FDBStoreTimer timer = new FDBStoreTimer();
final Iterator<Integer> iterator1 = IntStream.iterate(0, x -> x + 2).limit(150).iterator();
final Iterator<Integer> iterator2 = IntStream.iterate(0, x -> x + 3).limit(100).iterator();
final FirableCursor<Integer> cursor1 = new FirableCursor<>(RecordCursor.fromIterator(iterator1));
final FirableCursor<Integer> cursor2 = new FirableCursor<>(RecordCursor.fromIterator(iterator2));
final RecordCursor<Integer> intersectionCursor = ProbableIntersectionCursor.create(Collections::singletonList, Arrays.asList(bignore -> cursor1, bignore -> cursor2), null, timer);
// Intersection consumes first cursor
cursor1.fireAll();
CompletableFuture<RecordCursorResult<Integer>> firstFuture = intersectionCursor.onNext();
cursor2.fire();
RecordCursorResult<Integer> firstResult = firstFuture.join();
assertEquals(0, (int) firstResult.get());
assertThat(firstResult.hasNext(), is(true));
assertEquals(cursor1.getNext().getNoNextReason(), RecordCursor.NoNextReason.SOURCE_EXHAUSTED);
// Intersection consumes second cursor as they come
cursor2.fireAll();
AtomicInteger falsePositives = new AtomicInteger();
AsyncUtil.whileTrue(() -> intersectionCursor.onNext().thenApply(result -> {
if (result.hasNext()) {
int value = result.get();
// every result *must* be divisible by 3
assertEquals(0, value % 3);
if (value % 2 != 0) {
// most results should be divisible by 2
falsePositives.incrementAndGet();
}
assertThat(result.getContinuation().isEnd(), is(false));
assertNotNull(result.getContinuation().toBytes());
try {
RecordCursorProto.ProbableIntersectionContinuation protoContinuation = RecordCursorProto.ProbableIntersectionContinuation.parseFrom(result.getContinuation().toBytes());
assertEquals(2, protoContinuation.getChildStateCount());
assertThat(protoContinuation.getChildState(0).getExhausted(), is(true));
assertThat(protoContinuation.getChildState(0).hasContinuation(), is(false));
assertThat(protoContinuation.getChildState(1).getExhausted(), is(false));
assertThat(protoContinuation.getChildState(1).hasContinuation(), is(true));
} catch (InvalidProtocolBufferException e) {
throw new RecordCoreException("error parsing proto continuation", e);
}
} else {
assertThat(result.getNoNextReason().isSourceExhausted(), is(true));
assertThat(result.getContinuation().isEnd(), is(true));
assertNull(result.getContinuation().toBytes());
}
return result.hasNext();
}), intersectionCursor.getExecutor()).join();
assertThat(falsePositives.get(), lessThan(5));
assertEquals(50 + falsePositives.get(), timer.getCount(FDBStoreTimer.Counts.QUERY_INTERSECTION_PLAN_MATCHES));
assertEquals(200 - falsePositives.get(), timer.getCount(FDBStoreTimer.Counts.QUERY_INTERSECTION_PLAN_NONMATCHES));
}
use of com.apple.foundationdb.record.provider.foundationdb.FDBStoreTimer in project fdb-record-layer by FoundationDB.
the class ProbableIntersectionCursorTest method loopIterationWithLimit.
@Test
public void loopIterationWithLimit() throws ExecutionException, InterruptedException {
FDBStoreTimer timer = new FDBStoreTimer();
FirableCursor<Integer> secondCursor = new FirableCursor<>(RecordCursor.fromList(Arrays.asList(2, 1)));
RecordCursor<Integer> cursor = ProbableIntersectionCursor.create(Collections::singletonList, Arrays.asList(continuation -> RecordCursor.fromList(Arrays.asList(1, 2), continuation).limitRowsTo(1), continuation -> secondCursor), null, timer);
CompletableFuture<RecordCursorResult<Integer>> cursorResultFuture = cursor.onNext();
secondCursor.fire();
assertFalse(cursorResultFuture.isDone());
secondCursor.fire();
RecordCursorResult<Integer> cursorResult = cursorResultFuture.get();
assertEquals(1, (int) cursorResult.get());
secondCursor.fire();
cursorResult = cursor.getNext();
assertEquals(RecordCursor.NoNextReason.RETURN_LIMIT_REACHED, cursorResult.getNoNextReason());
assertThat(timer.getCount(FDBStoreTimer.Events.QUERY_INTERSECTION), lessThanOrEqualTo(5));
}
use of com.apple.foundationdb.record.provider.foundationdb.FDBStoreTimer in project fdb-record-layer by FoundationDB.
the class UnionIntersectionTest method nonIntersectingReasons.
@Test
public void nonIntersectingReasons() {
final List<Integer> leftList = Arrays.asList(0, 2, 4, 6);
final Function<byte[], RecordCursor<Integer>> left = continuation -> RecordCursor.fromList(leftList, continuation).limitRowsTo(1);
final List<Integer> rightList = Arrays.asList(1, 3, 5, 7);
final Function<byte[], RecordCursor<Integer>> right = continuation -> RecordCursor.fromList(rightList, continuation).limitRowsTo(1);
FDBStoreTimer timer = new FDBStoreTimer();
boolean done = false;
byte[] continuation = null;
List<Integer> results = new ArrayList<>();
while (!done) {
IntersectionCursor<Integer> intersectionCursor = IntersectionCursor.create(Collections::singletonList, false, left, right, continuation, timer);
intersectionCursor.forEach(results::add).join();
RecordCursorResult<Integer> noNextResult = intersectionCursor.getNext();
done = noNextResult.getNoNextReason().isSourceExhausted();
continuation = noNextResult.getContinuation().toBytes();
if (!done) {
assertEquals(RecordCursor.NoNextReason.RETURN_LIMIT_REACHED, noNextResult.getNoNextReason());
}
}
assertEquals(Collections.emptyList(), results);
System.out.println(timer.getKeysAndValues());
}
use of com.apple.foundationdb.record.provider.foundationdb.FDBStoreTimer in project fdb-record-layer by FoundationDB.
the class LocatableResolverTest method testResolveUseCacheCommits.
@Test
public void testResolveUseCacheCommits() {
FDBDatabaseFactory factory = FDBDatabaseFactory.instance();
factory.setDirectoryCacheSize(10);
FDBStoreTimer timer = new FDBStoreTimer();
String key = "hello " + UUID.randomUUID();
FDBDatabase fdb = factory.getDatabase();
assertEquals(0, timer.getCount(FDBStoreTimer.Events.COMMIT));
try (FDBRecordContext context = fdb.openContext()) {
context.setTimer(timer);
context.asyncToSync(FDBStoreTimer.Waits.WAIT_DIRECTORY_RESOLVE, globalScope.resolve(context.getTimer(), key));
}
// initial resolve may commit twice, once for the key and once to initialize the reverse directory cache
assertThat(timer.getCount(FDBStoreTimer.Events.COMMIT), is(greaterThanOrEqualTo(1)));
timer.reset();
try (FDBRecordContext context = fdb.openContext()) {
context.setTimer(timer);
context.asyncToSync(FDBStoreTimer.Waits.WAIT_DIRECTORY_RESOLVE, globalScope.resolve(context.getTimer(), "a-new-key"));
}
assertEquals(1, timer.getCount(FDBStoreTimer.Events.COMMIT));
timer.reset();
assertEquals(0, timer.getCount(FDBStoreTimer.Events.COMMIT));
try (FDBRecordContext context = fdb.openContext()) {
context.setTimer(timer);
context.asyncToSync(FDBStoreTimer.Waits.WAIT_DIRECTORY_RESOLVE, globalScope.resolve(context.getTimer(), key));
}
assertEquals(0, timer.getCount(FDBStoreTimer.Events.COMMIT));
}
Aggregations