(ctx context.Context, r *Ring, op Operation, minStability, maxWaiting time.Duration, isChanged func(ReplicationSet, ReplicationSet) bool)
| 75 | } |
| 76 | |
| 77 | func 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(). |
| 110 | func MakeBuffersForGet() (bufDescs []InstanceDesc, bufHosts []string, bufZones map[string]int) { |
no test coverage detected