-
Notifications
You must be signed in to change notification settings - Fork 61
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
Allow clients to request the transactor to retry queries #210
Conversation
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.
The new API makes sense.
Nitpick: seems more concise to call it withRetry
, or withMaxRetry
or allowRetry
instead of withNumRetries
.
@tuliren this should be ready for more thorough review |
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.
@sherifnada, the execution with retry looks good. However, there is a concurrency issue. Transactor should be thread safe. However, currently if multiple threads try to run different queries, they will all be manipulating the same execution context builder, and their configurations will be overridden by each other. I think one solution is to make the transactor immediately returns an execution context whenever asTransaction or withMaxRetry is called. Subsequent configurations will only affect the returned execution context.
Ah, great point. I'll make sure to add tests for that. How would you feel about making ExecutionContext |
I think The interface should still be fluent, because we can still write like this: transactor.withMaxRetry(3).asTransaction().execute(...); To make it even more fluent, ITransactor<IRlDb> retryTransactor = transactor.withMaxRetry(3);
...
retryTransactor.execute(...); |
Closing this beautiful PR in favor of #261 . |
This patch is inspired by #210 - It introduces `ExecutionContext` that allows clients to specify options for every query/update. Currently the two options supported are to run as a transaction (deprecates `queryAsTransaction` and `executeAsTransaction` methods) and set a retry policy on failure. The default behavior remains unchanged, namely, no retries on failure. However, clients can now use the new exponential backoff policy with tunable number of retries and sleep intervals. Users could potentially create their own advanced retry policies by implementing the `ITransactor.RetryPolicy` interface. The policy is executed on failure only after the connection has been invalidated or returned to the pool manager. *Example:* ```java transactor .asTransaction() .allowRetries(new ExponentialBackoffRetryPolicy(numRetries, sleepInterval)) .query(myQuery); ```
@tuliren
This change introduces the
ExecutionContext
concept. It allows a client of anITransactor
to configure settings to be applied on the next execution or query. Today, the only such option is whether to execute the query as a transaction, specified byqueryAsTransaction()
andexecuteAsTransaction()
. However, as the number of options increases (the current PR ultimately aims to add a retry mechanism), it becomes less feasible to add methods that both set the flag and execute the query.ExecutionContext
will be used to allow queries that look like this:or
or even
if they would rather use the default options. In the future, if we want to add more options, we can just add a
.withNewOption()
method to the interface.This would require us to deprecate
queryAsTransaction
andexecuteAsTransaction
since they can be replaced with the new API. What do you think of this interface?TODO: Add retry mechanism. Just sharing the PR to get feedback on the interface.