Search in sources :

Example 1 with ScopedValue

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

the class FDBReverseDirectoryCache method put.

/**
 * Explicitly add a new entry to the reverse directory cache.
 *
 * @param context the transactional context
 * @param pathKey the name of an entry in the FDB directory, the value of which is retrieved from the directory
 *                and explicitly inserted into the reverse directory cache
 * @return a future that performs the action
 * @throws NoSuchElementException will be thrown by this future if the <code>name</code> provided does not exist in the directory layer.
 */
public CompletableFuture<Void> put(@Nonnull FDBRecordContext context, @Nonnull ScopedValue<String> pathKey) {
    final LocatableResolver scope = pathKey.getScope();
    final String key = pathKey.getData();
    return getReverseCacheSubspace(scope).thenCompose(reverseCacheSubspace -> scope.mustResolve(context, key).thenApply(value -> {
        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug(KeyValueLogMessage.of("Adding value to reverse directory cache", LogMessageKeys.KEY, pathKey, LogMessageKeys.VALUE, value));
        }
        context.ensureActive().set(reverseCacheSubspace.pack(value), Tuple.from(pathKey.getData()).pack());
        return null;
    }));
}
Also used : LogMessageKeys(com.apple.foundationdb.record.logging.LogMessageKeys) ScopedValue(com.apple.foundationdb.record.provider.foundationdb.keyspace.ScopedValue) LoggerFactory(org.slf4j.LoggerFactory) CompletableFuture(java.util.concurrent.CompletableFuture) AsyncUtil(com.apple.foundationdb.async.AsyncUtil) LocatableResolver(com.apple.foundationdb.record.provider.foundationdb.keyspace.LocatableResolver) Subspace(com.apple.foundationdb.subspace.Subspace) Transaction(com.apple.foundationdb.Transaction) ExecuteProperties(com.apple.foundationdb.record.ExecuteProperties) Tuple(com.apple.foundationdb.tuple.Tuple) KeyValueLogMessage(com.apple.foundationdb.record.logging.KeyValueLogMessage) RecordCoreRetriableTransactionException(com.apple.foundationdb.record.RecordCoreRetriableTransactionException) RecordCoreException(com.apple.foundationdb.record.RecordCoreException) ScanProperties(com.apple.foundationdb.record.ScanProperties) NoSuchElementException(java.util.NoSuchElementException) Nonnull(javax.annotation.Nonnull) Nullable(javax.annotation.Nullable) Charsets(com.google.common.base.Charsets) IsolationLevel(com.apple.foundationdb.record.IsolationLevel) Logger(org.slf4j.Logger) KeyValue(com.apple.foundationdb.KeyValue) DirectoryLayer(com.apple.foundationdb.directory.DirectoryLayer) TupleRange(com.apple.foundationdb.record.TupleRange) TimeUnit(java.util.concurrent.TimeUnit) AtomicLong(java.util.concurrent.atomic.AtomicLong) RecordCursor(com.apple.foundationdb.record.RecordCursor) Optional(java.util.Optional) API(com.apple.foundationdb.annotation.API) VisibleForTesting(com.google.common.annotations.VisibleForTesting) Collections(java.util.Collections) LocatableResolver(com.apple.foundationdb.record.provider.foundationdb.keyspace.LocatableResolver)

Aggregations

KeyValue (com.apple.foundationdb.KeyValue)1 Transaction (com.apple.foundationdb.Transaction)1 API (com.apple.foundationdb.annotation.API)1 AsyncUtil (com.apple.foundationdb.async.AsyncUtil)1 DirectoryLayer (com.apple.foundationdb.directory.DirectoryLayer)1 ExecuteProperties (com.apple.foundationdb.record.ExecuteProperties)1 IsolationLevel (com.apple.foundationdb.record.IsolationLevel)1 RecordCoreException (com.apple.foundationdb.record.RecordCoreException)1 RecordCoreRetriableTransactionException (com.apple.foundationdb.record.RecordCoreRetriableTransactionException)1 RecordCursor (com.apple.foundationdb.record.RecordCursor)1 ScanProperties (com.apple.foundationdb.record.ScanProperties)1 TupleRange (com.apple.foundationdb.record.TupleRange)1 KeyValueLogMessage (com.apple.foundationdb.record.logging.KeyValueLogMessage)1 LogMessageKeys (com.apple.foundationdb.record.logging.LogMessageKeys)1 LocatableResolver (com.apple.foundationdb.record.provider.foundationdb.keyspace.LocatableResolver)1 ScopedValue (com.apple.foundationdb.record.provider.foundationdb.keyspace.ScopedValue)1 Subspace (com.apple.foundationdb.subspace.Subspace)1 Tuple (com.apple.foundationdb.tuple.Tuple)1 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 Charsets (com.google.common.base.Charsets)1