Skip to content
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

Closed

Conversation

harunzengin
Copy link
Contributor

@harunzengin harunzengin commented Sep 1, 2023

Closes #320

@harunzengin
Copy link
Contributor Author

We're getting the following error on the CI, not sure what it means:

1) test all the datatypes are documented in the guides (DataTypesTest)
Error:      test/integration/datatypes_test.exs:31
     ** (UndefinedFunctionError) function Mix.Project.project_file/0 is undefined or private. Did you mean one of:
     
           * in_project/3
           * in_project/4
     
     code: Mix.Project.project_file()
     stacktrace:
       (mix 1.11.4) Mix.Project.project_file()
       test/integration/datatypes_test.exs:33: (test)

Copy link
Owner

@whatyouhide whatyouhide left a 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:

  1. We don't want to break support for retry strategies on non-cluster connections
  2. We don't want to change the signature of RetryStrategy callbacks

lib/xandra.ex Outdated
Comment on lines 1223 to 1225
RetryStrategy.run_with_retrying(options, fn ->
execute_without_retrying(conn, query, params, options)
end)
Copy link
Owner

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.

Copy link
Contributor Author

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.

Copy link
Owner

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:

  1. 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!
  2. 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.

Copy link
Contributor Author

@harunzengin harunzengin Sep 5, 2023

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.

lib/xandra/cluster.ex Outdated Show resolved Hide resolved
lib/xandra/cluster/pool.ex Outdated Show resolved Hide resolved
lib/xandra/cluster/pool.ex Outdated Show resolved Hide resolved
lib/xandra/cluster/pool.ex Outdated Show resolved Hide resolved
lib/xandra/cluster/pool.ex Outdated Show resolved Hide resolved
test/xandra/cluster_test.exs Outdated Show resolved Hide resolved
test/xandra/cluster/pool_test.exs Outdated Show resolved Hide resolved
lib/xandra/retry_strategy.ex Outdated Show resolved Hide resolved
@harunzengin
Copy link
Contributor Author

@whatyouhide I think this is ready for another pass. I couldn't understand the aformentioned

** (UndefinedFunctionError) function Mix.Project.project_file/0 is undefined or private. Did you mean one of:

error in the CI though.

@whatyouhide whatyouhide changed the title Cluster aware retry strategy Make retry strategies cluster aware Sep 12, 2023
lib/xandra/cluster/pool.ex Outdated Show resolved Hide resolved
lib/xandra/retry_strategy.ex Outdated Show resolved Hide resolved
lib/xandra/retry_strategy.ex Outdated Show resolved Hide resolved
lib/xandra/retry_strategy.ex Outdated Show resolved Hide resolved
lib/xandra/retry_strategy.ex Outdated Show resolved Hide resolved
{conn, options} when is_pid(conn) ->
{conn, options}

{:random, options} ->
Copy link
Owner

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?

Copy link
Contributor Author

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.

Copy link
Contributor Author

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"

Copy link
Owner

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.

Copy link
Contributor Author

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.retryand 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.

Copy link
Contributor Author

@harunzengin harunzengin Sep 27, 2023

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

@harunzengin
Copy link
Contributor Author

@whatyouhide Done. Are we sure that we're supporting Elixir 1.11, since the CI fails and we get the following warning:

warning: the dependency :dialyxir requires Elixir ">= 1.12.0" but you are running on v1.11.4

@whatyouhide
Copy link
Owner

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.

@whatyouhide
Copy link
Owner

Replaced by #335.

@whatyouhide whatyouhide closed this Oct 4, 2023
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.

Cluster-aware retry strategy
2 participants