Interface AsyncTransactionManager
- All Superinterfaces:
AutoCloseable
- All Known Implementing Classes:
DelayedAsyncTransactionManager
TransactionContext for a description of transaction semantics.
At any point in time there can be at most one active transaction in this manager. When that
transaction is committed, if it fails with an ABORTED error, calling resetForRetryAsync() would create a new AsyncTransactionManager.TransactionContextFuture. The newly created
transaction would use the same session thus increasing its lock priority. If the transaction is
committed successfully, or is rolled back or commit fails with any error other than
ABORTED, the manager is considered complete and no further transactions are allowed to be
created in it.
Every AsyncTransactionManager should either be committed or rolled back. Failure to do
so can cause resources to be leaked and deadlocks. Easiest way to guarantee this is by calling
close() in a finally block.
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic interfaceEach step in a transaction chain is defined by anAsyncTransactionManager.AsyncTransactionFunction.static interfaceAsyncTransactionManager.AsyncTransactionStepis returned byAsyncTransactionManager.TransactionContextFuture.then(AsyncTransactionFunction, Executor)andAsyncTransactionManager.AsyncTransactionStep.then(AsyncTransactionFunction, Executor)and allows transaction steps that should be executed serially to be chained together.static interfaceApiFuturethat returns the commitTimestampof a Cloud Spanner transaction that is executed using anAsyncTransactionManager.static interfaceApiFuturethat returns aTransactionContextand that supports chaining of multipleAsyncTransactionManager.TransactionContextFutures to form a transaction. -
Method Summary
Modifier and TypeMethodDescriptionCreates a new read write transaction.beginAsync(AbortedException exception) Initializes a new read-write transaction that is a retry of a previously aborted transaction.voidclose()Closes the manager.com.google.api.core.ApiFuture<Void>Closes the transaction manager.com.google.api.core.ApiFuture<CommitResponse>Returns theCommitResponseof this transaction.getState()Returns the state of the transaction.Creates a new transaction for retry.com.google.api.core.ApiFuture<Void>Rolls back the currently active transaction.
-
Method Details
-
beginAsync
AsyncTransactionManager.TransactionContextFuture beginAsync()Creates a new read write transaction. This must be called before doing any other operation and can only be called once. To create a new transaction for subsequent retries, seeresetForRetryAsync(). -
beginAsync
Initializes a new read-write transaction that is a retry of a previously aborted transaction. This method must be called before performing any operations, and it can only be invoked once per transaction lifecycle.This method should only be used when multiplexed sessions are enabled to create a retry for a previously aborted transaction. This method can be used instead of
resetForRetryAsync()to create a retry. Using this method orresetForRetryAsync()will have the same effect. You must pass in theAbortedExceptionfrom the previous attempt to preserve the transaction's priority.For regular sessions, this behaves the same as
beginAsync(). -
rollbackAsync
com.google.api.core.ApiFuture<Void> rollbackAsync()Rolls back the currently active transaction. In most cases there should be no need to call this explicitly sinceclose()would automatically roll back any active transaction. -
resetForRetryAsync
AsyncTransactionManager.TransactionContextFuture resetForRetryAsync()Creates a new transaction for retry. This should only be called if the previous transaction failed withABORTED. In all other cases, this will throw anIllegalStateException. Users should backoff before calling this method. Backoff delay is specified bySpannerException.getRetryDelayInMillis()on theSpannerExceptionthrow by the previous commit call. -
getState
TransactionManager.TransactionState getState()Returns the state of the transaction. -
getCommitResponse
com.google.api.core.ApiFuture<CommitResponse> getCommitResponse()Returns theCommitResponseof this transaction. -
close
void close()Closes the manager. If there is an active transaction, it will be rolled back. Underlying session will be released back to the session pool.- Specified by:
closein interfaceAutoCloseable
-
closeAsync
com.google.api.core.ApiFuture<Void> closeAsync()Closes the transaction manager. If there is an active transaction, it will be rolled back. The underlying session will be released back to the session pool. The returnedApiFutureis done when the transaction (if any) has been rolled back.
-