Commit b61cef3
fix(queryeviction): deregister evicted queries to prevent double accounting
Evicted victims were never removed from the QueryRegistry by the evictor;
the only cleanup is the deferred Deregister in trackedQuery.Exec, which
runs when the query goroutine eventually unwinds. Until then the
already-cancelled victim remained in the evictable candidate set, so a
later eviction cycle could re-pick it: cortex_query_evictions_total was
double-counted for a single query, a MaxEvictionsPerCycle slot was burned
on a no-op Cancel instead of relieving pressure, and in tests the second
Cancel callback panicked on a double channel close.
Deregister the victim before cancelling it, keeping all bookkeeping
(metric, registry) ahead of the externally observable cancellation
signal. Deregister is an idempotent locked delete, so the deferred
Deregister in trackedQuery.Exec remains a safe no-op when the query
finishes unwinding.
Note the registry semantic shift: registry.Len() (and the
registered_queries debug log field) now means "evictable candidates" -
it no longer includes cancelled-but-still-unwinding victims.
Add TestEvictedVictim_RemovedFromRegistry, which fails deterministically
without this fix (expected: 0, actual: 1): the victim stayed registered
after its eviction was observed.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Signed-off-by: Sandy Chen <Yuxuan.Chen@morganstanley.com>1 parent 07ec4d5 commit b61cef3
2 files changed
Lines changed: 34 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
103 | 103 | | |
104 | 104 | | |
105 | 105 | | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
106 | 111 | | |
107 | 112 | | |
108 | 113 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
242 | 242 | | |
243 | 243 | | |
244 | 244 | | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
245 | 274 | | |
246 | 275 | | |
247 | 276 | | |
| |||
0 commit comments