@API(value=STABLE) public class FDBDatabaseFactory extends Object
FDBDatabase
instances, indexed by their cluster file location.Modifier and Type | Field and Description |
---|---|
static int |
DEFAULT_DIRECTORY_CACHE_SIZE
The default number of entries that is to be cached, per database, from
LocatableResolver retrieval requests. |
protected static Function<FDBLatencySource,Long> |
DEFAULT_LATENCY_INJECTOR |
Constructor and Description |
---|
FDBDatabaseFactory() |
Modifier and Type | Method and Description |
---|---|
void |
clear() |
void |
clearLatencyInjector()
Removes any previously installed latency injector.
|
protected Supplier<BlockingInAsyncDetection> |
getBlockingInAsyncDetectionSupplier() |
FDBDatabase |
getDatabase() |
FDBDatabase |
getDatabase(String clusterFile) |
String |
getDatacenterId() |
int |
getDirectoryCacheSize() |
Executor |
getExecutor() |
long |
getInitialDelayMillis()
Gets the delay ceiling (in milliseconds) that will be applied between attempts to
run a transactional database operation.
|
Function<FDBLatencySource,Long> |
getLatencyInjector()
Returns the current latency injector.
|
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.
|
Executor |
getNetworkExecutor() |
long |
getReverseDirectoryMaxMillisPerTransaction() |
int |
getReverseDirectoryRowsPerTransaction() |
long |
getStateRefreshTimeMillis() |
FDBRecordStoreStateCacheFactory |
getStoreStateCacheFactory()
Get the store state cache factory.
|
boolean |
getTrackLastSeenVersion() |
Supplier<Boolean> |
getTransactionIsTracedSupplier() |
protected FDB |
initFDB() |
static FDBDatabaseFactory |
instance() |
boolean |
isUnclosedWarning() |
void |
setBlockingInAsyncDetection(BlockingInAsyncDetection behavior)
Controls if calls to
FDBDatabase#asyncToSync(FDBStoreTimer, FDBStoreTimer.Wait, CompletableFuture)
or FDBRecordContext#asyncToSync(FDBStoreTimer.Wait, CompletableFuture) will attempt to detect
when they are being called from within an asynchronous context and how they should react to this fact
when they are. |
void |
setBlockingInAsyncDetection(Supplier<BlockingInAsyncDetection> supplier)
Provides a supplier that controls if calls to
FDBDatabase#asyncToSync(FDBStoreTimer, FDBStoreTimer.Wait, CompletableFuture)
or FDBRecordContext#asyncToSync(FDBStoreTimer.Wait, CompletableFuture) will attempt to detect
when they are being called from within an asynchronous context and how they should react to this fact
when they are. |
void |
setDatacenterId(String datacenterId) |
void |
setDirectoryCacheSize(int directoryCacheSize)
Sets the number of directory layer entries that will be cached for each database that is produced by the factory.
|
void |
setExecutor(Executor executor) |
void |
setInitialDelayMillis(long initialDelayMillis)
Sets the delay ceiling (in milliseconds) that will be applied between attempts to
run a transactional database operation.
|
void |
setLatencyInjector(Function<FDBLatencySource,Long> latencyInjector)
Provides a function that computes a latency that should be injected into a specific FDB 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 |
setNetworkExecutor(Executor networkExecutor) |
void |
setReverseDirectoryMaxMillisPerTransaction(long millisPerTransaction)
When a reverse directory lookup is performed from a
FDBReverseDirectoryCache and an entry is not found
in the cache and, thus, the directory layer must be scanned to find it, this property determines how many
milliseconds may be spent scanning the cache within the context of a single transaction, before the transaction
is closed and re-opened in order to avoid a past_version . |
void |
setReverseDirectoryRowsPerTransaction(int rowsPerTransaction)
When a reverse directory lookup is performed from a
FDBReverseDirectoryCache and an entry is not found
in the cache and, thus, the directory layer must be scanned to find it, this property determines how many rows
will be scanned within the context of a single transaction, before the transaction is closed and re-opened
in order to avoid a past_version . |
void |
setStateRefreshTimeMillis(long stateRefreshTimeMillis)
Set the refresh time for the cached
LocatableResolver
state. |
void |
setStoreStateCacheFactory(FDBRecordStoreStateCacheFactory storeStateCacheFactory)
Set the store state cache factory.
|
void |
setTrace(String traceDirectory,
String traceLogGroup) |
void |
setTrackLastSeenVersion(boolean trackLastSeenVersion) |
void |
setTransactionIsTracedSupplier(Supplier<Boolean> transactionIsTracedSupplier)
Use transactionIsTracedSupplier to control whether a newly created transaction should be traced or not.
|
void |
setUnclosedWarning(boolean unclosedWarning) |
void |
shutdown() |
protected static final Function<FDBLatencySource,Long> DEFAULT_LATENCY_INJECTOR
public static final int DEFAULT_DIRECTORY_CACHE_SIZE
LocatableResolver
retrieval requests.@Nonnull public static FDBDatabaseFactory instance()
protected FDB initFDB()
public void shutdown()
public void clear()
public boolean isUnclosedWarning()
public void setUnclosedWarning(boolean unclosedWarning)
public int getDirectoryCacheSize()
public boolean getTrackLastSeenVersion()
public String getDatacenterId()
public void setDirectoryCacheSize(int directoryCacheSize)
Each FDBDatabase
maintains a cache of entries that have been retrieved by any instance of a
LocatableResolver
using that database.
Thus, this cache is shared across all resolvers (it should be noted entries in this cache are
segregated by resolver and treated as distinct, ensuring that the value for a directory entry from one
resolver will not be returned to another resolver even if they share the same key).
directoryCacheSize
- the new directory cache sizepublic void setTrackLastSeenVersion(boolean trackLastSeenVersion)
public void setDatacenterId(String datacenterId)
public int getMaxAttempts()
FDBDatabase.run()
and FDBDatabase.runAsync()
to limit the number of
attempts that an operation is retried. The default value is 10.public void setMaxAttempts(int maxAttempts)
FDBDatabase.run()
and FDBDatabase.runAsync()
to limit the number of
attempts that an operation is retried. The default value is 10.maxAttempts
- the maximum number of times to run a transactional database operationIllegalArgumentException
- if a non-positive number is givenpublic long getMaxDelayMillis()
FDBDatabase.run()
and FDBDatabase.runAsync()
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.public void setMaxDelayMillis(long maxDelayMillis)
FDBDatabase.run()
and FDBDatabase.runAsync()
to limit the time spent
between successive attempts at completing a database operation. The default is 1000 so that
there will not be more than 1 second between attempts.maxDelayMillis
- the maximum delay between attempts when retrying operationsIllegalArgumentException
- if the value is negative or less than the minimum delaypublic long getInitialDelayMillis()
FDBDatabase.run()
and FDBDatabase.runAsync()
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.public void setInitialDelayMillis(long initialDelayMillis)
FDBDatabase.run()
and FDBDatabase.runAsync()
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.initialDelayMillis
- the delay ceiling between the first and second attempts at running a database operationIllegalArgumentException
- if the value is negative or greater than the maximum delaypublic void setReverseDirectoryRowsPerTransaction(int rowsPerTransaction)
FDBReverseDirectoryCache
and an entry is not found
in the cache and, thus, the directory layer must be scanned to find it, this property determines how many rows
will be scanned within the context of a single transaction, before the transaction is closed and re-opened
in order to avoid a past_version
.rowsPerTransaction
- the number of rows to scan within the context of a single transactionpublic int getReverseDirectoryRowsPerTransaction()
public void setReverseDirectoryMaxMillisPerTransaction(long millisPerTransaction)
FDBReverseDirectoryCache
and an entry is not found
in the cache and, thus, the directory layer must be scanned to find it, this property determines how many
milliseconds may be spent scanning the cache within the context of a single transaction, before the transaction
is closed and re-opened in order to avoid a past_version
.millisPerTransaction
- the number of miliseconds to spend scanningpublic long getReverseDirectoryMaxMillisPerTransaction()
public void setTransactionIsTracedSupplier(Supplier<Boolean> transactionIsTracedSupplier)
transactionIsTracedSupplier
- a supplier which should return true
for creating TracedTransaction
s or false
for creating normal Transaction
spublic void setBlockingInAsyncDetection(@Nonnull BlockingInAsyncDetection behavior)
FDBDatabase#asyncToSync(FDBStoreTimer, FDBStoreTimer.Wait, CompletableFuture)
or FDBRecordContext#asyncToSync(FDBStoreTimer.Wait, CompletableFuture)
will attempt to detect
when they are being called from within an asynchronous context and how they should react to this fact
when they are. Note that the process of performing this detection is quite expensive, so running with
detection enabled in not recommended for environments other than testing.behavior
- the blocking desired blocking detection behavior
(see BlockingInAsyncDetection
)public void setBlockingInAsyncDetection(@Nonnull Supplier<BlockingInAsyncDetection> supplier)
FDBDatabase#asyncToSync(FDBStoreTimer, FDBStoreTimer.Wait, CompletableFuture)
or FDBRecordContext#asyncToSync(FDBStoreTimer.Wait, CompletableFuture)
will attempt to detect
when they are being called from within an asynchronous context and how they should react to this fact
when they are. Because such detection is quite expensive, it is suggested that it is either
BlockingInAsyncDetection.DISABLED
for anything other than testing environments or that the
supplier randomly chooses a small sample rate in which detection should be enabled.supplier
- a supplier that produces the blocking desired blocking detection behavior
(see BlockingInAsyncDetection
)@Nonnull protected Supplier<BlockingInAsyncDetection> getBlockingInAsyncDetectionSupplier()
public void setLatencyInjector(@Nonnull Function<FDBLatencySource,Long> latencyInjector)
FDBLatencySource
as input and returns the number of milliseconds delay that should
be injected before the operation completes. Returning a value of zero or less indicates that no delay should
be injected.
Latency injection can be useful for simulating environments in which FDB is under stress or in a configuration in which latency is inherent in its operation.
latencyInjector
- a function computing the latency to be injected into an operationpublic Function<FDBLatencySource,Long> getLatencyInjector()
public void clearLatencyInjector()
public long getStateRefreshTimeMillis()
public void setStateRefreshTimeMillis(long stateRefreshTimeMillis)
LocatableResolver
state. Defaults to seconds.stateRefreshTimeMillis
- time to set, in milliseconds@API(value=EXPERIMENTAL) @Nonnull public FDBRecordStoreStateCacheFactory getStoreStateCacheFactory()
FDBDatabase
produced by this FDBDatabaseFactory
will be
initialized with an FDBRecordStoreStateCache
from this cache factory. By default, the factory is a PassThroughRecordStoreStateCacheFactory
which means
that the record store state information is never cached.FDBRecordStoreStateCache
s
used when initializing FDBDatabase
s@API(value=EXPERIMENTAL) public void setStoreStateCacheFactory(@Nonnull FDBRecordStoreStateCacheFactory storeStateCacheFactory)
FDBDatabase
produced by this FDBDatabaseFactory
will be
initialized with an FDBRecordStoreStateCache
from the cache factory provided.storeStateCacheFactory
- a factory of FDBRecordStoreStateCache
s
to use when initializing FDBDatabase
sFDBRecordStoreStateCache
@Nonnull public FDBDatabase getDatabase(@Nullable String clusterFile)
@Nonnull public FDBDatabase getDatabase()