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

Function normalizeIngestersMap

pkg/ring/model.go:321–352  ·  view source on GitHub ↗

normalizeIngestersMap will do the following: - sorts tokens and removes duplicates (only within single ingester) - modifies the input ring

(inputRing *Desc)

Source from the content-addressed store, hash-verified

319// - sorts tokens and removes duplicates (only within single ingester)
320// - modifies the input ring
321func normalizeIngestersMap(inputRing *Desc) {
322 // Make sure LEFT ingesters have no tokens
323 for n, ing := range inputRing.Ingesters {
324 if ing.State == LEFT {
325 ing.Tokens = nil
326 inputRing.Ingesters[n] = ing
327 }
328
329 // Sort tokens, and remove duplicates
330 if len(ing.Tokens) == 0 {
331 continue
332 }
333
334 if !sort.IsSorted(Tokens(ing.Tokens)) {
335 sort.Sort(Tokens(ing.Tokens))
336 }
337
338 // tokens are sorted now, we can easily remove duplicates.
339 prev := ing.Tokens[0]
340 for ix := 1; ix < len(ing.Tokens); {
341 if ing.Tokens[ix] == prev {
342 ing.Tokens = append(ing.Tokens[:ix], ing.Tokens[ix+1:]...)
343 } else {
344 prev = ing.Tokens[ix]
345 ix++
346 }
347 }
348
349 // write updated value back to map
350 inputRing.Ingesters[n] = ing
351 }
352}
353
354// tokensEqual checks for equality of two slices. Assumes the slices are sorted.
355func tokensEqual(lhs, rhs []uint32) bool {

Callers 1

mergeWithTimeMethod · 0.85

Calls 1

TokensTypeAlias · 0.85

Tested by

no test coverage detected