public interface TransactionManager extends AutoCloseable
Modifier and Type | Method and Description |
---|---|
void |
clearTimestampCache()
Clear the timestamp cache.
|
void |
close()
Frees resources used by this TransactionManager, and invokes any callbacks registered to run on close.
|
Cleaner |
getCleaner()
Returns the cleaner used by this transaction manager.
|
long |
getImmutableTimestamp()
Most AtlasDB TransactionManagers will provide
Transaction objects that have less than full
serializability. |
KeyValueService |
getKeyValueService()
Returns the KVS used by this transaction manager.
|
KeyValueServiceStatus |
getKeyValueServiceStatus()
Provides a
KeyValueServiceStatus , indicating the current availability of the key value store. |
com.palantir.lock.LockService |
getLockService()
Returns the lock service used by this transaction manager.
|
LockWatchManager |
getLockWatchManager() |
com.palantir.lock.v2.TimelockService |
getTimelockService()
Returns the timelock service used by this transaction manager.
|
TimelockServiceStatus |
getTimelockServiceStatus()
Provides a
TimelockServiceStatus , indicating the current availability of the timelock service. |
com.palantir.timestamp.TimestampManagementService |
getTimestampManagementService()
The timestamp management service is used by libraries providing additional functionality
around AtlasDB.
|
com.palantir.timestamp.TimestampService |
getTimestampService()
Returns the timestamp service used by this transaction manager.
|
TransactionService |
getTransactionService()
The transaction service is used by libraries providing additional functionality around AtlasDB.
|
long |
getUnreadableTimestamp()
Returns the timestamp that is before any open start timestamps.
|
default boolean |
isInitialized()
Whether this transaction manager has established a connection to the backing store and timestamp/lock services,
and is ready to service transactions.
|
void |
registerClosingCallback(Runnable closingCallback)
Registers a Runnable that will be run after the transaction manager is closed.
|
<T,E extends Exception> |
runTaskReadOnly(TransactionTask<T,E> task)
This will open and run a read-only transaction.
|
<T,E extends Exception> |
runTaskThrowOnConflict(TransactionTask<T,E> task)
runTaskWithRetry(TransactionTask) should be preferred over
runTaskThrowOnConflict(TransactionTask) . |
<T,C extends PreCommitCondition,E extends Exception> |
runTaskWithConditionReadOnly(C condition,
ConditionAwareTransactionTask<T,C,E> task)
This method is basically the same as
runTaskReadOnly(TransactionTask) , but it takes
a PreCommitCondition and checks it for validity before executing reads. |
<T,C extends PreCommitCondition,E extends Exception> |
runTaskWithConditionThrowOnConflict(C condition,
ConditionAwareTransactionTask<T,C,E> task)
This method is basically the same as
runTaskThrowOnConflict(TransactionTask) , but it takes
a PreCommitCondition and checks it immediately before the transaction commits. |
<T,C extends PreCommitCondition,E extends Exception> |
runTaskWithConditionWithRetry(java.util.function.Supplier<C> conditionSupplier,
ConditionAwareTransactionTask<T,C,E> task)
This method is basically the same as
runTaskWithRetry(TransactionTask) , but it will
acquire a PreCommitCondition right before the transaction is created and check it
immediately before the transaction commits. |
default <T,C extends PreCommitCondition,E extends Exception> |
runTaskWithConditionWithRetry(com.google.common.base.Supplier<C> guavaSupplier,
ConditionAwareTransactionTask<T,C,E> task)
Deprecated.
|
<T,E extends Exception> |
runTaskWithLocksThrowOnConflict(Iterable<com.palantir.lock.HeldLocksToken> lockTokens,
LockAwareTransactionTask<T,E> task)
This method is the same as
runTaskThrowOnConflict(TransactionTask) except the created transaction
will not commit successfully if these locks are invalid by the time commit is run. |
<T,E extends Exception> |
runTaskWithLocksWithRetry(Iterable<com.palantir.lock.HeldLocksToken> lockTokens,
java.util.function.Supplier<com.palantir.lock.LockRequest> lockSupplier,
LockAwareTransactionTask<T,E> task)
This method is the same as
runTaskWithLocksWithRetry(Supplier, LockAwareTransactionTask)
but it will also ensure that the existing lock tokens passed are still valid before committing. |
default <T,E extends Exception> |
runTaskWithLocksWithRetry(Iterable<com.palantir.lock.HeldLocksToken> lockTokens,
com.google.common.base.Supplier<com.palantir.lock.LockRequest> guavaSupplier,
LockAwareTransactionTask<T,E> task)
Deprecated.
|
<T,E extends Exception> |
runTaskWithLocksWithRetry(java.util.function.Supplier<com.palantir.lock.LockRequest> lockSupplier,
LockAwareTransactionTask<T,E> task)
This method is basically the same as
runTaskWithRetry(TransactionTask) but it will
acquire locks right before the transaction is created and release them after the task is complete. |
default <T,E extends Exception> |
runTaskWithLocksWithRetry(com.google.common.base.Supplier<com.palantir.lock.LockRequest> guavaSupplier,
LockAwareTransactionTask<T,E> task)
Deprecated.
|
<T,E extends Exception> |
runTaskWithRetry(TransactionTask<T,E> task)
Runs the given
TransactionTask . |
List<OpenTransaction> |
startTransactions(List<? extends PreCommitCondition> condition)
Deprecated.
Similar functionality will exist, but this method is likely to change in the future
|
default boolean isInitialized()
false
, a
NotInitializedException
will be thrown.
This method is used for TransactionManagers that can be initializeppd asynchronously (i.e. those extending
com.palantir.async.initializer.AsyncInitializer
; other TransactionManagers can keep the default
implementation, and return true (they're trivially fully initialized).<T,E extends Exception> T runTaskWithRetry(TransactionTask<T,E> task) throws E extends Exception
TransactionTask
. If the task completes successfully
and does not call Transaction.commit()
or Transaction.abort()
,
Transaction.commit()
is called automatically.
The task is re-run if a conflict is detected (if a TransactionConflictException
is thrown)
If runTaskWithRetry
completes successfully (no exception is thrown)
and the task did not explicitly
abort the transaction, then the transaction was successfully committed.
If an exception is thrown by the TransactionTask
and the task did not call
Transaction.commit()
, then the transaction will be rolled back.
NOTE: If an exception is thrown by Transaction.commit()
, the transaction might have
been committed.
It is important that the TransactionTask
does not modify any of its input state
in any non-idempotent way. If this task gets retried, and if you modified your input, then the
second try might not do the right thing. For example: if you are passed a list of objects
and at the end of the TransactionTask
, you clear the list. If your task gets retried
it will have no work to do, because the list was cleared.
task
- task to runIllegalStateException
- if the transaction manager has been closed.E extends Exception
<T,E extends Exception> T runTaskThrowOnConflict(TransactionTask<T,E> task) throws E extends Exception, TransactionFailedRetriableException
runTaskWithRetry(TransactionTask)
should be preferred over
runTaskThrowOnConflict(TransactionTask)
.
This method should be used unless runTaskWithRetry(TransactionTask)
cannot be used because the arguments
passed are not immutable and will be modified by the transaction so doing automatic retry is unsafe.
Runs the given TransactionTask
. If the task completes successfully
and does not call Transaction.commit()
or Transaction.abort()
,
Transaction.commit()
is called automatically.
If runTaskThrowOnConflict()
completes successfully (no exception is thrown)
and the task did not explicitly
abort the transaction, then the transaction was successfully committed.
If an exception is thrown by the TransactionTask
and the task did not call
Transaction.commit()
, then the transaction will be rolled back.
NOTE: If an exception is thrown by Transaction.commit()
, the transaction might have
been committed.
task
- task to runTransactionConflictException
- if a write-write conflict occursIllegalStateException
- if the transaction manager has been closed.E extends Exception
TransactionFailedRetriableException
<T,E extends Exception> T runTaskReadOnly(TransactionTask<T,E> task) throws E extends Exception
task
- task to runIllegalStateException
- if the transaction manager has been closed.E extends Exception
<T,E extends Exception> T runTaskWithLocksWithRetry(java.util.function.Supplier<com.palantir.lock.LockRequest> lockSupplier, LockAwareTransactionTask<T,E> task) throws E extends Exception, InterruptedException, LockAcquisitionException
runTaskWithRetry(TransactionTask)
but it will
acquire locks right before the transaction is created and release them after the task is complete.
The created transaction will not commit successfully if these locks are invalid by the time commit is run.
lockSupplier
- supplier for the lock requesttask
- task to runLockAcquisitionException
- If the supplied lock request is not successfully acquired.IllegalStateException
- if the transaction manager has been closed.E extends Exception
InterruptedException
@Deprecated default <T,E extends Exception> T runTaskWithLocksWithRetry(com.google.common.base.Supplier<com.palantir.lock.LockRequest> guavaSupplier, LockAwareTransactionTask<T,E> task) throws E extends Exception, InterruptedException, LockAcquisitionException
runTaskWithLocksWithRetry(Supplier, LockAwareTransactionTask)
instead.runTaskWithLocksWithRetry(Supplier, LockAwareTransactionTask)
, but instead
takes in a Guava supplier. This is deprecated in favour of the aforementioned method.E extends Exception
InterruptedException
LockAcquisitionException
runTaskWithLocksWithRetry(Supplier, LockAwareTransactionTask)
<T,E extends Exception> T runTaskWithLocksWithRetry(Iterable<com.palantir.lock.HeldLocksToken> lockTokens, java.util.function.Supplier<com.palantir.lock.LockRequest> lockSupplier, LockAwareTransactionTask<T,E> task) throws E extends Exception, InterruptedException, LockAcquisitionException
runTaskWithLocksWithRetry(Supplier, LockAwareTransactionTask)
but it will also ensure that the existing lock tokens passed are still valid before committing.lockTokens
- lock tokens to acquire while transaction executestask
- task to runLockAcquisitionException
- If the supplied lock request is not successfully acquired.IllegalStateException
- if the transaction manager has been closed.E extends Exception
InterruptedException
@Deprecated default <T,E extends Exception> T runTaskWithLocksWithRetry(Iterable<com.palantir.lock.HeldLocksToken> lockTokens, com.google.common.base.Supplier<com.palantir.lock.LockRequest> guavaSupplier, LockAwareTransactionTask<T,E> task) throws E extends Exception, InterruptedException, LockAcquisitionException
runTaskWithLocksWithRetry(Iterable, Supplier, LockAwareTransactionTask)
instead.runTaskWithLocksWithRetry(Iterable, Supplier, LockAwareTransactionTask)
, but instead
takes in a Guava supplier. This is deprecated in favour of the aforementioned method.E extends Exception
InterruptedException
LockAcquisitionException
runTaskWithLocksWithRetry(Iterable, Supplier, LockAwareTransactionTask)
<T,E extends Exception> T runTaskWithLocksThrowOnConflict(Iterable<com.palantir.lock.HeldLocksToken> lockTokens, LockAwareTransactionTask<T,E> task) throws E extends Exception, TransactionFailedRetriableException
runTaskThrowOnConflict(TransactionTask)
except the created transaction
will not commit successfully if these locks are invalid by the time commit is run.lockTokens
- lock tokens to refresh while transaction executestask
- task to runIllegalStateException
- if the transaction manager has been closed.E extends Exception
TransactionFailedRetriableException
<T,C extends PreCommitCondition,E extends Exception> T runTaskWithConditionWithRetry(java.util.function.Supplier<C> conditionSupplier, ConditionAwareTransactionTask<T,C,E> task) throws E extends Exception
runTaskWithRetry(TransactionTask)
, but it will
acquire a PreCommitCondition
right before the transaction is created and check it
immediately before the transaction commits.
The created transaction will not commit successfully if the check fails.
conditionSupplier
- supplier for the conditiontask
- task to runIllegalStateException
- if the transaction manager has been closed.E extends Exception
@Deprecated default <T,C extends PreCommitCondition,E extends Exception> T runTaskWithConditionWithRetry(com.google.common.base.Supplier<C> guavaSupplier, ConditionAwareTransactionTask<T,C,E> task) throws E extends Exception
runTaskWithConditionWithRetry(Supplier, ConditionAwareTransactionTask)
instead.runTaskWithConditionWithRetry(Supplier, ConditionAwareTransactionTask)
, but instead
takes in a Guava supplier. This is deprecated in favour of the aforementioned method.E extends Exception
runTaskWithConditionWithRetry(Supplier, ConditionAwareTransactionTask)
<T,C extends PreCommitCondition,E extends Exception> T runTaskWithConditionThrowOnConflict(C condition, ConditionAwareTransactionTask<T,C,E> task) throws E extends Exception, TransactionFailedRetriableException
runTaskThrowOnConflict(TransactionTask)
, but it takes
a PreCommitCondition
and checks it immediately before the transaction commits.
The created transaction will not commit successfully if the check fails.
condition
- condition associated with the transactiontask
- task to runIllegalStateException
- if the transaction manager has been closed.E extends Exception
TransactionFailedRetriableException
<T,C extends PreCommitCondition,E extends Exception> T runTaskWithConditionReadOnly(C condition, ConditionAwareTransactionTask<T,C,E> task) throws E extends Exception
runTaskReadOnly(TransactionTask)
, but it takes
a PreCommitCondition
and checks it for validity before executing reads.
The created transaction will fail if the check is no longer valid after fetching the read timestamp.
condition
- condition associated with the transactiontask
- task to runIllegalStateException
- if the transaction manager has been closed.E extends Exception
long getImmutableTimestamp()
Transaction
objects that have less than full
serializability. The most common is snapshot isolation (SI). SI has a start timestamp and a commit timestamp
and an open transaction can only read values that were committed before its start timestamp.
This method will return a timestamp that is before any uncommited/aborted open start timestamps.
Subsequent calls to this method will always be monotonically increasing for a single client.
You are only allowed to open historic/read-only transactions at a timestamp less than or equal to the immutableTimestamp
IllegalStateException
- if the transaction manager has been closed.com.palantir.lock.LockService getLockService()
com.palantir.lock.v2.TimelockService getTimelockService()
LockWatchManager getLockWatchManager()
com.palantir.timestamp.TimestampService getTimestampService()
com.palantir.timestamp.TimestampManagementService getTimestampManagementService()
TransactionService getTransactionService()
Cleaner getCleaner()
KeyValueService getKeyValueService()
KeyValueServiceStatus getKeyValueServiceStatus()
KeyValueServiceStatus
, indicating the current availability of the key value store.
This can be used to infer product health - in the usual, conservative case, products can call
KeyValueServiceStatus.isHealthy()
, which returns true only if all KVS nodes are up.
Products that use AtlasDB only for reads and writes (no schema mutations or deletes, including having sweep and
scrub disabled) can also treat KeyValueServiceStatus.HEALTHY_BUT_NO_SCHEMA_MUTATIONS_OR_DELETES
as
healthy.
This call must be implemented so that it completes synchronously.
TimelockServiceStatus getTimelockServiceStatus()
TimelockServiceStatus
, indicating the current availability of the timelock service.
This can be used to infer product health - in the usual, conservative case, products can call
TimelockServiceStatus.isHealthy()
, which returns true only a healthy connection to timelock
service is established.long getUnreadableTimestamp()
When using the unreadable timestamp for cleanup it is important to leave a sentinel value behind at a negative timestamp so any transaction that is open will fail out if reading a value that is cleaned up instead of just getting back no data. This is needed to ensure that all transactions either produce correct values or fail. It is not an option to return incorrect data.
IllegalStateException
- if the transaction manager has been closed.void clearTimestampCache()
void registerClosingCallback(Runnable closingCallback)
@Deprecated List<OpenTransaction> startTransactions(List<? extends PreCommitCondition> condition)
TransactionTask
ahead of
time, this method allows for a long lived transaction object. For any data read or written to the transaction to
be valid, the transaction must be committed by calling OpenTransaction.finish(TransactionTask)
to
also perform additional cleanup. Note that this does not clean up the pre commit condition associated with that
task. The order of transactions returned corresponds with the pre commit conditions passed in, however there are
no guarantees on the ordering of transactions returned with respect to their start timestamp.void close()
close
in interface AutoCloseable