Skip to content

fix: register inherited CacheStore entries on first hit - #4687

Open
1915rising wants to merge 1 commit into
zarr-developers:mainfrom
1915rising:fix/4282-cachestore-inherited-hit
Open

1915rising wants to merge 1 commit into
zarr-developers:mainfrom
1915rising:fix/4282-cachestore-inherited-hit

Conversation

@1915rising

Copy link
Copy Markdown

Summary

Part of #4282. A CacheStore opened over a cache store that already holds entries starts with empty tracking, and a hit on one of those entries did not register it: _update_access_order no-ops for untracked keys, so the entry never counted toward max_size and could never be evicted.

On a full-key hit, an untracked entry is now registered with _track_entry, using the buffer already in hand. No listing and no extra IO in the store lifecycle. Entries that are never read stay untracked, so this does not close out #4282 on its own. The broader question of how a new instance should account for pre-existing entries, including the public cache state direction raised in the issue, is still open.

Repro: two instances over one LocalStore, max_size=40960, five 8192-byte values written by the first. Before, the second instance reported current_size=0 after a hit on an inherited key, and on-disk grew from 40960 to 81920 with 0 evictions. After, the hit registers the entry (current_size=8192) and later writes evict it, holding current_size at the bound.

Tests: tests/test_experimental/test_cache_store.py, 47 passed before and 48 after. The new test covers registration on hit and eviction of a registered inherited entry, and fails without the fix. Ruff check and format clean.

For reviewers

The change is in _get_try_cache, full-key hits only. Byte-range entries live in the in-memory range cache and cannot be inherited, so that path is untouched. I am confident in the size accounting since it reuses _track_entry. A second look at the max_age_seconds interaction would be valued: untracked entries are treated as stale by get there and already refresh through _get_no_cache, so registration on hit only fires when the entry counts as fresh.

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 unit tests and/or doctests in docstrings
  • Add docstrings and API docs for any new/modified user-facing classes and functions
  • New/modified features documented in docs/user-guide/*.md
  • Changes documented as a new file in changes/
  • GitHub Actions have all passed
  • Test coverage is 100% (Codecov passes)

This branch has not been deployed

No deployments
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