-
-
Notifications
You must be signed in to change notification settings - Fork 54
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
Make retry strategies cluster aware #329
Make retry strategies cluster aware #329
Conversation
We're getting the following error on the CI, not sure what it means:
|
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.
Left a first round of comments, there are a couple of major things to hash out:
- We don't want to break support for retry strategies on non-cluster connections
- We don't want to change the signature of
RetryStrategy
callbacks
lib/xandra.ex
Outdated
RetryStrategy.run_with_retrying(options, fn -> | ||
execute_without_retrying(conn, query, params, options) | ||
end) |
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.
Mh, am I wrong or we are removing retrying altogether from non-cluster connections? If so, then we shouldn't do that 🙃
Let's also avoid renaming functions to do_
prefixes, since it's a long-gone convention in Elixir.
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.
Ah I thought that when elevating retries to cluster level, we both meant that we don't want Xandra
level retries anymore. Is the reason why we don't let the client implement a helper function but to have a retry strategy is to not checkout the Xandra
connection pool multiple times? Because that would be the only logical reason to have a retry logic, since everything else can be done with more context with a helper function on the client side.
Otherwise, if we want to have the retry logic on Xandra level as well, maybe we want to have a different callback than Xandra.RetryStrategy
? Since the retry/3
function is expected to return a Xandra
connection pool, we can't really have the same callback for Xandra.Cluster
and Xandra
.
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.
Is the reason why we don't let the client implement a helper function but to have a retry strategy is to not checkout the Xandra connection pool multiple times? Because that would be the only logical reason to have a retry logic
I disagree, and I think calling this "the only logical reason" can come off a bit arrogant 😉 Logical reasons to have retry logics are:
- We would introduce a breaking change by removing them. This might not be a good reason for having introduced them, but alas, it's what we have!
- It's easier to reuse retry logic modules provided by Xandra or other people. The intention initially was to provide other built-in retry strategies, such as retrying with lower consistency requirements and stuff like that. That never really happened, but still 🙃
Otherwise, if we want to have the retry logic on Xandra level as well, maybe we want to have a different callback than
Xandra.RetryStrategy
?
As I said in other comments, we can use the options for all of this. We can inject the node to use in the options, and use that in Xandra.Cluster.<...>
functions if present.
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.
Sorry, didn't mean to be that harsh :) I implemented the requested changes now, with the RetryStrategy
callback unchanged as requested. I still feel that the focus should be more on cluster side with this functionality rather than Xandra
level though, as it is limited by the functionality of the RetryStrategy
callback about what you can and cannot do.
Change spec notation Co-authored-by: Andrea Leopardi <[email protected]>
@whatyouhide I think this is ready for another pass. I couldn't understand the aformentioned
error in the CI though. |
lib/xandra/retry_strategy.ex
Outdated
{conn, options} when is_pid(conn) -> | ||
{conn, options} | ||
|
||
{:random, options} -> |
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.
Why did we add :random
here? Can't a retry strategy implement it by itself?
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.
This is only for internal use, not exposed to the outside. It's basically a fallback for when a :target_connection
doesn't exist.
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.
Not sure whether I understood "implement it by itself"
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.
I mean, a retry strategy can implement choosing a random node if :target_connection
doesn't exist, right? Unless we have a strong reason, let's just remove this.
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.
Yes, exactly, we pop the :target_connection
before calling retry_strategy.retry
and then do
|> Keyword.put_new(:target_connection, :random)
after calling retry_strategy.retry
, so that if it is empty, we'll be assigning it a random node. This is to have a mechanism to initially select the first node from load balancing strategy.
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.
@whatyouhide But using nil
instead of :random
also works, as in d54ab5b, if that's what you meant
Co-authored-by: Andrea Leopardi <[email protected]>
Co-authored-by: Andrea Leopardi <[email protected]>
Co-authored-by: Andrea Leopardi <[email protected]>
Co-authored-by: Andrea Leopardi <[email protected]>
@whatyouhide Done. Are we sure that we're supporting Elixir 1.11, since the CI fails and we get the following warning:
|
Yes we don't care about that, we can run Dialyxir only on the latest Elixir, but Xandra itself must support 1.11+ for now. Dialyxir is a dev/test dep, not a prod dep. |
Replaced by #335. |
Closes #320