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

Function normalizeIngestersMap

ring/model.go:318–349  ·  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

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

Callers 1

mergeWithTimeMethod · 0.85

Calls 1

TokensTypeAlias · 0.85

Tested by

no test coverage detected