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

Method updateRingState

ring/ring.go:413–447  ·  view source on GitHub ↗
(ringDesc *Desc)

Source from the content-addressed store, hash-verified

411}
412
413func (r *Ring) updateRingState(ringDesc *Desc) {
414 r.mtx.RLock()
415 prevRing := r.ringDesc
416 r.mtx.RUnlock()
417
418 // Filter out all instances belonging to excluded zones.
419 if len(r.cfg.ExcludedZones) > 0 {
420 for instanceID, instance := range ringDesc.Ingesters {
421 if slices.Contains(r.cfg.ExcludedZones, instance.Zone) {
422 delete(ringDesc.Ingesters, instanceID)
423 }
424 }
425 }
426
427 // Ensure the ID of each InstanceDesc is set based on the map of instances. This
428 // handles the case where some components are running older lifecyclers which do
429 // not set the instance ID when registering in the ring.
430 ringDesc.setInstanceIDs()
431
432 rc := prevRing.RingCompare(ringDesc)
433 if rc == Equal || rc == EqualButStatesAndTimestamps {
434 // No need to update tokens or zones. Only states and timestamps
435 // have changed. (If Equal, nothing has changed, but that doesn't happen
436 // when watching the ring for updates).
437 r.mtx.Lock()
438 r.ringDesc = ringDesc
439 if rc != Equal {
440 r.updateRingMetrics()
441 }
442 r.mtx.Unlock()
443 return
444 }
445
446 r.setRingStateFromDesc(ringDesc, true, true, true)
447}
448
449func (r *Ring) setRingStateFromDesc(ringDesc *Desc, updateMetrics, updateRegisteredTimestampCache, updateReadOnlyInstances bool) {
450 now := time.Now()

Calls 4

updateRingMetricsMethod · 0.95
setRingStateFromDescMethod · 0.95
setInstanceIDsMethod · 0.80
RingCompareMethod · 0.80