Skip to content

Commit

Permalink
Revert looking window var renaming
Browse files Browse the repository at this point in the history
  • Loading branch information
jhalterman committed Aug 5, 2024
1 parent 1dcc441 commit 7eec281
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 22 deletions.
18 changes: 9 additions & 9 deletions ring/partitions_ring_shuffle_shard_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,15 @@ func (r *partitionRingShuffleShardCache) setSubringWithLookback(identifier strin
}

var (
lookbackWindowStart = now.Add(-lookbackPeriod).Unix()
validForLookbackWindowEnd = int64(math.MaxInt64)
lookbackWindowStart = now.Add(-lookbackPeriod).Unix()
validForLookbackWindowsStartingBefore = int64(math.MaxInt64)
)

for _, partition := range subring.desc.Partitions {
stateChangedDuringLookbackWindow := partition.StateTimestamp >= lookbackWindowStart

if stateChangedDuringLookbackWindow && partition.StateTimestamp < validForLookbackWindowEnd {
validForLookbackWindowEnd = partition.StateTimestamp
if stateChangedDuringLookbackWindow && partition.StateTimestamp < validForLookbackWindowsStartingBefore {
validForLookbackWindowsStartingBefore = partition.StateTimestamp
}
}

Expand All @@ -68,11 +68,11 @@ func (r *partitionRingShuffleShardCache) setSubringWithLookback(identifier strin
// before and after the time a partition state has changed.
key := subringCacheKey{identifier: identifier, shardSize: size, lookbackPeriod: lookbackPeriod}

if existingEntry, haveCached := r.cacheWithLookback[key]; !haveCached || existingEntry.validLookbackWindowStart < lookbackWindowStart {
if existingEntry, haveCached := r.cacheWithLookback[key]; !haveCached || existingEntry.validForLookbackWindowsStartingAfter < lookbackWindowStart {
r.cacheWithLookback[key] = cachedSubringWithLookback[*PartitionRing]{
subring: subring,
validLookbackWindowStart: lookbackWindowStart,
validLookbackWindowEnd: validForLookbackWindowEnd,
subring: subring,
validForLookbackWindowsStartingAfter: lookbackWindowStart,
validForLookbackWindowsStartingBefore: validForLookbackWindowsStartingBefore,
}
}
}
Expand All @@ -87,7 +87,7 @@ func (r *partitionRingShuffleShardCache) getSubringWithLookback(identifier strin
}

lookbackWindowStart := now.Add(-lookbackPeriod).Unix()
if lookbackWindowStart < cached.validLookbackWindowStart || lookbackWindowStart > cached.validLookbackWindowEnd {
if lookbackWindowStart < cached.validForLookbackWindowsStartingAfter || lookbackWindowStart > cached.validForLookbackWindowsStartingBefore {
// The cached subring is not valid for the lookback window that has been requested.
return nil
}
Expand Down
26 changes: 13 additions & 13 deletions ring/ring.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,9 +224,9 @@ type subringCacheKey struct {
}

type cachedSubringWithLookback[R any] struct {
subring R
validLookbackWindowStart int64 // if the lookback window is from T to S, validLookbackWindowStart is the earliest value of T this cache entry is valid for
validLookbackWindowEnd int64 // if the lookback window is from T to S, validLookbackWindowEnd is the latest value of T this cache entry is valid for
subring R
validForLookbackWindowsStartingAfter int64 // if the lookback window is from T to S, validForLookbackWindowsStartingAfter is the earliest value of T this cache entry is valid for
validForLookbackWindowsStartingBefore int64 // if the lookback window is from T to S, validForLookbackWindowsStartingBefore is the latest value of T this cache entry is valid for
}

// New creates a new Ring. Being a service, Ring needs to be started to do anything.
Expand Down Expand Up @@ -1007,7 +1007,7 @@ func (r *Ring) getCachedShuffledSubringWithLookback(identifier string, size int,
}

lookbackWindowStart := now.Add(-lookbackPeriod).Unix()
if lookbackWindowStart < cached.validLookbackWindowStart || lookbackWindowStart > cached.validLookbackWindowEnd {
if lookbackWindowStart < cached.validForLookbackWindowsStartingAfter || lookbackWindowStart > cached.validForLookbackWindowsStartingBefore {
// The cached subring is not valid for the lookback window that has been requested.
return nil
}
Expand Down Expand Up @@ -1040,14 +1040,14 @@ func (r *Ring) setCachedShuffledSubringWithLookback(identifier string, size int,
}

lookbackWindowStart := now.Add(-lookbackPeriod).Unix()
validForLookbackWindowEnd := int64(math.MaxInt64)
validForLookbackWindowsStartingBefore := int64(math.MaxInt64)

for _, instance := range subring.ringDesc.Ingesters {
if instance.RegisteredTimestamp >= lookbackWindowStart && instance.RegisteredTimestamp < validForLookbackWindowEnd {
validForLookbackWindowEnd = instance.RegisteredTimestamp
if instance.RegisteredTimestamp >= lookbackWindowStart && instance.RegisteredTimestamp < validForLookbackWindowsStartingBefore {
validForLookbackWindowsStartingBefore = instance.RegisteredTimestamp
}
if instance.ReadOnlyUpdatedTimestamp >= lookbackWindowStart && instance.ReadOnlyUpdatedTimestamp < validForLookbackWindowEnd {
validForLookbackWindowEnd = instance.ReadOnlyUpdatedTimestamp
if instance.ReadOnlyUpdatedTimestamp >= lookbackWindowStart && instance.ReadOnlyUpdatedTimestamp < validForLookbackWindowsStartingBefore {
validForLookbackWindowsStartingBefore = instance.ReadOnlyUpdatedTimestamp
}
}

Expand All @@ -1070,11 +1070,11 @@ func (r *Ring) setCachedShuffledSubringWithLookback(identifier string, size int,
// before and after the time of an instance registering.
key := subringCacheKey{identifier: identifier, shardSize: size, lookbackPeriod: lookbackPeriod}

if existingEntry, haveCached := r.shuffledSubringWithLookbackCache[key]; !haveCached || existingEntry.validLookbackWindowStart < lookbackWindowStart {
if existingEntry, haveCached := r.shuffledSubringWithLookbackCache[key]; !haveCached || existingEntry.validForLookbackWindowsStartingAfter < lookbackWindowStart {
r.shuffledSubringWithLookbackCache[key] = cachedSubringWithLookback[*Ring]{
subring: subring,
validLookbackWindowStart: lookbackWindowStart,
validLookbackWindowEnd: validForLookbackWindowEnd,
subring: subring,
validForLookbackWindowsStartingAfter: lookbackWindowStart,
validForLookbackWindowsStartingBefore: validForLookbackWindowsStartingBefore,
}
}
}
Expand Down

0 comments on commit 7eec281

Please sign in to comment.