MCPcopy Index your code
hub / github.com/cortexproject/cortex / waitStability

Function waitStability

pkg/ring/util.go:77–107  ·  view source on GitHub ↗
(ctx context.Context, r *Ring, op Operation, minStability, maxWaiting time.Duration, isChanged func(ReplicationSet, ReplicationSet) bool)

Source from the content-addressed store, hash-verified

75}
76
77func waitStability(ctx context.Context, r *Ring, op Operation, minStability, maxWaiting time.Duration, isChanged func(ReplicationSet, ReplicationSet) bool) error {
78 // Configure the max waiting time as a context deadline.
79 ctx, cancel := context.WithTimeout(ctx, maxWaiting)
80 defer cancel()
81
82 // Get the initial ring state.
83 ringLastState, _ := r.GetAllHealthy(op) // nolint:errcheck
84 ringLastStateTs := time.Now()
85
86 const pollingFrequency = time.Second
87 pollingTicker := time.NewTicker(pollingFrequency)
88 defer pollingTicker.Stop()
89
90 for {
91 select {
92 case <-ctx.Done():
93 return ctx.Err()
94 case <-pollingTicker.C:
95 // We ignore the error because in case of error it will return an empty
96 // replication set which we use to compare with the previous state.
97 currRingState, _ := r.GetAllHealthy(op) // nolint:errcheck
98
99 if isChanged(ringLastState, currRingState) {
100 ringLastState = currRingState
101 ringLastStateTs = time.Now()
102 } else if time.Since(ringLastStateTs) >= minStability {
103 return nil
104 }
105 }
106 }
107}
108
109// MakeBuffersForGet returns buffers to use with Ring.Get().
110func MakeBuffersForGet() (bufDescs []InstanceDesc, bufHosts []string, bufZones map[string]int) {

Callers 2

WaitRingStabilityFunction · 0.85
WaitRingTokensStabilityFunction · 0.85

Calls 4

DoneMethod · 0.80
GetAllHealthyMethod · 0.65
StopMethod · 0.65
ErrMethod · 0.65

Tested by

no test coverage detected