-
Notifications
You must be signed in to change notification settings - Fork 155
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
Conversation
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.
There was a problem hiding this 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>>() |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
Added support for transaction functions that return futures. Cleaned up future helper methods.