Repository navigation
fix(ingester): skip in-flight entries when evicting from the postings cache - #7993
Merged
alanprot merged 2 commits intoDec 4, 2026
Merged
Conversation
… cache Since cortexproject#7944 an entry is linked into the LRU list when its fetch starts. evictLocked only looked at the list front, so: - under byte pressure it evicted an in-flight front, which frees no bytes and lets the next caller for that key start a duplicate fetch; - during expiry it stopped at an in-flight front, so expired entries behind it survived PurgeExpiredItems. Walk the list from the front and skip in-flight entries in both cases. Signed-off-by: Alan Protasio <alanprot@gmail.com>
Signed-off-by: Alan Protasio <alanprot@gmail.com>
alanprot
marked this pull request as ready for review
December 4, 2026 17:57
alanprot
enabled auto-merge (squash)
December 4, 2026 17:57
danielblando
approved these changes
Dec 4, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this PR does:
Fixes two regressions from #7944 in the expanded postings cache eviction.
Since #7944 an entry is linked into the LRU list when its fetch starts, not when it completes.
evictLockedonly looked at the list front, so an in-flight entry at the front caused two problems:max_bytes, thefullbranch evicted the in-flight front. That frees no bytes, since an in-flight entry's bytes are not counted yet, and the next caller for that key misses and starts a duplicate fetch instead of joining the running one.PurgeExpiredItemsreturned at the front and every expired entry behind it survived until that fetch finished.evictLockednow walks the list from the front and skips in-flight entries in both cases. The invariant that an entry is in the map if and only if it is linked in the list is unchanged. The walk passes over at most the number of fetches currently running.Expiry still stops at the first completed entry that is not expired. Expired entries can also sit behind a fresh completed entry, because a hit moves an entry to the back without refreshing its timestamp. That predates #7944 and is left for a separate change.
A fetch that never returns now keeps its key in flight until it does: it is neither expired nor evicted for space, so later callers for that key keep joining it, each bounded by its own context. Before this change, byte pressure could evict such an entry by accident. The bound on a hung fetch is
fetch_timeout, the same as for the caller running it.A failed fetch is removed from the cache before its waiters are woken;
TestLruCache_FailedFetchWithWaitersIsNotCachedcovers that with a waiter joined to the failing fetch.Which issue(s) this PR fixes:
None filed. Both regressions came in with #7944, which is not released yet, so there is no CHANGELOG entry.
Checklist
TestLruCache_FullEvictionSkipsInflightEntries,TestLruCache_ExpireSkipsInflightEntries, both fail before the fix;TestLruCache_FailedFetchWithWaitersIsNotCached)CHANGELOG.mdupdated - fixes an unreleased change (perf(ingester): cut postings cache memory with a single-object LRU entry #7944)docs/configuration/v1-guarantees.mdupdated if this PR introduces experimental flags (no new flags)