shuffleQueriersForUser returns nil if queriersToSelect is 0 or there are not enough queriers to select from. In that case *all* queriers should be used. Scratchpad is used for shuffling, to avoid new allocations. If nil, new slice is allocated.
(userSeed int64, queriersToSelect int, allSortedQueriers []string, scratchpad []string)
| 365 | // In that case *all* queriers should be used. |
| 366 | // Scratchpad is used for shuffling, to avoid new allocations. If nil, new slice is allocated. |
| 367 | func shuffleQueriersForUser(userSeed int64, queriersToSelect int, allSortedQueriers []string, scratchpad []string) map[string]struct{} { |
| 368 | if queriersToSelect == 0 || len(allSortedQueriers) <= queriersToSelect { |
| 369 | return nil |
| 370 | } |
| 371 | |
| 372 | queriers := make(map[string]struct{}, queriersToSelect) |
| 373 | rnd := rand.New(rand.NewSource(userSeed)) |
| 374 | |
| 375 | scratchpad = scratchpad[:0] |
| 376 | scratchpad = append(scratchpad, allSortedQueriers...) |
| 377 | |
| 378 | last := len(scratchpad) - 1 |
| 379 | for range queriersToSelect { |
| 380 | r := rnd.Intn(last + 1) |
| 381 | queriers[scratchpad[r]] = struct{}{} |
| 382 | scratchpad[r], scratchpad[last] = scratchpad[last], scratchpad[r] |
| 383 | last-- |
| 384 | } |
| 385 | |
| 386 | return queriers |
| 387 | } |
| 388 | |
| 389 | // getPriorityList returns a list of priorities, each priority repeated as much as number of reserved queriers. |
| 390 | // This is used when creating map of reserved queriers. |
no outgoing calls