Search in sources :

Example 1 with FDBDatabaseFactory

use of com.apple.foundationdb.record.provider.foundationdb.FDBDatabaseFactory in project fdb-record-layer by FoundationDB.

the class TestingResolverFactory method beforeEach.

@Override
public void beforeEach(@Nonnull final ExtensionContext context) throws Exception {
    resolvers.clear();
    knownBadEntries.clear();
    FDBDatabaseFactory factory = FDBDatabaseFactory.instance();
    factory.setDirectoryCacheSize(100);
    database = factory.getDatabase();
    // clear all state in the db
    database.close();
    // resets the lock cache
    database.setResolverStateRefreshTimeMillis(30000);
    wipeFDB();
}
Also used : FDBDatabaseFactory(com.apple.foundationdb.record.provider.foundationdb.FDBDatabaseFactory)

Example 2 with FDBDatabaseFactory

use of com.apple.foundationdb.record.provider.foundationdb.FDBDatabaseFactory in project fdb-record-layer by FoundationDB.

the class ResolverCreateHooksTest method setup.

@BeforeEach
public void setup() {
    FDBDatabaseFactory factory = FDBDatabaseFactory.instance();
    database = factory.getDatabase();
    database.clearCaches();
    keySpace = new KeySpace(new KeySpaceDirectory("test-root", KeySpaceDirectory.KeyType.STRING, "test-" + random.nextLong()).addSubdirectory(new KeySpaceDirectory("resolvers", KeySpaceDirectory.KeyType.STRING, "resolvers").addSubdirectory(new KeySpaceDirectory("resolverNode", KeySpaceDirectory.KeyType.STRING))).addSubdirectory(new KeySpaceDirectory("should-use-A", KeySpaceDirectory.KeyType.STRING, "should-use-A")));
}
Also used : FDBDatabaseFactory(com.apple.foundationdb.record.provider.foundationdb.FDBDatabaseFactory) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 3 with FDBDatabaseFactory

use of com.apple.foundationdb.record.provider.foundationdb.FDBDatabaseFactory 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));
}
Also used : FDBRecordContext(com.apple.foundationdb.record.provider.foundationdb.FDBRecordContext) FDBStoreTimer(com.apple.foundationdb.record.provider.foundationdb.FDBStoreTimer) FDBDatabase(com.apple.foundationdb.record.provider.foundationdb.FDBDatabase) FDBDatabaseFactory(com.apple.foundationdb.record.provider.foundationdb.FDBDatabaseFactory) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 4 with FDBDatabaseFactory

use of com.apple.foundationdb.record.provider.foundationdb.FDBDatabaseFactory in project fdb-record-layer by FoundationDB.

the class LocatableResolverTest method testDirectoryCache.

@Test
public void testDirectoryCache() {
    FDBDatabaseFactory factory = FDBDatabaseFactory.instance();
    factory.setDirectoryCacheSize(10);
    FDBStoreTimer timer = new FDBStoreTimer();
    FDBDatabase fdb = factory.getDatabase();
    // Make sure cache is fresh.
    fdb.close();
    String key = "world";
    Long value;
    try (FDBRecordContext context = fdb.openContext()) {
        context.setTimer(timer);
        value = context.asyncToSync(FDBStoreTimer.Waits.WAIT_DIRECTORY_RESOLVE, globalScope.resolve(context.getTimer(), key));
    }
    int initialReads = timer.getCount(FDBStoreTimer.Events.DIRECTORY_READ);
    assertThat(initialReads, is(greaterThanOrEqualTo(1)));
    for (int i = 0; i < 10; i++) {
        try (FDBRecordContext context = fdb.openContext()) {
            context.setTimer(timer);
            assertThat("we continue to resolve the same value", context.asyncToSync(FDBStoreTimer.Waits.WAIT_DIRECTORY_RESOLVE, globalScope.resolve(context.getTimer(), key)), is(value));
        }
    }
    assertEquals(timer.getCount(FDBStoreTimer.Events.DIRECTORY_READ), initialReads);
}
Also used : FDBRecordContext(com.apple.foundationdb.record.provider.foundationdb.FDBRecordContext) FDBStoreTimer(com.apple.foundationdb.record.provider.foundationdb.FDBStoreTimer) FDBDatabase(com.apple.foundationdb.record.provider.foundationdb.FDBDatabase) FDBDatabaseFactory(com.apple.foundationdb.record.provider.foundationdb.FDBDatabaseFactory) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 5 with FDBDatabaseFactory

use of com.apple.foundationdb.record.provider.foundationdb.FDBDatabaseFactory in project fdb-record-layer by FoundationDB.

the class LocatableResolverTest method testVersionIncrementInvalidatesCache.

@Test
public void testVersionIncrementInvalidatesCache() {
    FDBDatabaseFactory factory = FDBDatabaseFactory.instance();
    factory.setDirectoryCacheSize(10);
    FDBStoreTimer timer = new FDBStoreTimer();
    FDBDatabase fdb = factory.getDatabase();
    // Make sure cache is fresh, and resets version
    fdb.close();
    fdb.setResolverStateRefreshTimeMillis(100);
    String key = "some-key";
    Long value;
    try (FDBRecordContext context = fdb.openContext()) {
        context.setTimer(timer);
        value = context.asyncToSync(FDBStoreTimer.Waits.WAIT_DIRECTORY_RESOLVE, globalScope.resolve(context.getTimer(), key));
    }
    assertThat(timer.getCount(FDBStoreTimer.Events.DIRECTORY_READ), is(greaterThanOrEqualTo(1)));
    timer.reset();
    consistently("we hit the cached value", () -> {
        try (FDBRecordContext context = fdb.openContext()) {
            context.setTimer(timer);
            assertThat("the resolved value is still the same", globalScope.resolve(context.getTimer(), key).join(), is(value));
        }
        return timer.getCount(FDBStoreTimer.Events.DIRECTORY_READ);
    }, is(0), 200, 10);
    globalScope.incrementVersion().join();
    timer.reset();
    eventually("we see the version change and invalidate the cache", () -> {
        try (FDBRecordContext context = fdb.openContext()) {
            context.setTimer(timer);
            assertThat("the resolved value is still the same", globalScope.resolve(context.getTimer(), key).join(), is(value));
        }
        return timer.getCount(FDBStoreTimer.Events.DIRECTORY_READ);
    }, is(1), 120, 10);
    timer.reset();
    consistently("the value is cached while the version is not changed", () -> {
        try (FDBRecordContext context = fdb.openContext()) {
            context.setTimer(timer);
            assertThat("the resolved value is still the same", globalScope.resolve(context.getTimer(), key).join(), is(value));
        }
        return timer.getCount(FDBStoreTimer.Events.DIRECTORY_READ);
    }, is(0), 200, 10);
}
Also used : FDBRecordContext(com.apple.foundationdb.record.provider.foundationdb.FDBRecordContext) FDBStoreTimer(com.apple.foundationdb.record.provider.foundationdb.FDBStoreTimer) FDBDatabase(com.apple.foundationdb.record.provider.foundationdb.FDBDatabase) FDBDatabaseFactory(com.apple.foundationdb.record.provider.foundationdb.FDBDatabaseFactory) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

FDBDatabaseFactory (com.apple.foundationdb.record.provider.foundationdb.FDBDatabaseFactory)8 FDBDatabase (com.apple.foundationdb.record.provider.foundationdb.FDBDatabase)4 FDBRecordContext (com.apple.foundationdb.record.provider.foundationdb.FDBRecordContext)4 FDBStoreTimer (com.apple.foundationdb.record.provider.foundationdb.FDBStoreTimer)4 BeforeEach (org.junit.jupiter.api.BeforeEach)4 Test (org.junit.jupiter.api.Test)4 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)4 AsyncUtil (com.apple.foundationdb.async.AsyncUtil)1 MoreAsyncUtil (com.apple.foundationdb.async.MoreAsyncUtil)1 ExecuteProperties (com.apple.foundationdb.record.ExecuteProperties)1 RecordCoreException (com.apple.foundationdb.record.RecordCoreException)1 ScanProperties (com.apple.foundationdb.record.ScanProperties)1 ExceptionMessageMatcher.hasMessageContaining (com.apple.foundationdb.record.TestHelpers.ExceptionMessageMatcher.hasMessageContaining)1 TestHelpers.consistently (com.apple.foundationdb.record.TestHelpers.consistently)1 TestHelpers.eventually (com.apple.foundationdb.record.TestHelpers.eventually)1 FDBDatabaseFactoryImpl (com.apple.foundationdb.record.provider.foundationdb.FDBDatabaseFactoryImpl)1 FDBRecordContextConfig (com.apple.foundationdb.record.provider.foundationdb.FDBRecordContextConfig)1 FDBTestBase (com.apple.foundationdb.record.provider.foundationdb.FDBTestBase)1 KeyType (com.apple.foundationdb.record.provider.foundationdb.keyspace.KeySpaceDirectory.KeyType)1 LocatableResolverLockedException (com.apple.foundationdb.record.provider.foundationdb.keyspace.LocatableResolver.LocatableResolverLockedException)1