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