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

refactor: distribute slots to replicas #398

Merged
merged 2 commits into from
Nov 1, 2023

Conversation

proost
Copy link
Contributor

@proost proost commented Oct 31, 2023

resolve: #397

randomly pick one of replicas for a slot

@codecov-commenter
Copy link

codecov-commenter commented Oct 31, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (425a16a) 97.51% compared to head (29c152a) 97.51%.

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #398   +/-   ##
=======================================
  Coverage   97.51%   97.51%           
=======================================
  Files          76       76           
  Lines       30866    30868    +2     
=======================================
+ Hits        30098    30100    +2     
  Misses        641      641           
  Partials      127      127           
Files Coverage Δ
cluster.go 98.65% <100.00%> (+<0.01%) ⬆️

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

cluster.go Outdated
for _, slot := range g.slots {
for i := slot[0]; i <= slot[1]; i++ {
var cc conn
if c.opt.ReplicaOnly && nodesCount > 1 {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Hi @proost,

Your change looks good to me generally. However, I am concerned about this repeatness of the if statement inside each slot range.

I wonder whether it would be better if we moved the check to the outer block:

	for master, g := range groups {
		if c.opt.ReplicaOnly && len(g.nodes) > 1 {
			for _, slot := range g.slots {
				for i := slot[0]; i <= slot[1]; i++ {
					slots[i] = conns[g.nodes[1+rand.Intn(len(g.nodes)-1)]]
				}
			}
		} else {
			for _, slot := range g.slots {
				for i := slot[0]; i <= slot[1]; i++ {
					slots[i] = conns[master]
				}
			}
		}
	}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay. I change it. 29c152a

Copy link
Collaborator

Choose a reason for hiding this comment

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

Hi @proost, thank you for your contribution! It looks great.

@proost proost requested a review from rueian November 1, 2023 07:30
@rueian rueian merged commit 0242d4e into redis:main Nov 1, 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.

[Feature Request] Randomly pick one of replicas when ReplicaOnly is true
3 participants