MCPcopy
hub / github.com/grafana/dskit / filterOutReadOnlyInstances

Method filterOutReadOnlyInstances

ring/ring.go:1141–1166  ·  view source on GitHub ↗

filterOutReadOnlyInstances removes all read-only instances from the ring, and returns the resulting ring.

(lookbackPeriod time.Duration, now time.Time)

Source from the content-addressed store, hash-verified

1139
1140// filterOutReadOnlyInstances removes all read-only instances from the ring, and returns the resulting ring.
1141func (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).
1169func (r *Ring) buildRingForTheShard(shard map[string]InstanceDesc) *Ring {

Callers 2

ShuffleShardMethod · 0.95

Calls 3

buildRingForTheShardMethod · 0.95
AddMethod · 0.65

Tested by

no test coverage detected