Skip to content

feat: added support for route randomly flag #894

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

ayush-sarda
Copy link

No description provided.

// Enabling it alongside client side caching can result in higher memory usage due to
// individual cache store against each connection.
// Only works when SendToReplicas return true
RouteRandomly bool
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think we don't need the new RouteRandomly option. We can just always invoke ReplicaSelector to pick a replica when necessary.

Copy link
Author

Choose a reason for hiding this comment

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

The idea I had in my mind was, user should be in control if they want to route traffic across all the nodes (including master). If this flag is turned off then distribution will happen as it was happening earlier.

Copy link
Author

Choose a reason for hiding this comment

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

If you want to make it default, then we can go with that approach. But we'd still need some flag to specify if master node should be included in distribution or not.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Users already have the control with ReplicaSelector. They can return an out of range index, then we can send the command to the primary.

rIndex := c.opt.ReplicaSelector(uint16(i), g.nodes[1:])
if rIndex >= 0 && rIndex < n {
rslots[i] = conns[g.nodes[1+rIndex].Addr].conn
var replicas nodes
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
var replicas nodes
replicas := make(nodes, n)

rslots[i] = conns[g.nodes[1+rIndex].Addr].conn
var replicas nodes
if c.opt.RouteRandomly {
for _, node := range g.nodes {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
for _, node := range g.nodes {
for _, node := range g.nodes[1:] { // exclude master node

Copy link
Author

Choose a reason for hiding this comment

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

Shouldn't we include master node for reads as well? That way we can route the traffic evenly across all the nodes for a given group.

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.

2 participants