normalizeIngestersMap will do the following: - sorts tokens and removes duplicates (only within single ingester) - modifies the input ring
(inputRing *Desc)
| 319 | // - sorts tokens and removes duplicates (only within single ingester) |
| 320 | // - modifies the input ring |
| 321 | func 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. |
| 355 | func tokensEqual(lhs, rhs []uint32) bool { |
no test coverage detected