Add transaction with retries API #219
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
3 main commits of this PR:
Introduce transaction with retries API
This commit adds two new API functions:
Session#readTransaction()
Session#writeTransaction()
Both take a single function as input. This function takes a single argument of type
Transaction
and returns a promise. It can be used to perform regular async operations like query execution. Introduced functions will commit/rollback transaction depending on the returned promise, so user code does not need to callTransaction#commit()
explicitly. They also perform retries if given transaction fails with network errors (ServiceUnavaliable
orSessionExpired
) or with transient errors (DeadlockDetected
, etc.). Retries are one with exponential backoff with initial delay of 1 second and total cap of 30 seconds.These API functions are useful to hide tolerable network problems and transient errors for both single and causal cluster deployments.
Commit also fixes a problem in transaction error handling where
_onError
executed a rollback but did not properly wait for the returned promise to complete.TransactionExecutor checks if tx is active
To make sure it does not try to commit transaction that has already been committed or rolled back.
This commit also adds a new API function
Transaction#isOpen()
which checks internal transaction state and returnstrue
when transaction has not been committed/rolled back andfalse
otherwise.Make maximum transaction retry time configurable
Commit makes driver aware of a new config property
maxTransactionRetryTime
to tune amount of time transactions executed viaSession#readTransaction(function(Transaction))
andSession#writeTransaction(function(Transaction))
can be retried. It also adds JSDoc forconnectionPoolSize
property.Fixes #207