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

Function configureClusterTopology

osscluster_test.go:111–210  ·  view source on GitHub ↗
(ctx context.Context, scenario *clusterScenario)

Source from the content-addressed store, hash-verified

109}
110
111func configureClusterTopology(ctx context.Context, scenario *clusterScenario) error {
112 allowErrs := []string{
113 "ERR Slot 0 is already busy",
114 "ERR Slot 5461 is already busy",
115 "ERR Slot 10923 is already busy",
116 "ERR Slot 16384 is already busy",
117 }
118
119 err := collectNodeInformation(ctx, scenario)
120 if err != nil {
121 return err
122 }
123
124 // Meet cluster nodes.
125 for _, client := range scenario.clients {
126 err := client.ClusterMeet(ctx, "127.0.0.1", scenario.ports[0]).Err()
127 if err != nil {
128 return err
129 }
130 }
131
132 slots := scenario.slots()
133 for pos, master := range scenario.masters() {
134 err := master.ClusterAddSlotsRange(ctx, slots[pos], slots[pos+1]-1).Err()
135 if err != nil && slices.Contains(allowErrs, err.Error()) == false {
136 return err
137 }
138 }
139
140 // Bootstrap slaves.
141 for idx, slave := range scenario.slaves() {
142 masterID := scenario.nodeIDs[idx]
143
144 // Wait until master is available
145 err := eventually(func() error {
146 s := slave.ClusterNodes(ctx).Val()
147 wanted := masterID
148 if !strings.Contains(s, wanted) {
149 return fmt.Errorf("%q does not contain %q", s, wanted)
150 }
151 return nil
152 }, 10*time.Second)
153 if err != nil {
154 return err
155 }
156
157 err = slave.ClusterReplicate(ctx, masterID).Err()
158 if err != nil {
159 return err
160 }
161 }
162
163 // Wait until all nodes have consistent info.
164 wanted := []redis.ClusterSlot{{
165 Start: 0,
166 End: 5460,
167 Nodes: []redis.ClusterNode{{
168 ID: "",

Callers 4

BenchmarkClusterPingFunction · 0.85
BenchmarkClusterDoIntFunction · 0.85
main_test.goFile · 0.85

Calls 15

collectNodeInformationFunction · 0.85
eventuallyFunction · 0.85
assertSlotsEqualFunction · 0.85
slotsMethod · 0.80
mastersMethod · 0.80
slavesMethod · 0.80
ErrMethod · 0.65
ClusterMeetMethod · 0.65
ClusterAddSlotsRangeMethod · 0.65
ClusterNodesMethod · 0.65
ClusterReplicateMethod · 0.65
ResultMethod · 0.65

Tested by

no test coverage detected