Skip to content

fix(cache): invalidate MultiTier L1 on deleteByPrefix/clear, race-safe (#1989) - #2064

Merged
ariskemper merged 1 commit into
mainfrom
fix/1989-multitier-l1-v2
Jun 3, 2026
Merged

ariskemper merged 1 commit into
mainfrom
fix/1989-multitier-l1-v2

Conversation

@ariskemper

Copy link
Copy Markdown
Contributor

Supersedes #2050 (rebased onto current main after #2049 merged, with both review findings incorporated).

What

MultiTierCacheRepository.deleteByPrefix/clear only pattern-deleted the L3 backend, but get() reads L1 first — so deleted entries were served stale from the in-memory L1 tier until TTL.

Both #2050 review findings incorporated

  1. Race (HIGH): invalidate L1 both before and after the awaited L3 delete. Before-wipe makes concurrent reads miss L1 fast; after-wipe drops any entry a racing get() backfilled from a not-yet-deleted L3 value (which would otherwise survive to TTL — the exact bug).
  2. No-delByPattern branch: wipe L1 before the early return, so a backend lacking delByPattern still gets L1 invalidated (previously skipped).

Adds MemoryTier.deleteByPrefix and 4 tests including a deferred-gated race test and a no-delByPattern L1-wipe test. Red-green verified: each finding's test fails on the corresponding broken variant and passes with the fix.

Refs #1989

#1989)

Closes the L1 stale-read gap: deleteByPrefix/clear only pattern-deleted the L3
backend, but get() reads L1 first, so deleted entries were served from the
in-memory tier until TTL.

Incorporates both review findings on the original fix:
- Race: invalidate L1 BOTH before and after the awaited L3 delete. The
  before-wipe makes concurrent reads miss L1 fast; the after-wipe drops any
  entry a racing get() backfilled from a not-yet-deleted L3 value (which would
  otherwise survive until TTL — the very bug being fixed).
- No-delByPattern branch: wipe L1 before the early return so a backend lacking
  delByPattern still gets its L1 invalidated (was previously skipped).

Adds MemoryTier.deleteByPrefix and 4 tests incl. a deferred-gated race test and
a no-delByPattern L1-wipe test. Red-green verified per finding.

Refs #1989
@ariskemper
ariskemper merged commit b7ce3b8 into main Jun 3, 2026
18 checks passed
@ariskemper
ariskemper deleted the fix/1989-multitier-l1-v2 branch June 3, 2026 06:45
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.

1 participant