Skip to content

Commit

Permalink
Order masters by amount of slots before picking failover nodes (#19)
Browse files Browse the repository at this point in the history
  • Loading branch information
chris-cmsoft authored May 27, 2022
1 parent a784f63 commit 030ba86
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions internal/redis/cluster_nodes.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,13 @@ func (c *ClusterNodes) EnsureClusterReplicationRatio(ctx context.Context, cluste
// todo select keepable masters as masters with most slots attached
var keepMasters []*Node
var removeMasters []*Node

// We want to sort the masters by the amount of slots they have.
// That way when we select removable masters, they are most likely to be empty from slots
sort.Slice(masters, func(i, j int) bool {
return len(masters[i].NodeAttributes.slots) > len(masters[j].NodeAttributes.slots)
})

// We have too many masters and need to fail over some
keepMasters = masters[:cluster.Spec.Masters]
removeMasters = masters[cluster.Spec.Masters:]
Expand Down

0 comments on commit 030ba86

Please sign in to comment.