Skip to content

Commit 8b6ff68

Browse files
ndyakovofekshenawa
authored andcommitted
[CAE-1046] fix(loading): cache the loaded flag for slave nodes (redis#3410)
* fix(loading): cache the loaded flag for slave nodes * fix(lint): make linter happy
1 parent 3e74631 commit 8b6ff68

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
@@ -349,6 +349,7 @@ type clusterNode struct {
349349
latency uint32 // atomic
350350
generation uint32 // atomic
351351
failing uint32 // atomic
352+
loaded uint32 // atomic
352353

353354
// last time the latency measurement was performed for the node, stored in nanoseconds
354355
// from epoch
@@ -415,6 +416,7 @@ func (n *clusterNode) Latency() time.Duration {
415416

416417
func (n *clusterNode) MarkAsFailing() {
417418
atomic.StoreUint32(&n.failing, uint32(time.Now().Unix()))
419+
atomic.StoreUint32(&n.loaded, 0)
418420
}
419421

420422
func (n *clusterNode) Failing() bool {
@@ -458,11 +460,21 @@ func (n *clusterNode) SetLastLatencyMeasurement(t time.Time) {
458460
}
459461

460462
func (n *clusterNode) Loading() bool {
463+
loaded := atomic.LoadUint32(&n.loaded)
464+
if loaded == 1 {
465+
return false
466+
}
467+
468+
// check if the node is loading
461469
ctx, cancel := context.WithTimeout(context.Background(), 100*time.Millisecond)
462470
defer cancel()
463471

464472
err := n.Client.Ping(ctx).Err()
465-
return err != nil && isLoadingError(err)
473+
loading := err != nil && isLoadingError(err)
474+
if !loading {
475+
atomic.StoreUint32(&n.loaded, 1)
476+
}
477+
return loading
466478
}
467479

468480
//------------------------------------------------------------------------------

0 commit comments

Comments
 (0)