MCPcopy
hub / github.com/redis/go-redis / slotShardPickerSlaveNode

Method slotShardPickerSlaveNode

osscluster.go:1023–1044  ·  view source on GitHub ↗
(slot int, shardPicker routing.ShardPicker)

Source from the content-addressed store, hash-verified

1021}
1022
1023func (c *clusterState) slotShardPickerSlaveNode(slot int, shardPicker routing.ShardPicker) (*clusterNode, error) {
1024 nodes := c.slotNodes(slot)
1025 if len(nodes) == 0 {
1026 return c.nodes.Random()
1027 }
1028
1029 // nodes[0] is master, nodes[1:] are slaves
1030 // First, try all slave nodes for this slot using ShardPicker order
1031 slaves := nodes[1:]
1032 if len(slaves) > 0 {
1033 for i := 0; i < len(slaves); i++ {
1034 idx := shardPicker.Next(len(slaves))
1035 slave := slaves[idx]
1036 if !slave.Failing() && !slave.Loading() {
1037 return slave, nil
1038 }
1039 }
1040 }
1041
1042 // All slaves are failing or loading - return master
1043 return nodes[0], nil
1044}
1045
1046func (c *clusterState) slotNodes(slot int) []*clusterNode {
1047 i := sort.Search(len(c.slots), func(i int) bool {

Callers 1

slotReadOnlyNodeMethod · 0.80

Calls 5

slotNodesMethod · 0.95
FailingMethod · 0.80
LoadingMethod · 0.80
NextMethod · 0.65
RandomMethod · 0.45

Tested by

no test coverage detected