Skip to content

gocache/gocached: evict Actions younger than maxAge when over size - #16

Merged
tomhjp merged 1 commit into
mainfrom
tomhjp/gocached-size-cleanup-max-age
Nov 9, 2026
Merged

tomhjp merged 1 commit into
mainfrom
tomhjp/gocached-size-cleanup-max-age

Conversation

@tomhjp

@tomhjp tomhjp commented Nov 9, 2026

Copy link
Copy Markdown
Member

cleanupTick always used the maxAge cutoff when maxAge was set, even when no Actions were over age. Size-only cleanup could then evict only Actions older than maxAge, so the cache could grow past maxSize without limit. cmd/gocached sets maxAge by default, so this affected production.

Use the maxAge cutoff only when some Actions are over age. When the cache is over both limits, cleanup removes over-age Actions first and then falls back to size-only cleanup.

Fixes tailscale/corp#51226

@tomhjp
tomhjp requested a review from a team November 9, 2026 13:45

@winckler winckler left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left one suggestion, which I think doesn't add complexity and improves accuracy. But since the drift is only temporary (10 min per shard), it's fine if you prefer to land as is.

Comment thread gocache/gocached/gocached.go Resolved
cleanupTick always used the maxAge cutoff when maxAge was set, even
when no Actions were over age. Size-only cleanup could then evict
only Actions older than maxAge, so the cache could grow past maxSize
without limit. cmd/gocached sets maxAge by default, so this affected
production.

Run the age-cutoff pass only when some Actions are over age. If the
cache is over size and the age pass evicts nothing, continue to a
size-only pass with no age cutoff. Eviction does not update the
ActionsLE histograms that overAge comes from, so overAge can stay
true for up to shardStalenessTarget after the last over-age Actions
are gone. Without the fall-through, size cleanup stops during that
time.

Fixes tailscale/corp#51226
@tomhjp
tomhjp force-pushed the tomhjp/gocached-size-cleanup-max-age branch from 8c0c304 to 96093b5 Compare November 9, 2026 16:33
@tomhjp
tomhjp merged commit bae4d25 into main Nov 9, 2026
7 of 9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants