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

default policy: Rack awareness without token awareness #777

Merged

Conversation

wprzytula
Copy link
Collaborator

@wprzytula wprzytula commented Jul 30, 2023

Until now, the default policy respected rack preference only when it came to replicas.
Considering non-token-aware queries (e.g. unprepared statements), they would never prioritize the preferred rack.

Now, local rack nodes are always preferred before other nodes, both in pick() and in fallback().
Existing tests adjusted for new behaviour.

The PR contains breaking changes, as it slightly changes signature of ReplicaSet::choose_filtered() (note the reference added).

Pre-review checklist

  • I have split my patch into logically separate commits.
  • All commit messages clearly explain what they change and why.
  • I added relevant tests for new features and bug fixes.
  • All commits compile, pass static checks and pass test.
  • PR description sums up the changes and reasons why they should be introduced.
  • [ ] I have provided docstrings for the public items that I want to introduce.
  • I have adjusted the documentation in ./docs/source/.
  • [ ] I added appropriate Fixes: annotations to PR description.

@wprzytula wprzytula added load-balancing API-breaking This might introduce incompatible API changes labels Jul 30, 2023
@wprzytula wprzytula force-pushed the rack-awareness-without-token-awareness branch 2 times, most recently from 9d08507 to fb225fc Compare July 31, 2023 07:03
@wprzytula wprzytula marked this pull request as ready for review July 31, 2023 07:27
Copy link
Collaborator

@piodul piodul left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@havaker please take a look as well

@@ -170,8 +170,22 @@ or refrain from preferring datacenters (which may ban all other datacenters, if
// some alive local node.
// If there was no preferred datacenter specified, all nodes are treated as local.
let nodes = self.preferred_node_set(cluster);
let picked = Self::pick_node(nodes, &self.pick_predicate);
if let Some(alive_local) = picked {

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The token_with_strategy.is_some() and token_with_strategy_is_none() paths look very similar. Perhaps we could unify them somehow? Not necessarily here, just food for thought for future improvements.

scylla/src/transport/load_balancing/default.rs Outdated Show resolved Hide resolved
docs/source/load-balancing/default-policy.md Outdated Show resolved Hide resolved
@wprzytula wprzytula force-pushed the rack-awareness-without-token-awareness branch from fb225fc to 5bf2e55 Compare August 2, 2023 07:42
The predicate is more convenient for use in this form, because methods
such as `filter()` expect predicates to take values by reference.
It makes implementation in the following commit more elegant.
However, it unfortunately brings a breaking change.
Until now, the default policy respected rack preference only when it
came to replicas. Considering non-token-aware queries (e.g. unprepared
statements), they would never prioritize the preferred rack.
Now, local rack nodes are always preferred before other nodes, both in
`pick()` and in `fallback()`. Tests and docs are adjusted for this
behaviour. One new test is added for the case when no token is provided
and a rack is preferred.
As rack awareness now prefers not only local-rack replicas over other
replicas, but also local-rack nodes over other nodes, the name of
`ReplicaLocationPreference` is changed to `NodeLocationPreference` and
similarly for `ReplicaLocationCriteria`.
@wprzytula wprzytula force-pushed the rack-awareness-without-token-awareness branch from 5bf2e55 to 0fca0db Compare August 2, 2023 07:52
@wprzytula
Copy link
Collaborator Author

v2:

  • renamed ReplicaLocation[Criteria|Location] to Node...
  • provided a test for rack awareness when no token is known
  • rebased on main

@piodul piodul merged commit 4efc84d into scylladb:main Aug 3, 2023
9 checks passed
@wprzytula wprzytula deleted the rack-awareness-without-token-awareness branch August 3, 2023 17:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API-breaking This might introduce incompatible API changes load-balancing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants