Search in sources :

Example 61 with Subspace

use of com.apple.foundationdb.subspace.Subspace in project fdb-record-layer by FoundationDB.

the class SynchronizedSessionRunner method startSessionAsync.

/**
 * Produces a new runner, wrapping a given runner, which performs all work in the context of a new
 * {@link SynchronizedSession}.
 * <p>
 * The returned runner will have acquired and started the lease, so care must be taken to ensure that
 * work begins before the lease expiration period.
 * </p>
 * @param lockSubspace the lock for which the session contends
 * @param leaseLengthMill length between last access and lease's end time in milliseconds
 * @param runner the underlying runner
 * @return a future that will return a runner maintaining a new synchronized session
 */
public static CompletableFuture<SynchronizedSessionRunner> startSessionAsync(@Nonnull Subspace lockSubspace, long leaseLengthMill, @Nonnull FDBDatabaseRunnerImpl runner) {
    final UUID newSessionId = UUID.randomUUID();
    SynchronizedSession session = new SynchronizedSession(lockSubspace, newSessionId, leaseLengthMill);
    return runner.runAsync(context -> session.initializeSessionAsync(context.ensureActive()), Arrays.asList(LogMessageKeys.TRANSACTION_NAME, "SynchronizedSessionRunner::startSession", LogMessageKeys.SESSION_ID, session.getSessionId(), LogMessageKeys.SUBSPACE, lockSubspace)).thenApply(vignore -> new SynchronizedSessionRunner(runner, session));
}
Also used : Arrays(java.util.Arrays) LogMessageKeys(com.apple.foundationdb.record.logging.LogMessageKeys) StoreTimer(com.apple.foundationdb.record.provider.common.StoreTimer) FDBStoreTimer(com.apple.foundationdb.record.provider.foundationdb.FDBStoreTimer) Executor(java.util.concurrent.Executor) BiFunction(java.util.function.BiFunction) FDBRecordContext(com.apple.foundationdb.record.provider.foundationdb.FDBRecordContext) CompletableFuture(java.util.concurrent.CompletableFuture) AsyncUtil(com.apple.foundationdb.async.AsyncUtil) FDBDatabase(com.apple.foundationdb.record.provider.foundationdb.FDBDatabase) FDBDatabaseRunnerImpl(com.apple.foundationdb.record.provider.foundationdb.FDBDatabaseRunnerImpl) UUID(java.util.UUID) Function(java.util.function.Function) FDBRecordContextConfig(com.apple.foundationdb.record.provider.foundationdb.FDBRecordContextConfig) Subspace(com.apple.foundationdb.subspace.Subspace) ArrayList(java.util.ArrayList) List(java.util.List) Pair(org.apache.commons.lang3.tuple.Pair) API(com.apple.foundationdb.annotation.API) FDBDatabaseRunner(com.apple.foundationdb.record.provider.foundationdb.FDBDatabaseRunner) Nonnull(javax.annotation.Nonnull) Nullable(javax.annotation.Nullable) SynchronizedSession(com.apple.foundationdb.synchronizedsession.SynchronizedSession) UUID(java.util.UUID) SynchronizedSession(com.apple.foundationdb.synchronizedsession.SynchronizedSession)

Aggregations

Subspace (com.apple.foundationdb.subspace.Subspace)61 Nonnull (javax.annotation.Nonnull)33 Tuple (com.apple.foundationdb.tuple.Tuple)28 List (java.util.List)23 ArrayList (java.util.ArrayList)21 CompletableFuture (java.util.concurrent.CompletableFuture)21 Nullable (javax.annotation.Nullable)20 RecordCoreException (com.apple.foundationdb.record.RecordCoreException)19 KeyValue (com.apple.foundationdb.KeyValue)18 Map (java.util.Map)18 AsyncUtil (com.apple.foundationdb.async.AsyncUtil)17 API (com.apple.foundationdb.annotation.API)16 ScanProperties (com.apple.foundationdb.record.ScanProperties)15 Collections (java.util.Collections)15 Test (org.junit.jupiter.api.Test)15 Transaction (com.apple.foundationdb.Transaction)14 RecordCursor (com.apple.foundationdb.record.RecordCursor)14 TupleRange (com.apple.foundationdb.record.TupleRange)14 LogMessageKeys (com.apple.foundationdb.record.logging.LogMessageKeys)14 Message (com.google.protobuf.Message)14