Skip to content

Add transaction with retries API #219

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Mar 16, 2017
Merged

Conversation

lutovich
Copy link
Contributor

@lutovich lutovich commented Mar 15, 2017

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 call Transaction#commit() explicitly. They also perform retries if given transaction fails with network errors (ServiceUnavaliable or SessionExpired) 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 returns true when transaction has not been committed/rolled back and false otherwise.

  • Make maximum transaction retry time configurable
    Commit makes driver aware of a new config property maxTransactionRetryTime to tune amount of time transactions executed via Session#readTransaction(function(Transaction)) and Session#writeTransaction(function(Transaction)) can be retried. It also adds JSDoc for connectionPoolSize property.

Fixes #207

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 call `Transaction#commit()` explicitly. They also perform
retries if given transaction fails with network errors
(`ServiceUnavaliable` or `SessionExpired`) 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.
This is more convenient and interactive then printing dots.
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 returns `true` when transaction has not
been committed/rolled back and `false` otherwise.
Commit makes driver aware of a new config property `maxTransactionRetryTime`
to tune amount of time transactions executed via
`Session#readTransaction(function(Transaction))` and
`Session#writeTransaction(function(Transaction))` can be retried.

It also adds JSDoc for `connectionPoolSize` property.
@lutovich lutovich force-pushed the 1.2-read-write-tx branch from 9d64b63 to 90dac27 Compare March 15, 2017 19:00
@oskarhane
Copy link
Member

Really nice! lgtm

To make `maxTransactionRetryTime` config have unique tags.
Renamed private function `Transaction#_runDiscardAll()` to
`Transaction#_runPullAll()` because it actually executes `PULL_ALL`
and not `DISCARD_ALL`.
@lutovich lutovich merged commit 7e6c5ff into neo4j:1.2 Mar 16, 2017
@lutovich lutovich deleted the 1.2-read-write-tx branch March 16, 2017 11:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants