Skip to content

fix: invalidate CacheStore entries after bulk deletion - #4696

Merged
d-v-b merged 2 commits into
zarr-developers:mainfrom
Harshit-2118:fix/cache-bulk-deletion
Dec 4, 2026
Merged

d-v-b merged 2 commits into
zarr-developers:mainfrom
Harshit-2118:fix/cache-bulk-deletion

Conversation

@Harshit-2118

Copy link
Copy Markdown
Contributor

Summary

Fixes #4695.

CacheStore.clear() and CacheStore.delete_dir() previously deleted entries in the source store without invalidating cached data, leaving stale full-key or byte-range entries and out-of-sync size/LRU tracking. This fix performs the source deletion first, invalidates the persistent cache and matching tracked entries, and updates current_size and LRU tracking under the state lock. Directory boundaries are preserved: deleting data/ leaves the key data and the prefix database/ alone.

For reviewers

Range invalidation removes its tuple-key tracking and subtracts its sizes. The following loop handles only full-key entries, subtracting each size once before removing its tracking. Persistent cache deletion also removes stale entries that are not tracked by this instance.

The 12 new cases cover full/range reads, clear and directory deletion, trailing-slash and empty prefixes, untracked persistent entries, public group reopening in formats 2 and 3, shared read-only views, a disk-backed cache, size-budget reuse/LRU eviction, and source-error controls. Against unchanged main 13f4bf5, they give 10 failures and 2 passing controls; with the fix all 12 pass. The selected cache/wrapper/memory/local-store suite reports 562 passed and 159 GPU-only skips. Ruff check/format, focused mypy and changelog validation pass. A fresh run of the 12 new cases also passes against the unchanged upstream head.

Source errors raised before deletion propagate before cache invalidation. This does not add rollback for partially failing backends or atomicity for concurrent reads and deletion. The full project suite and hosted CI have not been run locally.

Author attestation

  • I am a human, these are my changes, and I have reviewed and understood every change and can explain why each is correct.

TODO

  • Add regression tests.
  • Add docstrings for the overrides.
  • Add a bugfix changelog fragment.
  • GitHub Actions have all passed.
  • Codecov passes.

@codecov

codecov Bot commented Dec 4, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.06%. Comparing base (13f4bf5) to head (303de67).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4696      +/-   ##
==========================================
+ Coverage   95.00%   95.06%   +0.06%     
==========================================
  Files          96       96              
  Lines       14115    14131      +16     
==========================================
+ Hits        13410    13434      +24     
+ Misses        705      697       -8     
Files with missing lines Coverage Δ
src/zarr/experimental/cache_store.py 92.99% <100.00%> (+4.60%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@d-v-b
d-v-b merged commit 12b4721 into zarr-developers:main Dec 4, 2026
43 checks passed
d-v-b added a commit to d-v-b/zarr-python that referenced this pull request Dec 4, 2026
…gacy copy

zarr-developers#4696 changed `zarr.experimental.cache_store`, so the legacy copy and the
"legacy in sync with zarr" check fell behind. Regenerated, with that PR's store-level tests added
to the copy of the test module.

Assisted-by: ClaudeCode:claude-opus-5-5
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

CacheStore serves deleted arrays after group deletion or store clearing

2 participants