Interface AsyncTransactionManager (6.71.0)

public interface AsyncTransactionManager extends AutoCloseable

An interface for managing the life cycle of a read write transaction including all its retries. See 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 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. See Also: DatabaseClient#transactionManagerAsync(TransactionOption...)

Implements

AutoCloseable

Methods

beginAsync()

public abstract 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, see #resetForRetryAsync().

Returns
Type Description
AsyncTransactionManager.TransactionContextFuture

close()

public abstract 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.

closeAsync()

public abstract 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 returned ApiFuture is done when the transaction (if any) has been rolled back.

Returns
Type Description
ApiFuture<Void>

getCommitResponse()

public abstract ApiFuture<CommitResponse> getCommitResponse()

Returns the CommitResponse of this transaction.

Returns
Type Description
ApiFuture<CommitResponse>

getState()

public abstract TransactionManager.TransactionState getState()

Returns the state of the transaction.

Returns
Type Description
TransactionManager.TransactionState

resetForRetryAsync()

public abstract AsyncTransactionManager.TransactionContextFuture resetForRetryAsync()

Creates a new transaction for retry. This should only be called if the previous transaction failed with ABORTED. In all other cases, this will throw an IllegalStateException. Users should backoff before calling this method. Backoff delay is specified by SpannerException#getRetryDelayInMillis() on the SpannerException throw by the previous commit call.

Returns
Type Description
AsyncTransactionManager.TransactionContextFuture

rollbackAsync()

public abstract ApiFuture<Void> rollbackAsync()

Rolls back the currently active transaction. In most cases there should be no need to call this explicitly since #close() would automatically roll back any active transaction.

Returns
Type Description
ApiFuture<Void>