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)
| 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. |
| 217 | func (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 | |
| 231 | func (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. |