Class FDBDatabaseRunnerImpl
- java.lang.Object
-
- com.apple.foundationdb.record.provider.foundationdb.FDBDatabaseRunnerImpl
-
- All Implemented Interfaces:
FDBDatabaseRunner
,AutoCloseable
@API(INTERNAL) public class FDBDatabaseRunnerImpl extends Object implements FDBDatabaseRunner
The standard implementation ofFDBDatabaseRunner
.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface com.apple.foundationdb.record.provider.foundationdb.FDBDatabaseRunner
FDBDatabaseRunner.RunnerClosed
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description <T> T
asyncToSync(StoreTimer.Wait event, CompletableFuture<T> async)
void
close()
Close this runner.FDBRecordContextConfig.Builder
getContextConfigBuilder()
Get the configuration used in record contexts opened by this runner.FDBDatabase
getDatabase()
Get the database against which functions are run.Executor
getExecutor()
long
getInitialDelayMillis()
Gets the delay ceiling (in milliseconds) that will be applied between attempts to run a transactional database operation.int
getMaxAttempts()
Gets the maximum number of attempts for a database to make when running a retriable transactional operation.long
getMaxDelayMillis()
Gets the maximum delay (in milliseconds) that will be applied between attempts to run a transactional database operation.long
getMinDelayMillis()
Gets the minimum delay (in milliseconds) that will be applied between attempts to run a transactional database operation.SynchronizedSessionRunner
joinSynchronizedSession(Subspace lockSubspace, UUID sessionId, long leaseLengthMillis)
Produces a new runner, wrapping this runner, which performs all work in the context of an existingSynchronizedSession
.FDBRecordContext
openContext()
Open a new record context.<T> T
run(Function<? super FDBRecordContext,? extends T> retriable, List<Object> additionalLogMessageKeyValues)
Runs a transactional function against with retry logic.<T> CompletableFuture<T>
runAsync(Function<? super FDBRecordContext,CompletableFuture<? extends T>> retriable, BiFunction<? super T,Throwable,? extends org.apache.commons.lang3.tuple.Pair<? extends T,? extends Throwable>> handlePostTransaction, List<Object> additionalLogMessageKeyValues)
Runs a transactional function asynchronously with retry logic.void
setContextConfigBuilder(FDBRecordContextConfig.Builder contextConfigBuilder)
Set the configuration used in record contexts opened by this runner.void
setInitialDelayMillis(long initialDelayMillis)
Sets the delay ceiling (in milliseconds) that will be applied between attempts to run a transactional database operation.void
setMaxAttempts(int maxAttempts)
Sets the maximum number of attempts for a database to make when running a retriable transactional operation.void
setMaxDelayMillis(long maxDelayMillis)
Sets the maximum delay (in milliseconds) that will be applied between attempts to run a transactional database operation.void
setMdcContext(Map<String,String> mdcContext)
Set the logging context used in record contexts opened by this runner.SynchronizedSessionRunner
startSynchronizedSession(Subspace lockSubspace, long leaseLengthMillis)
Synchronous/blocking version ofFDBDatabaseRunner.startSynchronizedSessionAsync(Subspace, long)
.CompletableFuture<SynchronizedSessionRunner>
startSynchronizedSessionAsync(Subspace lockSubspace, long leaseLengthMillis)
Produces a new runner, wrapping this runner, which performs all work in the context of a newSynchronizedSession
.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.apple.foundationdb.record.provider.foundationdb.FDBDatabaseRunner
getMdcContext, getPriority, getTimer, getTransactionTimeoutMillis, getWeakReadSemantics, run, runAsync, runAsync, setPriority, setTimer, setTransactionTimeoutMillis, setWeakReadSemantics
-
-
-
-
Method Detail
-
getDatabase
@Nonnull public FDBDatabase getDatabase()
Description copied from interface:FDBDatabaseRunner
Get the database against which functions are run.- Specified by:
getDatabase
in interfaceFDBDatabaseRunner
- Returns:
- the database used to run
-
getContextConfigBuilder
@Nonnull public FDBRecordContextConfig.Builder getContextConfigBuilder()
Description copied from interface:FDBDatabaseRunner
Get the configuration used in record contexts opened by this runner. Any changes made to the returned builder will be reflected in contexts opened by this runner.- Specified by:
getContextConfigBuilder
in interfaceFDBDatabaseRunner
- Returns:
- configuration to use
-
setContextConfigBuilder
public void setContextConfigBuilder(@Nonnull FDBRecordContextConfig.Builder contextConfigBuilder)
Description copied from interface:FDBDatabaseRunner
Set the configuration used in record contexts opened by this runner.- Specified by:
setContextConfigBuilder
in interfaceFDBDatabaseRunner
- Parameters:
contextConfigBuilder
- configuration to use
-
getExecutor
public Executor getExecutor()
Description copied from interface:FDBDatabaseRunner
Get the executor that will be used forFDBDatabaseRunner.runAsync(java.util.function.Function<? super com.apple.foundationdb.record.provider.foundationdb.FDBRecordContext, java.util.concurrent.CompletableFuture<? extends T>>)
.- Specified by:
getExecutor
in interfaceFDBDatabaseRunner
- Returns:
- the executor to use
-
setMdcContext
public void setMdcContext(@Nullable Map<String,String> mdcContext)
Description copied from interface:FDBDatabaseRunner
Set the logging context used in record contexts opened by this runner. This will change the executor to be one that restores this newmdcContext
.- Specified by:
setMdcContext
in interfaceFDBDatabaseRunner
- Parameters:
mdcContext
- the logging context to use- See Also:
FDBDatabase.openContext(Map,FDBStoreTimer)
-
getMaxAttempts
public int getMaxAttempts()
Description copied from interface:FDBDatabaseRunner
Gets the maximum number of attempts for a database to make when running a retriable transactional operation. This is used byFDBDatabaseRunner.run(java.util.function.Function<? super com.apple.foundationdb.record.provider.foundationdb.FDBRecordContext, ? extends T>)
andFDBDatabaseRunner.runAsync(java.util.function.Function<? super com.apple.foundationdb.record.provider.foundationdb.FDBRecordContext, java.util.concurrent.CompletableFuture<? extends T>>)
to limit the number of attempts that an operation is retried.- Specified by:
getMaxAttempts
in interfaceFDBDatabaseRunner
- Returns:
- the maximum number of times to run a transactional database operation
-
setMaxAttempts
public void setMaxAttempts(int maxAttempts)
Description copied from interface:FDBDatabaseRunner
Sets the maximum number of attempts for a database to make when running a retriable transactional operation. This is used byFDBDatabaseRunner.run(java.util.function.Function<? super com.apple.foundationdb.record.provider.foundationdb.FDBRecordContext, ? extends T>)
andFDBDatabaseRunner.runAsync(java.util.function.Function<? super com.apple.foundationdb.record.provider.foundationdb.FDBRecordContext, java.util.concurrent.CompletableFuture<? extends T>>)
to limit the number of attempts that an operation is retried.- Specified by:
setMaxAttempts
in interfaceFDBDatabaseRunner
- Parameters:
maxAttempts
- the maximum number of times to run a transactional database operation
-
getMinDelayMillis
public long getMinDelayMillis()
Description copied from interface:FDBDatabaseRunner
Gets the minimum delay (in milliseconds) that will be applied between attempts to run a transactional database operation. This is used withinFDBDatabaseRunner.run(java.util.function.Function<? super com.apple.foundationdb.record.provider.foundationdb.FDBRecordContext, ? extends T>)
andFDBDatabaseRunner.runAsync(java.util.function.Function<? super com.apple.foundationdb.record.provider.foundationdb.FDBRecordContext, java.util.concurrent.CompletableFuture<? extends T>>)
to limit the time spent between successive attempts at completing a database operation. Currently this value is fixed at 2 milliseconds and is not settable.- Specified by:
getMinDelayMillis
in interfaceFDBDatabaseRunner
- Returns:
- the minimum delay between attempts when retrying operations
-
getMaxDelayMillis
public long getMaxDelayMillis()
Description copied from interface:FDBDatabaseRunner
Gets the maximum delay (in milliseconds) that will be applied between attempts to run a transactional database operation. This is used withinFDBDatabaseRunner.run(java.util.function.Function<? super com.apple.foundationdb.record.provider.foundationdb.FDBRecordContext, ? extends T>)
andFDBDatabaseRunner.runAsync(java.util.function.Function<? super com.apple.foundationdb.record.provider.foundationdb.FDBRecordContext, java.util.concurrent.CompletableFuture<? extends T>>)
to limit the time spent between successive attempts at completing a database operation. The default value is 1000 so that there will not be more than 1 second between attempts.- Specified by:
getMaxDelayMillis
in interfaceFDBDatabaseRunner
- Returns:
- the maximum delay between attempts when retrying operations
-
setMaxDelayMillis
public void setMaxDelayMillis(long maxDelayMillis)
Description copied from interface:FDBDatabaseRunner
Sets the maximum delay (in milliseconds) that will be applied between attempts to run a transactional database operation. This is used withinFDBDatabaseRunner.run(java.util.function.Function<? super com.apple.foundationdb.record.provider.foundationdb.FDBRecordContext, ? extends T>)
andFDBDatabaseRunner.runAsync(java.util.function.Function<? super com.apple.foundationdb.record.provider.foundationdb.FDBRecordContext, java.util.concurrent.CompletableFuture<? extends T>>)
to limit the time spent between successive attempts at completing a database operation. The default value is 1000 so that there will not be more than 1 second between attempts.- Specified by:
setMaxDelayMillis
in interfaceFDBDatabaseRunner
- Parameters:
maxDelayMillis
- the maximum delay between attempts when retrying operations
-
getInitialDelayMillis
public long getInitialDelayMillis()
Description copied from interface:FDBDatabaseRunner
Gets the delay ceiling (in milliseconds) that will be applied between attempts to run a transactional database operation. This is used withinFDBDatabaseRunner.run(java.util.function.Function<? super com.apple.foundationdb.record.provider.foundationdb.FDBRecordContext, ? extends T>)
andFDBDatabaseRunner.runAsync(java.util.function.Function<? super com.apple.foundationdb.record.provider.foundationdb.FDBRecordContext, java.util.concurrent.CompletableFuture<? extends T>>)
to determine how long to wait between the first and second attempts at running a database operation. The exponential backoff algorithm will choose an amount of time to wait between zero and the initial delay, and will use that value each successive iteration to determine how long that wait should be. The default value is 10 milliseconds.- Specified by:
getInitialDelayMillis
in interfaceFDBDatabaseRunner
- Returns:
- the delay ceiling between the first and second attempts at running a database operation
-
setInitialDelayMillis
public void setInitialDelayMillis(long initialDelayMillis)
Description copied from interface:FDBDatabaseRunner
Sets the delay ceiling (in milliseconds) that will be applied between attempts to run a transactional database operation. This is used withinFDBDatabaseRunner.run(java.util.function.Function<? super com.apple.foundationdb.record.provider.foundationdb.FDBRecordContext, ? extends T>)
andFDBDatabaseRunner.runAsync(java.util.function.Function<? super com.apple.foundationdb.record.provider.foundationdb.FDBRecordContext, java.util.concurrent.CompletableFuture<? extends T>>)
to determine how long to wait between the first and second attempts at running a database operation. The exponential backoff algorithm will choose an amount of time to wait between zero and the initial delay, and will use that value each successive iteration to determine how long that wait should be. The default value is 10 milliseconds.- Specified by:
setInitialDelayMillis
in interfaceFDBDatabaseRunner
- Parameters:
initialDelayMillis
- the delay ceiling between the first and second attempts at running a database operation
-
openContext
@Nonnull public FDBRecordContext openContext()
Description copied from interface:FDBDatabaseRunner
Open a new record context.- Specified by:
openContext
in interfaceFDBDatabaseRunner
- Returns:
- a new open record context
- See Also:
FDBDatabase.openContext(Map,FDBStoreTimer,FDBDatabase.WeakReadSemantics)
-
run
@API(EXPERIMENTAL) public <T> T run(@Nonnull Function<? super FDBRecordContext,? extends T> retriable, @Nullable List<Object> additionalLogMessageKeyValues)
Description copied from interface:FDBDatabaseRunner
Runs a transactional function against with retry logic. This is a blocking call. See the appropriate overload ofFDBDatabaseRunner.runAsync(java.util.function.Function<? super com.apple.foundationdb.record.provider.foundationdb.FDBRecordContext, java.util.concurrent.CompletableFuture<? extends T>>)
for the non-blocking version of this method.- Specified by:
run
in interfaceFDBDatabaseRunner
- Type Parameters:
T
- return type of function to run- Parameters:
retriable
- the database operation to run transactionallyadditionalLogMessageKeyValues
- additional key/value pairs to be included in logs- Returns:
- result of function after successful run and commit
- See Also:
FDBDatabaseRunner.runAsync(Function)
-
runAsync
@Nonnull @API(EXPERIMENTAL) public <T> CompletableFuture<T> runAsync(@Nonnull Function<? super FDBRecordContext,CompletableFuture<? extends T>> retriable, @Nonnull BiFunction<? super T,Throwable,? extends org.apache.commons.lang3.tuple.Pair<? extends T,? extends Throwable>> handlePostTransaction, @Nullable List<Object> additionalLogMessageKeyValues)
Description copied from interface:FDBDatabaseRunner
Runs a transactional function asynchronously with retry logic. This is also a non-blocking call.- Specified by:
runAsync
in interfaceFDBDatabaseRunner
- Type Parameters:
T
- return type of function to run- Parameters:
retriable
- the database operation to run transactionallyhandlePostTransaction
- after the transaction is committed, or fails to commit, this function is called with the result or exception respectively. This handler should return a new pair with either the result to return fromrunAsync
or an exception to be checked whetherretriable
should be retried.additionalLogMessageKeyValues
- additional key/value pairs to be included in logs- Returns:
- future that will contain the result of
retriable
after successful run and commit - See Also:
FDBDatabaseRunner.run(Function)
-
asyncToSync
@Nullable public <T> T asyncToSync(StoreTimer.Wait event, @Nonnull CompletableFuture<T> async)
- Specified by:
asyncToSync
in interfaceFDBDatabaseRunner
-
close
public void close()
Description copied from interface:FDBDatabaseRunner
Close this runner.- Disallows starting more transactions
- Closes already open transactions
- Cancels futures returned by
runAsync
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceFDBDatabaseRunner
-
startSynchronizedSessionAsync
public CompletableFuture<SynchronizedSessionRunner> startSynchronizedSessionAsync(@Nonnull Subspace lockSubspace, long leaseLengthMillis)
Description copied from interface:FDBDatabaseRunner
Produces a new runner, wrapping this runner, which performs all work in the context of a newSynchronizedSession
.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.
- Specified by:
startSynchronizedSessionAsync
in interfaceFDBDatabaseRunner
- Parameters:
lockSubspace
- the lock for which the session contendsleaseLengthMillis
- length between last access and lease's end time in milliseconds- Returns:
- a future that will return a runner maintaining a new synchronized session
- See Also:
SynchronizedSession
-
startSynchronizedSession
public SynchronizedSessionRunner startSynchronizedSession(@Nonnull Subspace lockSubspace, long leaseLengthMillis)
Description copied from interface:FDBDatabaseRunner
Synchronous/blocking version ofFDBDatabaseRunner.startSynchronizedSessionAsync(Subspace, long)
.- Specified by:
startSynchronizedSession
in interfaceFDBDatabaseRunner
- Parameters:
lockSubspace
- the lock for which the session contendsleaseLengthMillis
- length between last access and lease's end time in milliseconds- Returns:
- a runner maintaining a new synchronized session
-
joinSynchronizedSession
public SynchronizedSessionRunner joinSynchronizedSession(@Nonnull Subspace lockSubspace, @Nonnull UUID sessionId, long leaseLengthMillis)
Description copied from interface:FDBDatabaseRunner
Produces a new runner, wrapping this runner, which performs all work in the context of an existingSynchronizedSession
.- Specified by:
joinSynchronizedSession
in interfaceFDBDatabaseRunner
- Parameters:
lockSubspace
- the lock for which the session contendssessionId
- session IDleaseLengthMillis
- length between last access and lease's end time in milliseconds- Returns:
- a runner maintaining a existing synchronized session
- See Also:
SynchronizedSession
-
-