Package com.apple.foundationdb
Interface Database
- All Superinterfaces:
AutoCloseable,ReadTransactionContext,TransactionContext
A mutable, lexicographically ordered mapping from binary keys to binary values.
The simplest correct programs using FoundationDB will make use of the methods defined in the
Note:
Transactions are used to manipulate data within a single
Database -- multiple, concurrent
Transactions on a Database enforce ACID properties.The simplest correct programs using FoundationDB will make use of the methods defined in the
TransactionContext interface. When used on a Database these
methods will call Transaction#commit() after user code has been
executed. These methods will not return successfully until commit() has
returned successfully.Note:
Database objects must be closed when no longer
in use in order to free any associated resources.-
Method Summary
Modifier and TypeMethodDescriptiondefault CompletableFuture<Boolean>blobbifyRange(byte[] beginKey, byte[] endKey) RunsblobbifyRange(byte[] beginKey, byte[] endKey)on the default executor.blobbifyRange(byte[] beginKey, byte[] endKey, Executor e) Sets a range to be blobbified in the database.default CompletableFuture<Boolean>blobbifyRangeBlocking(byte[] beginKey, byte[] endKey) RunsblobbifyRange(byte[] beginKey, byte[] endKey, Executor e)on the default executor.blobbifyRangeBlocking(byte[] beginKey, byte[] endKey, Executor e) Sets a range to be blobbified in the database.voidclose()Close theDatabaseobject and release any associated resources.default TransactionCreates aTransactionthat operates on thisDatabase.Creates aTransactionthat operates on thisDatabasewith the givenExecutorfor asynchronous callbacks.createTransaction(Executor e, EventKeeper eventKeeper) Creates aTransactionthat operates on thisDatabasewith the givenExecutorfor asynchronous callbacks.default CompletableFuture<Boolean>flushBlobRange(byte[] beginKey, byte[] endKey, boolean compact) RunsflushBlobRange(byte[] beginKey, byte[] endKey, boolean compact, long version, Executor e)on the default executor.default CompletableFuture<Boolean>flushBlobRange(byte[] beginKey, byte[] endKey, boolean compact, long version) RunsflushBlobRange(byte[] beginKey, byte[] endKey, boolean compact, long version, Executor e)on the default executor.flushBlobRange(byte[] beginKey, byte[] endKey, boolean compact, long version, Executor e) Checks if a blob range is blobbified.default CompletableFuture<byte[]>Returns client-side status informationCompletableFuture<byte[]>Returns client-side status informationdoubleReturns a value which indicates the saturation of the client
Note: By default, this value is updated every seconddefault CompletableFuture<KeyRangeArrayResult>listBlobbifiedRanges(byte[] beginKey, byte[] endKey, int rangeLimit) RunslistBlobbifiedRanges(byte[] beginKey, byte[] endKey, int rangeLimit)on the default executor.listBlobbifiedRanges(byte[] beginKey, byte[] endKey, int rangeLimit, Executor e) Lists blobbified ranges in the database.default TenantopenTenant(byte[] tenantName) Opens an existing tenant to be used for running transactions.
Note: opening a tenant does not check its existence in the cluster.openTenant(byte[] tenantName, Executor e) Opens an existing tenant to be used for running transactions.openTenant(byte[] tenantName, Executor e, EventKeeper eventKeeper) Opens an existing tenant to be used for running transactions.openTenant(Tuple tenantName) Opens an existing tenant to be used for running transactions.openTenant(Tuple tenantName, Executor e) Opens an existing tenant to be used for running transactions.openTenant(Tuple tenantName, Executor e, EventKeeper eventKeeper) Opens an existing tenant to be used for running transactions.options()Returns a set of options that can be set on aDatabasedefault CompletableFuture<byte[]>purgeBlobGranules(byte[] beginKey, byte[] endKey, boolean force) RunspurgeBlobGranules(byte[] beginKey, byte[] endKey, boolean force)on the default executor.default CompletableFuture<byte[]>purgeBlobGranules(byte[] beginKey, byte[] endKey, long purgeVersion, boolean force) RunspurgeBlobGranules(byte[] beginKey, byte[] endKey, long purgeVersion, boolean force)on the default executor.CompletableFuture<byte[]>purgeBlobGranules(byte[] beginKey, byte[] endKey, long purgeVersion, boolean force, Executor e) Queues a purge of blob granules for the specified key range, at the specified version.default <T> Tread(Function<? super ReadTransaction, T> retryable) Runs a read-only transactional function against thisDatabasewith retry logic.<T> Tread(Function<? super ReadTransaction, T> retryable, Executor e) Runs a read-only transactional function against thisDatabasewith retry logic.default <T> CompletableFuture<T>readAsync(Function<? super ReadTransaction, ? extends CompletableFuture<T>> retryable) Runs a read-only transactional function against thisDatabasewith retry logic.<T> CompletableFuture<T>readAsync(Function<? super ReadTransaction, ? extends CompletableFuture<T>> retryable, Executor e) Runs a read-only transactional function against thisDatabasewith retry logic.default <T> Trun(Function<? super Transaction, T> retryable) Runs a transactional function against thisDatabasewith retry logic.<T> Trun(Function<? super Transaction, T> retryable, Executor e) Runs a transactional function against thisDatabasewith retry logic.default <T> CompletableFuture<T>runAsync(Function<? super Transaction, ? extends CompletableFuture<T>> retryable) Runs a transactional function against thisDatabasewith retry logic.<T> CompletableFuture<T>runAsync(Function<? super Transaction, ? extends CompletableFuture<T>> retryable, Executor e) Runs a transactional function against thisDatabasewith retry logic.default CompletableFuture<Boolean>unblobbifyRange(byte[] beginKey, byte[] endKey) RunsunblobbifyRange(byte[] beginKey, byte[] endKey)on the default executor.unblobbifyRange(byte[] beginKey, byte[] endKey, Executor e) Unsets a blobbified range in the database.default CompletableFuture<Long>verifyBlobRange(byte[] beginKey, byte[] endKey) RunsverifyBlobRange(byte[] beginKey, byte[] endKey)on the default executor.default CompletableFuture<Long>verifyBlobRange(byte[] beginKey, byte[] endKey, long version) RunsverifyBlobRange(byte[] beginKey, byte[] endKey, long version)on the default executor.verifyBlobRange(byte[] beginKey, byte[] endKey, long version, Executor e) Checks if a blob range is blobbified.default CompletableFuture<Void>waitPurgeGranulesComplete(byte[] purgeKey) RunswaitPurgeGranulesComplete(byte[] purgeKey)on the default executor.waitPurgeGranulesComplete(byte[] purgeKey, Executor e) Wait for a previous call to purgeBlobGranules to complete.Methods inherited from interface com.apple.foundationdb.ReadTransactionContext
getExecutor
-
Method Details
-
openTenant
Opens an existing tenant to be used for running transactions.
Note: opening a tenant does not check its existence in the cluster. If the tenant does not exist, attempts to read or write data with it will fail.- Parameters:
tenantName- The name of the tenant to open.- Returns:
- a
Tenantthat can be used to create transactions that will operate in the tenant's key-space.
-
openTenant
Opens an existing tenant to be used for running transactions. This is a convenience method that generates the tenant name by packing aTuple.
Note: opening a tenant does not check its existence in the cluster. If the tenant does not exist, attempts to read or write data with it will fail.- Parameters:
tenantName- The name of the tenant to open, as a Tuple.- Returns:
- a
Tenantthat can be used to create transactions that will operate in the tenant's key-space.
-
openTenant
Opens an existing tenant to be used for running transactions. -
openTenant
Opens an existing tenant to be used for running transactions. This is a convenience method that generates the tenant name by packing aTuple. -
openTenant
Opens an existing tenant to be used for running transactions.- Parameters:
tenantName- The name of the tenant to open.e- theExecutorto use when executing asynchronous callbacks.eventKeeper- theEventKeeperto use when tracking instrumented calls for the tenant's transactions.- Returns:
- a
Tenantthat can be used to create transactions that will operate in the tenant's key-space.
-
openTenant
Opens an existing tenant to be used for running transactions. This is a convenience method that generates the tenant name by packing aTuple.- Parameters:
tenantName- The name of the tenant to open, as a Tuple.e- theExecutorto use when executing asynchronous callbacks.eventKeeper- theEventKeeperto use when tracking instrumented calls for the tenant's transactions.- Returns:
- a
Tenantthat can be used to create transactions that will operate in the tenant's key-space.
-
createTransaction
Creates aTransactionthat operates on thisDatabase. Creating a transaction in this way does not associate it with aTenant, and as a result the transaction will operate on the entire key-space for the database.
Note: Java transactions automatically set theTransactionOptions.setUsedDuringCommitProtectionDisable()option. This is because the Java bindings disallow use ofTransactionobjects afterTransaction.onError(java.lang.Throwable)is called.
Note: Transactions created directly on aDatabaseobject cannot be used in a cluster that requires tenant-based access. To run transactions in those clusters, you must first open a tenant withopenTenant(byte[]).- Returns:
- a newly created
Transactionthat reads from and writes to thisDatabase.
-
createTransaction
Creates aTransactionthat operates on thisDatabasewith the givenExecutorfor asynchronous callbacks.- Parameters:
e- theExecutorto use when executing asynchronous callbacks for the database- Returns:
- a newly created
Transactionthat reads from and writes to thisDatabase.
-
createTransaction
Creates aTransactionthat operates on thisDatabasewith the givenExecutorfor asynchronous callbacks.- Parameters:
e- theExecutorto use when executing asynchronous callbacks for the databaseeventKeeper- theEventKeeperto use when tracking instrumented calls for the transaction.- Returns:
- a newly created
Transactionthat reads from and writes to thisDatabase.
-
options
DatabaseOptions options()Returns a set of options that can be set on aDatabase- Returns:
- a set of database-specific options affecting this
Database
-
getMainThreadBusyness
double getMainThreadBusyness()Returns a value which indicates the saturation of the client
Note: By default, this value is updated every second- Returns:
- a value where 0 indicates that the client is idle and 1 (or larger) indicates that the client is saturated.
-
purgeBlobGranules
RunspurgeBlobGranules(byte[] beginKey, byte[] endKey, boolean force)on the default executor.- Parameters:
beginKey- start of the key rangeendKey- end of the key rangeforce- if true delete all data, if not keep data >= purgeVersion- Returns:
- the key to watch for purge complete
-
purgeBlobGranules
default CompletableFuture<byte[]> purgeBlobGranules(byte[] beginKey, byte[] endKey, long purgeVersion, boolean force) RunspurgeBlobGranules(byte[] beginKey, byte[] endKey, long purgeVersion, boolean force)on the default executor.- Parameters:
beginKey- start of the key rangeendKey- end of the key rangepurgeVersion- version to purge atforce- if true delete all data, if not keep data >= purgeVersion- Returns:
- the key to watch for purge complete
-
purgeBlobGranules
CompletableFuture<byte[]> purgeBlobGranules(byte[] beginKey, byte[] endKey, long purgeVersion, boolean force, Executor e) Queues a purge of blob granules for the specified key range, at the specified version.- Parameters:
beginKey- start of the key rangeendKey- end of the key rangepurgeVersion- version to purge atforce- if true delete all data, if not keep data >= purgeVersione- theExecutorto use for asynchronous callbacks- Returns:
- the key to watch for purge complete
-
waitPurgeGranulesComplete
RunswaitPurgeGranulesComplete(byte[] purgeKey)on the default executor.- Parameters:
purgeKey- key to watch- Returns:
- void
-
waitPurgeGranulesComplete
Wait for a previous call to purgeBlobGranules to complete.- Parameters:
purgeKey- key to watche- theExecutorto use for asynchronous callbacks- Returns:
- void
-
blobbifyRange
RunsblobbifyRange(byte[] beginKey, byte[] endKey)on the default executor.- Parameters:
beginKey- start of the key rangeendKey- end of the key range- Returns:
- if the recording of the range was successful
-
blobbifyRange
Sets a range to be blobbified in the database. Must be a completely unblobbified range.- Parameters:
beginKey- start of the key rangeendKey- end of the key rangee- theExecutorto use for asynchronous callbacks- Returns:
- if the recording of the range was successful
-
blobbifyRangeBlocking
RunsblobbifyRange(byte[] beginKey, byte[] endKey, Executor e)on the default executor.- Parameters:
beginKey- start of the key rangeendKey- end of the key range- Returns:
- if the recording of the range was successful
-
blobbifyRangeBlocking
Sets a range to be blobbified in the database. Must be a completely unblobbified range.- Parameters:
beginKey- start of the key rangeendKey- end of the key rangee- theExecutorto use for asynchronous callbacks- Returns:
- if the recording of the range was successful
-
unblobbifyRange
RunsunblobbifyRange(byte[] beginKey, byte[] endKey)on the default executor.- Parameters:
beginKey- start of the key rangeendKey- end of the key range- Returns:
- if the recording of the range was successful
-
unblobbifyRange
Unsets a blobbified range in the database. The range must be aligned to known blob ranges.- Parameters:
beginKey- start of the key rangeendKey- end of the key rangee- theExecutorto use for asynchronous callbacks- Returns:
- if the recording of the range was successful
-
listBlobbifiedRanges
default CompletableFuture<KeyRangeArrayResult> listBlobbifiedRanges(byte[] beginKey, byte[] endKey, int rangeLimit) RunslistBlobbifiedRanges(byte[] beginKey, byte[] endKey, int rangeLimit)on the default executor.- Parameters:
beginKey- start of the key rangeendKey- end of the key rangerangeLimit- batch size- Returns:
- a future with the list of blobbified ranges: [lastLessThan(beginKey), firstGreaterThanOrEqual(endKey)]
-
listBlobbifiedRanges
CompletableFuture<KeyRangeArrayResult> listBlobbifiedRanges(byte[] beginKey, byte[] endKey, int rangeLimit, Executor e) Lists blobbified ranges in the database. There may be more if result.size() == rangeLimit.- Parameters:
beginKey- start of the key rangeendKey- end of the key rangerangeLimit- batch sizee- theExecutorto use for asynchronous callbacks- Returns:
- a future with the list of blobbified ranges: [lastLessThan(beginKey), firstGreaterThanOrEqual(endKey)]
-
verifyBlobRange
RunsverifyBlobRange(byte[] beginKey, byte[] endKey)on the default executor.- Parameters:
beginKey- start of the key rangeendKey- end of the key range- Returns:
- a future with the version of the last blob granule.
-
verifyBlobRange
RunsverifyBlobRange(byte[] beginKey, byte[] endKey, long version)on the default executor.- Parameters:
beginKey- start of the key rangeendKey- end of the key rangeversion- version to read at- Returns:
- a future with the version of the last blob granule.
-
verifyBlobRange
Checks if a blob range is blobbified.- Parameters:
beginKey- start of the key rangeendKey- end of the key rangeversion- version to read ate- theExecutorto use for asynchronous callbacks- Returns:
- a future with the version of the last blob granule.
-
flushBlobRange
RunsflushBlobRange(byte[] beginKey, byte[] endKey, boolean compact, long version, Executor e)on the default executor.- Parameters:
beginKey- start of the key rangeendKey- end of the key rangecompact- force compact or just flush- Returns:
- a future with a boolean for success or failure
-
flushBlobRange
default CompletableFuture<Boolean> flushBlobRange(byte[] beginKey, byte[] endKey, boolean compact, long version) RunsflushBlobRange(byte[] beginKey, byte[] endKey, boolean compact, long version, Executor e)on the default executor.- Parameters:
beginKey- start of the key rangeendKey- end of the key rangecompact- force compact or just flushversion- version to flush at- Returns:
- a future with a boolean for success or failure
-
flushBlobRange
CompletableFuture<Boolean> flushBlobRange(byte[] beginKey, byte[] endKey, boolean compact, long version, Executor e) Checks if a blob range is blobbified.- Parameters:
beginKey- start of the key rangeendKey- end of the key rangecompact- force compact or just flushversion- version to flush ate- theExecutorto use for asynchronous callbacks- Returns:
- a future with a boolean for success or failure
-
read
Runs a read-only transactional function against thisDatabasewith retry logic.apply(ReadTransaction)will be called on the suppliedFunctionuntil a non-retryableFDBException(or anyThrowableother than anFDBException) is thrown. This call is blocking -- this method will not return until theFunctionhas been called and completed without error.- Specified by:
readin interfaceReadTransactionContext- Type Parameters:
T- the return type ofretryable- Parameters:
retryable- the block of logic to execute in aTransactionagainst this database- Returns:
- the result of the last run of
retryable
-
read
Runs a read-only transactional function against thisDatabasewith retry logic. Use this formulation ofread(Function)if one wants to set a customExecutorfor the transaction when run.- Type Parameters:
T- the return type ofretryable- Parameters:
retryable- the block of logic to execute in aTransactionagainst this databasee- theExecutorto use for asynchronous callbacks- Returns:
- the result of the last run of
retryable - See Also:
-
readAsync
default <T> CompletableFuture<T> readAsync(Function<? super ReadTransaction, ? extends CompletableFuture<T>> retryable) Runs a read-only transactional function against thisDatabasewith retry logic.apply(ReadTransaction)will be called on the suppliedFunctionuntil a non-retryableFDBException(or anyThrowableother than anFDBException) is thrown. This call is non-blocking -- this method will return immediately and with aCompletableFuturethat will be set when theFunctionhas been called and completed without error.
Any errors encountered executingretryable, or received from the database, will be set on the returnedCompletableFuture.- Specified by:
readAsyncin interfaceReadTransactionContext- Type Parameters:
T- the return type ofretryable- Parameters:
retryable- the block of logic to execute in aReadTransactionagainst this database- Returns:
- a
CompletableFuturethat will be set to the value returned by the last call toretryable
-
readAsync
<T> CompletableFuture<T> readAsync(Function<? super ReadTransaction, ? extends CompletableFuture<T>> retryable, Executor e) Runs a read-only transactional function against thisDatabasewith retry logic. Use this version ofreadAsync(Function)if one wants to set a customExecutorfor the transaction when run.- Type Parameters:
T- the return type ofretryable- Parameters:
retryable- the block of logic to execute in aReadTransactionagainst this databasee- theExecutorto use for asynchronous callbacks- Returns:
- a
CompletableFuturethat will be set to the value returned by the last call toretryable - See Also:
-
run
Runs a transactional function against thisDatabasewith retry logic.apply(Transaction)will be called on the suppliedFunctionuntil a non-retryableFDBException(or anyThrowableother than anFDBException) is thrown orcommit(), when called afterapply(), returns success. This call is blocking -- this method will not return untilcommit()has been called and returned success.
As with other client/server databases, in some failure scenarios a client may be unable to determine whether a transaction succeeded. In these cases, your transaction may be executed twice. For more information about how to reason about these situations see the FounationDB Developer Guide- Specified by:
runin interfaceTransactionContext- Type Parameters:
T- the return type ofretryable- Parameters:
retryable- the block of logic to execute in aTransactionagainst this database- Returns:
- the result of the last run of
retryable
-
run
Runs a transactional function against thisDatabasewith retry logic. Use this formulation ofrun(Function)if one would like to set a customExecutorfor the transaction when run.- Type Parameters:
T- the return type ofretryable- Parameters:
retryable- the block of logic to execute in aTransactionagainst this databasee- theExecutorto use for asynchronous callbacks- Returns:
- the result of the last run of
retryable
-
runAsync
default <T> CompletableFuture<T> runAsync(Function<? super Transaction, ? extends CompletableFuture<T>> retryable) Runs a transactional function against thisDatabasewith retry logic.apply(Transaction)will be called on the suppliedFunctionuntil a non-retryableFDBException(or anyThrowableother than anFDBException) is thrown orcommit(), when called afterapply(), returns success. This call is non-blocking -- this method will return immediately and with aCompletableFuturethat will be set whencommit()has been called and returned success.
As with other client/server databases, in some failure scenarios a client may be unable to determine whether a transaction succeeded. In these cases, your transaction may be executed twice. For more information about how to reason about these situations see the FounationDB Developer Guide
Any errors encountered executingretryable, or received from the database, will be set on the returnedCompletableFuture.- Specified by:
runAsyncin interfaceTransactionContext- Type Parameters:
T- the return type ofretryable- Parameters:
retryable- the block of logic to execute in aTransactionagainst this database- Returns:
- a
CompletableFuturethat will be set to the value returned by the last call toretryable
-
runAsync
<T> CompletableFuture<T> runAsync(Function<? super Transaction, ? extends CompletableFuture<T>> retryable, Executor e) Runs a transactional function against thisDatabasewith retry logic. Use this formulation of the non-blockingrunAsync(Function)if one wants to set a customExecutorfor the transaction when run.- Type Parameters:
T- the return type ofretryable- Parameters:
retryable- the block of logic to execute in aTransactionagainst this databasee- theExecutorto use for asynchronous callbacks- Returns:
- a
CompletableFuturethat will be set to the value returned by the last call toretryable - See Also:
-
close
void close()Close theDatabaseobject and release any associated resources. This must be called at least once after theDatabaseobject is no longer in use. This can be called multiple times, but care should be taken that it is not in use in another thread at the time of the call.- Specified by:
closein interfaceAutoCloseable
-
getClientStatus
Returns client-side status information- Returns:
- a
CompletableFuturecontaining a JSON string with client status health information
-
getClientStatus
Returns client-side status information- Parameters:
e- theExecutorto use for asynchronous callbacks- Returns:
- a
CompletableFuturecontaining a JSON string with client status health information
-