Skip to content

Commit f4358ac

Browse files
authored
[CAE-1046] fix(loading): cache the loaded flag for slave nodes (#3410)
* fix(loading): cache the loaded flag for slave nodes * fix(lint): make linter happy
1 parent 4c635cc commit f4358ac

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

osscluster.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,7 @@ type clusterNode struct {
340340
latency uint32 // atomic
341341
generation uint32 // atomic
342342
failing uint32 // atomic
343+
loaded uint32 // atomic
343344

344345
// last time the latency measurement was performed for the node, stored in nanoseconds
345346
// from epoch
@@ -406,6 +407,7 @@ func (n *clusterNode) Latency() time.Duration {
406407

407408
func (n *clusterNode) MarkAsFailing() {
408409
atomic.StoreUint32(&n.failing, uint32(time.Now().Unix()))
410+
atomic.StoreUint32(&n.loaded, 0)
409411
}
410412

411413
func (n *clusterNode) Failing() bool {
@@ -449,11 +451,21 @@ func (n *clusterNode) SetLastLatencyMeasurement(t time.Time) {
449451
}
450452

451453
func (n *clusterNode) Loading() bool {
454+
loaded := atomic.LoadUint32(&n.loaded)
455+
if loaded == 1 {
456+
return false
457+
}
458+
459+
// check if the node is loading
452460
ctx, cancel := context.WithTimeout(context.Background(), 100*time.Millisecond)
453461
defer cancel()
454462

455463
err := n.Client.Ping(ctx).Err()
456-
return err != nil && isLoadingError(err)
464+
loading := err != nil && isLoadingError(err)
465+
if !loading {
466+
atomic.StoreUint32(&n.loaded, 1)
467+
}
468+
return loading
457469
}
458470

459471
//------------------------------------------------------------------------------

0 commit comments

Comments
 (0)