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

Function shuffleQueriersForUser

pkg/scheduler/queue/user_queues.go:367–387  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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.
367func 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.

Callers 4

getOrAddQueueMethod · 0.85
recomputeUserQueriersMethod · 0.85
TestShuffleQueriersFunction · 0.85

Calls

no outgoing calls

Tested by 2

TestShuffleQueriersFunction · 0.68