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

Method ShuffleShardWithLookback

ring/partition_ring.go:217–229  ·  view source on GitHub ↗

ShuffleShardWithLookback is like ShuffleShard() but the returned subring includes all instances that have been part of the identifier's shard in [now - lookbackPeriod, now] time window. This function can return a mix of ACTIVE and INACTIVE partitions. INACTIVE partitions are only included if they w

(identifier string, size int, lookbackPeriod time.Duration, now time.Time)

Source from the content-addressed store, hash-verified

215// This function supports caching, but the cache will only be effective if successive calls for the
216// same identifier are with the same lookbackPeriod and increasing values of now.
217func (r *PartitionRing) ShuffleShardWithLookback(identifier string, size int, lookbackPeriod time.Duration, now time.Time) (*PartitionRing, error) {
218 if cached := r.shuffleShardCache.getSubringWithLookback(identifier, size, lookbackPeriod, now); cached != nil {
219 return cached, nil
220 }
221
222 subring, err := r.shuffleShard(identifier, size, lookbackPeriod, now)
223 if err != nil {
224 return nil, err
225 }
226
227 r.shuffleShardCache.setSubringWithLookback(identifier, size, lookbackPeriod, now, subring)
228 return subring, nil
229}
230
231func (r *PartitionRing) shuffleShard(identifier string, size int, lookbackPeriod time.Duration, now time.Time) (*PartitionRing, error) {
232 // If the size is too small or too large, run with a size equal to the total number of partitions.

Calls 3

shuffleShardMethod · 0.95