filterOutReadOnlyInstances removes all read-only instances from the ring, and returns the resulting ring.
(lookbackPeriod time.Duration, now time.Time)
| 1139 | |
| 1140 | // filterOutReadOnlyInstances removes all read-only instances from the ring, and returns the resulting ring. |
| 1141 | func (r *Ring) filterOutReadOnlyInstances(lookbackPeriod time.Duration, now time.Time) *Ring { |
| 1142 | lookbackUntil := now.Add(-lookbackPeriod).Unix() |
| 1143 | |
| 1144 | r.mtx.RLock() |
| 1145 | defer r.mtx.RUnlock() |
| 1146 | |
| 1147 | // If there are no read-only instances, there's no need to do any filtering. |
| 1148 | if r.readOnlyInstances != nil && *r.readOnlyInstances == 0 { |
| 1149 | return r |
| 1150 | } |
| 1151 | |
| 1152 | // If all readOnlyUpdatedTimestamp values are within lookback window, we can return the ring without any filtering. |
| 1153 | if lookbackPeriod > 0 && r.oldestReadOnlyUpdatedTimestamp != nil && *r.oldestReadOnlyUpdatedTimestamp >= lookbackUntil { |
| 1154 | return r |
| 1155 | } |
| 1156 | |
| 1157 | shard := make(map[string]InstanceDesc, len(r.ringDesc.Ingesters)) |
| 1158 | |
| 1159 | for id, inst := range r.ringDesc.Ingesters { |
| 1160 | if shouldIncludeReadonlyInstanceInTheShard(inst, lookbackPeriod, lookbackUntil) { |
| 1161 | shard[id] = inst |
| 1162 | } |
| 1163 | } |
| 1164 | |
| 1165 | return r.buildRingForTheShard(shard) |
| 1166 | } |
| 1167 | |
| 1168 | // buildRingForTheShard builds read-only ring for the shard (this ring won't be updated in the future). |
| 1169 | func (r *Ring) buildRingForTheShard(shard map[string]InstanceDesc) *Ring { |
no test coverage detected