Skip to content

Async transaction functions #404

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 5 commits into from
Sep 22, 2017

Conversation

lutovich
Copy link
Contributor

Added support for transaction functions that return futures. Cleaned up future helper methods.

This is a test-only implementation of `RetryLogic` interface that
retries up to a specified amount of times. It previously had a
separate implementation which was basically a simplified version
of `ExponentialBackoffRetryLogic`. It is problematic for following
`retryAsync` functionality because implementation will not be that
simple. This commit makes `FixedRetryLogic` extend
`ExponentialBackoffRetryLogic` and override just a single method.
So that they can share complicated retrying code.
This commit makes retry logic able to retry work that executes async
operations and return a `Future`. It's a first step towards supporting
async transaction functions.

Also renamed future combinator methods to better represent their intent.
Via `Session#readTransactionAsync()` and `#writeTransactionAsync()`.
Both accept a single parameter - async function that takes a
transaction and returns a `Response`. When function returns a failed
response or throws exception it will be retried. Retries only happen
on non-fatal & transient errors.

API is not fully complete yet - there is no way to create a `Result`
object so it'll be inconvenient to use. Helpers to create some sort
of "settable" response will come in subsequent commits.
Given work might fail by throwing exception or by returning a failed
future. This commit makes retries gracefully handle exceptions.
Previously retrying code would only log an exception and hang.
Transaction should be marked as failed when queries fail. It was
previously only marked when PULL_ALL failed. This commit makes RUN
handler notify transaction on failure.
Copy link
Contributor

@ali-ince ali-ince left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me.

@@ -240,7 +245,7 @@ public void close()
{
if ( asyncConnectionFuture != null )
{
return asyncConnectionFuture.thenCombine( new Function<AsyncConnection,InternalFuture<Void>>()
return asyncConnectionFuture.thenCompose( new Function<AsyncConnection,InternalFuture<Void>>()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can both asyncConnectionFuture and currentAsyncTransactionFuture be not null?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They can, yeah. I see your point, basically if we close session it will first force-release connection (with RESET message) and then try to close active transaction. Later, however, is not really needed after RESET. I think else if ( currentAsyncTransactionFuture != null ) branch here is not really required. Will think a bit more about this and probably remove it in a separate PR.

@lutovich lutovich merged commit 7eae698 into neo4j:1.5-async Sep 22, 2017
@lutovich lutovich deleted the 1.5-tx-functions-async branch September 22, 2017 12:00
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