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_lb: Enrich comments & docstrings #1062

Merged
merged 1 commit into from
Aug 22, 2024

Conversation

wprzytula
Copy link
Collaborator

@wprzytula wprzytula commented Aug 21, 2024

The DefaultPolicy is a complex machinery. In order to grasp it fully, extensive comments are essential.
Some internal functions' names were changed, to make them more better reflect the functions' semantics.

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 self-assigned this Aug 21, 2024
@wprzytula wprzytula added area/documentation Improvements or additions to documentation area/load-balancing labels Aug 21, 2024
Copy link

github-actions bot commented Aug 21, 2024

cargo semver-checks found no API-breaking changes in this PR! 🎉🥳
Checked commit: 17d495e

Copy link
Collaborator

@Lorak-mmk Lorak-mmk left a comment

Choose a reason for hiding this comment

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

Great PR!
I'd add a description for DefaultPolicyTargetComparator because it is definitely not obvious what that is or why it is present.
I propose the following, lmk what you think:

Plan should return unique elements. It is not however obvious what it means because some nodes in the plan may have shards and some may not.
This helper structure defines equality of plan elements.
How the comparison works:
- If at least one of elements is shard-less then compare just nodes.
- If both elements have shards, then compare both nodes and shards.
Why is it implemented this way?
Driver should not attempt to send the same request to the same destination twice.
If plan element doesn't have shard specified, then a random shard will be chosen by the driver.
If the plan also contains the same node but with the shard present, and we randomly chose the same shard for the shard-less element, then we have duplication.
Example: plan is `[(Node1, Some(1)), (Node1, None)]` - if the driver uses the second element and randomly chooses shard 1, then we have a duplication.

On the other hand if the plan has a duplicate node, but with different shards, then we want to use both elements - so we can't just make the list unique by node, and so this struct was created.

scylla/src/transport/load_balancing/default.rs Outdated Show resolved Hide resolved
@wprzytula wprzytula force-pushed the default-lbp-comments branch from d4ecc4d to cb6e7bc Compare August 22, 2024 07:51
@wprzytula
Copy link
Collaborator Author

v1.1: justified why latency awareness is not recommended.

@wprzytula
Copy link
Collaborator Author

I propose the following, lmk what you think:

Wonderful, I'll include it in the PR.

@wprzytula wprzytula force-pushed the default-lbp-comments branch from cb6e7bc to 69358e4 Compare August 22, 2024 08:08
@wprzytula
Copy link
Collaborator Author

v1.2: added DefaultPolicyTargetComparator docstring.

The DefaultPolicy is a complex machinery. In order to grasp it fully,
extensive comments are essential.
Some internal functions' names were changed, to make them more
better reflect the functions' semantics.
@wprzytula wprzytula force-pushed the default-lbp-comments branch from 69358e4 to 17d495e Compare August 22, 2024 08:18
@wprzytula
Copy link
Collaborator Author

v1.2.1: clippy fixes.

@Lorak-mmk Lorak-mmk merged commit da37348 into scylladb:main Aug 22, 2024
11 checks passed
wprzytula pushed a commit to wprzytula/scylla-rust-driver that referenced this pull request Aug 22, 2024
default_lb: Enrich comments & docstrings

(cherry picked from commit da37348)
@wprzytula wprzytula mentioned this pull request Aug 22, 2024
@wprzytula wprzytula deleted the default-lbp-comments branch October 2, 2024 11:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/documentation Improvements or additions to documentation area/load-balancing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants