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)
| 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. |
| 193 | func (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. |
nothing calls this directly
no test coverage detected