File tree Expand file tree Collapse file tree 1 file changed +14
-3
lines changed Expand file tree Collapse file tree 1 file changed +14
-3
lines changed Original file line number Diff line number Diff line change @@ -204,15 +204,26 @@ func (n *clusterNode) updateLatency() {
204
204
const numProbe = 10
205
205
var dur uint64
206
206
207
+ successes := 0
207
208
for i := 0 ; i < numProbe ; i ++ {
208
209
time .Sleep (time .Duration (10 + rand .Intn (10 )) * time .Millisecond )
209
210
210
211
start := time .Now ()
211
- n .Client .Ping (context .TODO ())
212
- dur += uint64 (time .Since (start ) / time .Microsecond )
212
+ err := n .Client .Ping (context .TODO ()).Err ()
213
+ if err == nil {
214
+ dur += uint64 (time .Since (start ) / time .Microsecond )
215
+ successes ++
216
+ }
213
217
}
214
218
215
- latency := float64 (dur ) / float64 (numProbe )
219
+ var latency float64
220
+ if successes == 0 {
221
+ // If none of the pings worked, set latency to some arbitrarily high value so this node gets
222
+ // least priority.
223
+ latency = float64 ((1 * time .Minute ) / time .Microsecond )
224
+ } else {
225
+ latency = float64 (dur ) / float64 (successes )
226
+ }
216
227
atomic .StoreUint32 (& n .latency , uint32 (latency + 0.5 ))
217
228
}
218
229
You can’t perform that action at this time.
0 commit comments