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

Method ShuffleShard

ring/partition_ring.go:193–206  ·  view source on GitHub ↗

ShuffleShard returns a subring for the provided identifier (eg. a tenant ID) and size (number of partitions). The algorithm used to build the subring is a shuffle sharder based on probabilistic hashing. We pick N unique partitions, walking the ring starting from random but predictable numbers. The

(identifier string, size int)

Source from the content-addressed store, hash-verified

191// - Shuffling: probabilistically, for a large enough cluster each identifier gets a different
192// set of instances, with a reduced number of overlapping instances between two identifiers.
193func (r *PartitionRing) ShuffleShard(identifier string, size int) (*PartitionRing, error) {
194 if cached := r.shuffleShardCache.getSubring(identifier, size); cached != nil {
195 return cached, nil
196 }
197
198 // No need to pass the time if there's no lookback.
199 subring, err := r.shuffleShard(identifier, size, 0, time.Time{})
200 if err != nil {
201 return nil, err
202 }
203
204 r.shuffleShardCache.setSubring(identifier, size, subring)
205 return subring, nil
206}
207
208// ShuffleShardWithLookback is like ShuffleShard() but the returned subring includes all instances
209// that have been part of the identifier's shard in [now - lookbackPeriod, now] time window.

Callers

nothing calls this directly

Calls 3

shuffleShardMethod · 0.95
getSubringMethod · 0.80
setSubringMethod · 0.80

Tested by

no test coverage detected