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

Added new routing option: SingleNodeRoutingInfo::RandomPrimary #194

Merged
merged 4 commits into from
Oct 7, 2024

Conversation

eifrah-aws
Copy link

  • Added new routing option: RandomPrimary.
  • Added new convenience method Route::new_random_primary()
  • Added test cases to check correct routing for commands EVAL, EVALSHA and FCALL when no arguments are provided

This commit is (part of) the fix for this issue: valkey-io/valkey-glide#1569

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Copy link
Member

@shohamazon shohamazon left a comment

Choose a reason for hiding this comment

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

LGTM

redis/src/aio/tokio.rs Outdated Show resolved Hide resolved
redis/src/aio/tokio.rs Outdated Show resolved Hide resolved
@@ -730,6 +727,9 @@ where
SingleNodeRoutingInfo::SpecificNode(route) => {
self.get_connection(&mut connections, route)?
}
SingleNodeRoutingInfo::RandomPrimary => {
Copy link

Choose a reason for hiding this comment

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

Why is there no distinction at line 462 between RandomPrimary and Random, but here they are processed differently? Is there a bug at line 462?

Copy link
Author

Choose a reason for hiding this comment

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

  1. The code for RandomPrimary is correct
  2. The RoutingInfo::SingleNode(SingleNodeRoutingInfo::Random) was not changed (replaced the old code with a call to Route::new_random_primary()

Having said that, there is no bug on that line, however there can be an optimization: for example we could add a check to see whether the cmd is readonly, and in case it does, we could allow "read-from-replica" instead of "SlotAddr::Master`.

If you think that this is correct, we could open a new bug and fix it in a different PR (I prefer not to mix changes in a single PR)


/// Choose a random slot from `0..SLOT_SIZE` (excluding)
fn random_slot() -> u16 {
use rand::Rng;
Copy link

Choose a reason for hiding this comment

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

please put "use" alongside all the others at the top

@eifrah-aws eifrah-aws merged commit 41de670 into amazon-contributing:main Oct 7, 2024
10 checks passed
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.

3 participants