Search in sources :

Example 1 with ScopedDirectoryLayer

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

the class FDBReverseDirectoryCacheTest method testPutIfNotExistsNotVisibleUntilCommit.

@Test
public void testPutIfNotExistsNotVisibleUntilCommit() throws Exception {
    final ScopedDirectoryLayer scope = globalScope;
    final String name = "dir_" + Math.abs(new Random().nextInt());
    final FDBReverseDirectoryCache rdc = fdb.getReverseDirectoryCache();
    final ScopedValue<String> scopedName = scope.wrap(name);
    // Create a new directory layer entry, put it in the cache in the same transaction
    try (FDBRecordContext context = openContext()) {
        Transaction transaction = context.ensureActive();
        DirectoryLayer directoryLayerToUse = new DirectoryLayer(context.join(scope.getNodeSubspace(context)), scope.getContentSubspace());
        final byte[] rawDirectoryEntry = directoryLayerToUse.createOrOpen(transaction, Collections.singletonList(name)).get().getKey();
        final Long id = Tuple.fromBytes(rawDirectoryEntry).getLong(0);
        rdc.putIfNotExists(context, scopedName, id).get();
        // This happens in its own transaction so should not yet see the uncommitted directory and reverse
        // directory entries that are being created.
        Optional<String> result = rdc.get(scope.wrap(id)).join();
        assertFalse(result.isPresent(), "Should not have gotten a result from RDC lookup");
        commit(context);
    }
}
Also used : DirectoryLayer(com.apple.foundationdb.directory.DirectoryLayer) ScopedDirectoryLayer(com.apple.foundationdb.record.provider.foundationdb.keyspace.ScopedDirectoryLayer) ScopedDirectoryLayer(com.apple.foundationdb.record.provider.foundationdb.keyspace.ScopedDirectoryLayer) Random(java.util.Random) Transaction(com.apple.foundationdb.Transaction) Test(org.junit.jupiter.api.Test)

Example 2 with ScopedDirectoryLayer

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

the class FDBReverseDirectoryCacheTest method createRandomDirectoryScope.

private LocatableResolver createRandomDirectoryScope() {
    final String name = String.format("name-%d", Math.abs(random.nextLong()));
    KeySpace keySpace = new KeySpace(new KeySpaceDirectory(name, KeySpaceDirectory.KeyType.STRING, name));
    ResolvedKeySpacePath path;
    try (FDBRecordContext context = fdb.openContext()) {
        path = keySpace.resolveFromKey(context, Tuple.from(name));
    }
    return new ScopedDirectoryLayer(fdb, path);
}
Also used : ScopedDirectoryLayer(com.apple.foundationdb.record.provider.foundationdb.keyspace.ScopedDirectoryLayer) ResolvedKeySpacePath(com.apple.foundationdb.record.provider.foundationdb.keyspace.ResolvedKeySpacePath) KeySpace(com.apple.foundationdb.record.provider.foundationdb.keyspace.KeySpace) KeySpaceDirectory(com.apple.foundationdb.record.provider.foundationdb.keyspace.KeySpaceDirectory)

Aggregations

ScopedDirectoryLayer (com.apple.foundationdb.record.provider.foundationdb.keyspace.ScopedDirectoryLayer)2 Transaction (com.apple.foundationdb.Transaction)1 DirectoryLayer (com.apple.foundationdb.directory.DirectoryLayer)1 KeySpace (com.apple.foundationdb.record.provider.foundationdb.keyspace.KeySpace)1 KeySpaceDirectory (com.apple.foundationdb.record.provider.foundationdb.keyspace.KeySpaceDirectory)1 ResolvedKeySpacePath (com.apple.foundationdb.record.provider.foundationdb.keyspace.ResolvedKeySpacePath)1 Random (java.util.Random)1 Test (org.junit.jupiter.api.Test)1