From 9fde25132c4d4845fc69efdea5adf550405a3fd2 Mon Sep 17 00:00:00 2001 From: Jonathan Halterman Date: Tue, 6 Aug 2024 11:40:49 -0700 Subject: [PATCH] Restore oldestRegisteredTimestamp optimization --- ring/ring.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/ring/ring.go b/ring/ring.go index 4305c0f4b..a669408eb 100644 --- a/ring/ring.go +++ b/ring/ring.go @@ -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 @@ -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