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

Method ShuffleShard

ring/ring.go:946–963  ·  view source on GitHub ↗

ShuffleShard returns a subring for the provided identifier (eg. a tenant ID) and size (number of instances). The size is expected to be a multiple of the number of zones and the returned subring will contain the same number of instances per zone as far as there are enough registered instances in the

(identifier string, size int)

Source from the content-addressed store, hash-verified

944//
945// Subring returned by this method does not contain instances that have read-only field set.
946func (r *Ring) ShuffleShard(identifier string, size int) ReadRing {
947 if cached := r.getCachedShuffledSubring(identifier, size); cached != nil {
948 return cached
949 }
950
951 var result *Ring
952 if size <= 0 {
953 result = r.filterOutReadOnlyInstances(0, time.Now())
954 } else {
955 result = r.shuffleShard(identifier, size, 0, time.Now())
956 }
957 // Only cache subring if it is different from this ring, to avoid deadlocks in getCachedShuffledSubring,
958 // when we update the cached ring.
959 if result != r {
960 r.setCachedShuffledSubring(identifier, size, result)
961 }
962 return result
963}
964
965// ShuffleShardWithLookback is like ShuffleShard() but the returned subring includes all instances
966// that have been part of the identifier's shard since "now - lookbackPeriod".

Calls 4

shuffleShardMethod · 0.95