@API(value=INTERNAL) public class FDBDatabaseRunnerImpl extends Object implements FDBDatabaseRunner
FDBDatabaseRunner
.FDBDatabaseRunner.RunnerClosed
Constructor and Description |
---|
FDBDatabaseRunnerImpl(FDBDatabase database) |
FDBDatabaseRunnerImpl(FDBDatabase database,
FDBStoreTimer timer,
Map<String,String> mdcContext) |
FDBDatabaseRunnerImpl(FDBDatabase database,
FDBStoreTimer timer,
Map<String,String> mdcContext,
FDBDatabase.WeakReadSemantics weakReadSemantics) |
Modifier and Type | Method and Description |
---|---|
<T> T |
asyncToSync(StoreTimer.Wait event,
CompletableFuture<T> async) |
void |
close()
Close 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.
|
Map<String,String> |
getMdcContext()
Get the logging context used in record contexts opened by this runner.
|
long |
getMinDelayMillis()
Gets the minimum delay (in milliseconds) that will be applied between attempts to
run a transactional database operation.
|
FDBTransactionPriority |
getPriority()
Get the priority of transactions opened by this runner.
|
FDBStoreTimer |
getTimer()
Get the timer used in record contexts opened by this runner.
|
FDBDatabase.WeakReadSemantics |
getWeakReadSemantics()
Get the read semantics used in record contexts opened by this runner.
|
SynchronizedSessionRunner |
joinSynchronizedSession(Subspace lockSubspace,
UUID sessionId,
long leaseLengthMillis)
Produces a new runner, wrapping this runner, which performs all work in the context of an existing
SynchronizedSession . |
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 |
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.
|
void |
setPriority(FDBTransactionPriority priority)
Set the priority of transactions opened by this runner.
|
void |
setTimer(FDBStoreTimer timer)
Set the timer used in record contexts opened by this runner.
|
void |
setWeakReadSemantics(FDBDatabase.WeakReadSemantics weakReadSemantics)
Set the read semantics used in record contexts opened by this runner.
|
SynchronizedSessionRunner |
startSynchronizedSession(Subspace lockSubspace,
long leaseLengthMillis)
Synchronous/blocking version of
FDBDatabaseRunner.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 new
SynchronizedSession . |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
run, runAsync, runAsync
@API(value=INTERNAL) public FDBDatabaseRunnerImpl(@Nonnull FDBDatabase database, @Nullable FDBStoreTimer timer, @Nullable Map<String,String> mdcContext, @Nullable FDBDatabase.WeakReadSemantics weakReadSemantics)
@API(value=INTERNAL) public FDBDatabaseRunnerImpl(@Nonnull FDBDatabase database, @Nullable FDBStoreTimer timer, @Nullable Map<String,String> mdcContext)
@API(value=INTERNAL) public FDBDatabaseRunnerImpl(@Nonnull FDBDatabase database)
@Nonnull public FDBDatabase getDatabase()
FDBDatabaseRunner
getDatabase
in interface FDBDatabaseRunner
public Executor getExecutor()
FDBDatabaseRunner
FDBDatabaseRunner.runAsync(java.util.function.Function<? super com.apple.foundationdb.record.provider.foundationdb.FDBRecordContext, java.util.concurrent.CompletableFuture<? extends T>>)
.getExecutor
in interface FDBDatabaseRunner
@Nullable public FDBStoreTimer getTimer()
FDBDatabaseRunner
getTimer
in interface FDBDatabaseRunner
public void setTimer(@Nullable FDBStoreTimer timer)
FDBDatabaseRunner
setTimer
in interface FDBDatabaseRunner
timer
- timer to useFDBDatabase.openContext(Map,FDBStoreTimer)
@Nullable public Map<String,String> getMdcContext()
FDBDatabaseRunner
getMdcContext
in interface FDBDatabaseRunner
public void setMdcContext(@Nullable Map<String,String> mdcContext)
FDBDatabaseRunner
mdcContext
.setMdcContext
in interface FDBDatabaseRunner
mdcContext
- the logging context to useFDBDatabase.openContext(Map,FDBStoreTimer)
@Nullable public FDBDatabase.WeakReadSemantics getWeakReadSemantics()
FDBDatabaseRunner
getWeakReadSemantics
in interface FDBDatabaseRunner
public void setWeakReadSemantics(@Nullable FDBDatabase.WeakReadSemantics weakReadSemantics)
FDBDatabaseRunner
setWeakReadSemantics
in interface FDBDatabaseRunner
weakReadSemantics
- allowable staleness parameters if caching read versionsFDBDatabase.openContext(Map,FDBStoreTimer,FDBDatabase.WeakReadSemantics)
@Nonnull public FDBTransactionPriority getPriority()
FDBDatabaseRunner
getPriority
in interface FDBDatabaseRunner
FDBRecordContext.getPriority()
public void setPriority(@Nonnull FDBTransactionPriority priority)
FDBDatabaseRunner
setPriority
in interface FDBDatabaseRunner
priority
- the priority of transactions by this runnerFDBRecordContext.getPriority()
public int getMaxAttempts()
FDBDatabaseRunner
FDBDatabaseRunner.run(java.util.function.Function<? super com.apple.foundationdb.record.provider.foundationdb.FDBRecordContext, ? extends T>)
and FDBDatabaseRunner.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.getMaxAttempts
in interface FDBDatabaseRunner
public void setMaxAttempts(int maxAttempts)
FDBDatabaseRunner
FDBDatabaseRunner.run(java.util.function.Function<? super com.apple.foundationdb.record.provider.foundationdb.FDBRecordContext, ? extends T>)
and FDBDatabaseRunner.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.setMaxAttempts
in interface FDBDatabaseRunner
maxAttempts
- the maximum number of times to run a transactional database operationpublic long getMinDelayMillis()
FDBDatabaseRunner
FDBDatabaseRunner.run(java.util.function.Function<? super com.apple.foundationdb.record.provider.foundationdb.FDBRecordContext, ? extends T>)
and FDBDatabaseRunner.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.getMinDelayMillis
in interface FDBDatabaseRunner
public long getMaxDelayMillis()
FDBDatabaseRunner
FDBDatabaseRunner.run(java.util.function.Function<? super com.apple.foundationdb.record.provider.foundationdb.FDBRecordContext, ? extends T>)
and FDBDatabaseRunner.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.getMaxDelayMillis
in interface FDBDatabaseRunner
public void setMaxDelayMillis(long maxDelayMillis)
FDBDatabaseRunner
FDBDatabaseRunner.run(java.util.function.Function<? super com.apple.foundationdb.record.provider.foundationdb.FDBRecordContext, ? extends T>)
and FDBDatabaseRunner.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.setMaxDelayMillis
in interface FDBDatabaseRunner
maxDelayMillis
- the maximum delay between attempts when retrying operationspublic long getInitialDelayMillis()
FDBDatabaseRunner
FDBDatabaseRunner.run(java.util.function.Function<? super com.apple.foundationdb.record.provider.foundationdb.FDBRecordContext, ? extends T>)
and FDBDatabaseRunner.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.getInitialDelayMillis
in interface FDBDatabaseRunner
public void setInitialDelayMillis(long initialDelayMillis)
FDBDatabaseRunner
FDBDatabaseRunner.run(java.util.function.Function<? super com.apple.foundationdb.record.provider.foundationdb.FDBRecordContext, ? extends T>)
and FDBDatabaseRunner.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.setInitialDelayMillis
in interface FDBDatabaseRunner
initialDelayMillis
- the delay ceiling between the first and second attempts at running a database operation@Nonnull public FDBRecordContext openContext()
FDBDatabaseRunner
openContext
in interface FDBDatabaseRunner
FDBDatabase.openContext(Map,FDBStoreTimer,FDBDatabase.WeakReadSemantics)
@API(value=EXPERIMENTAL) public <T> T run(@Nonnull Function<? super FDBRecordContext,? extends T> retriable, @Nullable List<Object> additionalLogMessageKeyValues)
FDBDatabaseRunner
FDBDatabaseRunner.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.run
in interface FDBDatabaseRunner
T
- return type of function to runretriable
- the database operation to run transactionallyadditionalLogMessageKeyValues
- additional key/value pairs to be included in logsFDBDatabaseRunner.runAsync(Function)
@Nonnull @API(value=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)
FDBDatabaseRunner
runAsync
in interface FDBDatabaseRunner
T
- return type of function to runretriable
- 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 from
runAsync
or an exception to be checked whether retriable
should be retried.additionalLogMessageKeyValues
- additional key/value pairs to be included in logsretriable
after successful run and commitFDBDatabaseRunner.run(Function)
@Nullable public <T> T asyncToSync(StoreTimer.Wait event, @Nonnull CompletableFuture<T> async)
asyncToSync
in interface FDBDatabaseRunner
public void close()
FDBDatabaseRunner
runAsync
close
in interface FDBDatabaseRunner
close
in interface AutoCloseable
public CompletableFuture<SynchronizedSessionRunner> startSynchronizedSessionAsync(@Nonnull Subspace lockSubspace, long leaseLengthMillis)
FDBDatabaseRunner
SynchronizedSession
.
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.
startSynchronizedSessionAsync
in interface FDBDatabaseRunner
lockSubspace
- the lock for which the session contendsleaseLengthMillis
- length between last access and lease's end time in millisecondsSynchronizedSession
public SynchronizedSessionRunner startSynchronizedSession(@Nonnull Subspace lockSubspace, long leaseLengthMillis)
FDBDatabaseRunner
FDBDatabaseRunner.startSynchronizedSessionAsync(Subspace, long)
.startSynchronizedSession
in interface FDBDatabaseRunner
lockSubspace
- the lock for which the session contendsleaseLengthMillis
- length between last access and lease's end time in millisecondspublic SynchronizedSessionRunner joinSynchronizedSession(@Nonnull Subspace lockSubspace, @Nonnull UUID sessionId, long leaseLengthMillis)
FDBDatabaseRunner
SynchronizedSession
.joinSynchronizedSession
in interface FDBDatabaseRunner
lockSubspace
- the lock for which the session contendssessionId
- session IDleaseLengthMillis
- length between last access and lease's end time in millisecondsSynchronizedSession