Allow clients to request the transactor to retry queries#210
Allow clients to request the transactor to retry queries#210Sherif A. Nada (sherifnada) wants to merge 14 commits into
Conversation
Liren Tu (tuliren)
left a comment
There was a problem hiding this comment.
The new API makes sense.
Nitpick: seems more concise to call it withRetry, or withMaxRetry or allowRetry instead of withNumRetries.
|
Liren Tu (@tuliren) this should be ready for more thorough review |
Liren Tu (tuliren)
left a comment
There was a problem hiding this comment.
Sherif A. Nada (@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); ```
Liren Tu (@tuliren)
This change introduces the
ExecutionContextconcept. It allows a client of anITransactorto 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.ExecutionContextwill 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
queryAsTransactionandexecuteAsTransactionsince 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.