MCPcopy Create free account
hub / github.com/cortexproject/cortex / countTokensByAz

Method countTokensByAz

pkg/ring/ring.go:610–634  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

608}
609
610func (r *Ring) countTokensByAz() (map[string]map[string]uint32, map[string]int64) {
611 numTokens := map[string]map[string]uint32{}
612 owned := map[string]int64{}
613
614 for zone, zonalTokens := range r.ringDesc.getTokensByZone() {
615 numTokens[zone] = map[string]uint32{}
616 for i := 1; i <= len(zonalTokens); i++ {
617 index := i % len(zonalTokens)
618 diff := tokenDistance(zonalTokens[i-1], zonalTokens[index])
619 info := r.ringInstanceByToken[zonalTokens[index]]
620 owned[info.InstanceID] = owned[info.InstanceID] + diff
621 numTokens[zone][info.InstanceID] = numTokens[zone][info.InstanceID] + 1
622 }
623 }
624
625 // Set to 0 the number of owned tokens by instances which don't have tokens yet.
626 for id, info := range r.ringDesc.Ingesters {
627 if _, ok := owned[id]; !ok {
628 owned[id] = 0
629 numTokens[info.Zone][id] = 0
630 }
631 }
632
633 return numTokens, owned
634}
635
636// countTokens returns the number of tokens and tokens within the range for each instance.
637// The ring read lock must be already taken when calling this function.

Callers 1

ServeHTTPMethod · 0.95

Calls 2

tokenDistanceFunction · 0.85
getTokensByZoneMethod · 0.80

Tested by

no test coverage detected