Skip to content

Commit

Permalink
Restore oldestRegisteredTimestamp optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
jhalterman committed Aug 6, 2024
1 parent 8df0c89 commit 9fde251
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion ring/ring.go
Original file line number Diff line number Diff line change
Expand Up @@ -726,6 +726,16 @@ func (r *Ring) shuffleShard(identifier string, size int, lookbackPeriod time.Dur
r.mtx.RLock()
defer r.mtx.RUnlock()

// If all instances have RegisteredTimestamp within the lookback period,
// then all instances would be included in the resulting ring, so we can
// simply return this ring.
//
// If any instance had RegisteredTimestamp equal to 0 (it would not cause additional lookup of next instance),
// then r.oldestRegisteredTimestamp is zero too, and we skip this optimization.
if lookbackPeriod > 0 && r.oldestRegisteredTimestamp > 0 && r.oldestRegisteredTimestamp >= lookbackUntil {
return r
}

var numInstancesPerZone int
var actualZones []string

Expand Down Expand Up @@ -801,7 +811,7 @@ func (r *Ring) shuffleShard(identifier string, size int, lookbackPeriod time.Dur
// If the lookback is enabled, and this instance has switched its read-only state within the lookback period,
// then we should include it in the subring, but continue selecting more instances.
//
// * If instance switched to read-only state within the lookback period, then next instance is currently receiving data that belonged to this instance before.
// * If instance switched to read-only state within the lookback period, then next instance is currently receiving data that previously belonged to this instance.
// * If instance switched to read-write state (read-only=false) within the lookback period, then there was another instance that received data that now belongs back to this instance.
if lookbackPeriod > 0 && instance.ReadOnlyUpdatedTimestamp >= lookbackUntil {
continue
Expand Down

0 comments on commit 9fde251

Please sign in to comment.