Package com.apple.foundationdb
Interface Tenant
- All Superinterfaces:
AutoCloseable
,ReadTransactionContext
,TransactionContext
A tenant represents a named key-space within a database that can be interacted with
transactionally.
The simplest correct programs using tenants will make use of the methods defined in the
Note:
The simplest correct programs using tenants will make use of the methods defined in the
TransactionContext
interface. When used on a Tenant
these
methods will call Transaction#commit()
after user code has been
executed. These methods will not return successfully until commit()
has
returned successfully.Note:
Tenant
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 this tenant.default CompletableFuture<Boolean>
blobbifyRangeBlocking
(byte[] beginKey, byte[] endKey) RunsblobbifyRangeBlocking(byte[] beginKey, byte[] endKey, Executor e)
on the default executor.blobbifyRangeBlocking
(byte[] beginKey, byte[] endKey, Executor e) Sets a range to be blobbified in this tenant.void
close()
Close theTenant
object and release any associated resources.default Transaction
Creates aTransaction
that operates on thisTenant
.
Note: Java transactions automatically set theTransactionOptions.setUsedDuringCommitProtectionDisable()
option.Creates aTransaction
that operates on thisTenant
with the givenExecutor
for asynchronous callbacks.createTransaction
(Executor e, EventKeeper eventKeeper) Creates aTransaction
that operates on thisTenant
with the givenExecutor
for 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<Long>
getId()
RunsgetId()
on the default executor.Returns the tenant ID of this tenant.byte[]
getName()
Returns the name of thisTenant
.default 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 this tenant.default 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 specified key range of this tenant, at the specified version.default <T> T
read
(Function<? super ReadTransaction, T> retryable) Runs a read-only transactional function against thisTenant
with retry logic.<T> T
read
(Function<? super ReadTransaction, T> retryable, Executor e) Runs a read-only transactional function against thisTenant
with retry logic.default <T> CompletableFuture<T>
readAsync
(Function<? super ReadTransaction, ? extends CompletableFuture<T>> retryable) Runs a read-only transactional function against thisTenant
with retry logic.<T> CompletableFuture<T>
readAsync
(Function<? super ReadTransaction, ? extends CompletableFuture<T>> retryable, Executor e) Runs a read-only transactional function against thisTenant
with retry logic.default <T> T
run
(Function<? super Transaction, T> retryable) Runs a transactional function against thisTenant
with retry logic.<T> T
run
(Function<? super Transaction, T> retryable, Executor e) Runs a transactional function against thisTenant
with retry logic.default <T> CompletableFuture<T>
runAsync
(Function<? super Transaction, ? extends CompletableFuture<T>> retryable) Runs a transactional function against thisTenant
with retry logic.<T> CompletableFuture<T>
runAsync
(Function<? super Transaction, ? extends CompletableFuture<T>> retryable, Executor e) Runs a transactional function against thisTenant
with 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 this tenant.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 in this tenant.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
-
createTransaction
Creates aTransaction
that operates on thisTenant
.
Note: Java transactions automatically set theTransactionOptions.setUsedDuringCommitProtectionDisable()
option. This is because the Java bindings disallow use ofTransaction
objects afterTransaction.onError(java.lang.Throwable)
is called.- Returns:
- a newly created
Transaction
that reads from and writes to thisTenant
.
-
createTransaction
Creates aTransaction
that operates on thisTenant
with the givenExecutor
for asynchronous callbacks.- Parameters:
e
- theExecutor
to use when executing asynchronous callbacks.- Returns:
- a newly created
Transaction
that reads from and writes to thisTenant
.
-
createTransaction
Creates aTransaction
that operates on thisTenant
with the givenExecutor
for asynchronous callbacks.- Parameters:
e
- theExecutor
to use when executing asynchronous callbacks.eventKeeper
- theEventKeeper
to use when tracking instrumented calls for the transaction.- Returns:
- a newly created
Transaction
that reads from and writes to thisTenant
.
-
getName
byte[] getName()Returns the name of thisTenant
.- Returns:
- the name of this
Tenant
as a byte string.
-
read
Runs a read-only transactional function against thisTenant
with retry logic.apply(ReadTransaction)
will be called on the suppliedFunction
until a non-retryable FDBException (or anyThrowable
other than anFDBException
) is thrown. This call is blocking -- this method will not return until theFunction
has been called and completed without error.- Specified by:
read
in interfaceReadTransactionContext
- Type Parameters:
T
- the return type ofretryable
- Parameters:
retryable
- the block of logic to execute in aTransaction
against this tenant- Returns:
- the result of the last run of
retryable
-
read
Runs a read-only transactional function against thisTenant
with retry logic. Use this formulation ofread(Function)
if one wants to set a customExecutor
for the transaction when run.- Type Parameters:
T
- the return type ofretryable
- Parameters:
retryable
- the block of logic to execute in aTransaction
against this tenante
- theExecutor
to 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 thisTenant
with retry logic.apply(ReadTransaction)
will be called on the suppliedFunction
until a non-retryable FDBException (or anyThrowable
other than anFDBException
) is thrown. This call is non-blocking -- this method will return immediately and with aCompletableFuture
that will be set when theFunction
has been called and completed without error.
Any errors encountered executingretryable
, or received from the database, will be set on the returnedCompletableFuture
.- Specified by:
readAsync
in interfaceReadTransactionContext
- Type Parameters:
T
- the return type ofretryable
- Parameters:
retryable
- the block of logic to execute in aReadTransaction
against this tenant- Returns:
- a
CompletableFuture
that 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 thisTenant
with retry logic. Use this version ofreadAsync(Function)
if one wants to set a customExecutor
for the transaction when run.- Type Parameters:
T
- the return type ofretryable
- Parameters:
retryable
- the block of logic to execute in aReadTransaction
against this tenante
- theExecutor
to use for asynchronous callbacks- Returns:
- a
CompletableFuture
that will be set to the value returned by the last call toretryable
- See Also:
-
run
Runs a transactional function against thisTenant
with retry logic.apply(Transaction)
will be called on the suppliedFunction
until a non-retryable FDBException (or anyThrowable
other 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:
run
in interfaceTransactionContext
- Type Parameters:
T
- the return type ofretryable
- Parameters:
retryable
- the block of logic to execute in aTransaction
against this tenant- Returns:
- the result of the last run of
retryable
-
run
Runs a transactional function against thisTenant
with retry logic. Use this formulation ofrun(Function)
if one would like to set a customExecutor
for the transaction when run.- Type Parameters:
T
- the return type ofretryable
- Parameters:
retryable
- the block of logic to execute in aTransaction
against this tenante
- theExecutor
to 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 thisTenant
with retry logic.apply(Transaction)
will be called on the suppliedFunction
until a non-retryable FDBException (or anyThrowable
other than anFDBException
) is thrown orcommit()
, when called afterapply()
, returns success. This call is non-blocking -- this method will return immediately and with aCompletableFuture
that 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:
runAsync
in interfaceTransactionContext
- Type Parameters:
T
- the return type ofretryable
- Parameters:
retryable
- the block of logic to execute in aTransaction
against this tenant- Returns:
- a
CompletableFuture
that 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 thisTenant
with retry logic. Use this formulation of the non-blockingrunAsync(Function)
if one wants to set a customExecutor
for the transaction when run.- Type Parameters:
T
- the return type ofretryable
- Parameters:
retryable
- the block of logic to execute in aTransaction
against this tenante
- theExecutor
to use for asynchronous callbacks- Returns:
- a
CompletableFuture
that will be set to the value returned by the last call toretryable
- See Also:
-
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 specified key range of this tenant, 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
- theExecutor
to 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
- theExecutor
to 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 this tenant. Must be a completely unblobbified range.- Parameters:
beginKey
- start of the key rangeendKey
- end of the key rangee
- theExecutor
to use for asynchronous callbacks- Returns:
- if the recording of the range was successful
-
blobbifyRangeBlocking
RunsblobbifyRangeBlocking(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 this tenant. Must be a completely unblobbified range.- Parameters:
beginKey
- start of the key rangeendKey
- end of the key rangee
- theExecutor
to 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 this tenant. The range must be aligned to known blob ranges.- Parameters:
beginKey
- start of the key rangeendKey
- end of the key rangee
- theExecutor
to 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 this tenant. There may be more if result.size() == rangeLimit.- Parameters:
beginKey
- start of the key rangeendKey
- end of the key rangerangeLimit
- batch sizee
- theExecutor
to 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 in this tenant.- Parameters:
beginKey
- start of the key rangeendKey
- end of the key rangeversion
- version to read ate
- the executor- 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
- theExecutor
to use for asynchronous callbacks- Returns:
- a future with a boolean for success or failure
-
getId
RunsgetId()
on the default executor.- Returns:
- a future with the tenant ID
-
getId
Returns the tenant ID of this tenant.- Parameters:
e
- theExecutor
to use for asynchronous callbacks- Returns:
- a future with the tenant ID
-
close
void close()Close theTenant
object and release any associated resources. This must be called at least once after theTenant
object 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:
close
in interfaceAutoCloseable
-