Skip to content

Fix CacheStore size tracking when entries are removed - #4708

Open
sohailshk wants to merge 1 commit into
zarr-developers:mainfrom
sohailshk:fix/cachestore-size-after-delete
Open

sohailshk wants to merge 1 commit into
zarr-developers:mainfrom
sohailshk:fix/cachestore-size-after-delete

Conversation

@sohailshk

Copy link
Copy Markdown

Summary

_remove_from_tracking removed keys without reducing current_size. This caused incorrect cache-size tracking after deletion, or when a source key is missing.

import asyncio
from zarr.core.buffer import default_buffer_prototype
from zarr.experimental.cache_store import CacheStore
from zarr.storage import MemoryStore

async def main():
    p = default_buffer_prototype()
    s = CacheStore(MemoryStore(), cache_store=MemoryStore(), max_size=100)
    await s.set("a", p.buffer.from_bytes(b"x" * 60))
    await s.delete("a")
    print(s.cache_info()["current_size"])   # main: 60, expected 0
    await s.set("b", p.buffer.from_bytes(b"x" * 60))
    print(s.cache_info()["current_size"])   # main: 120 with max_size=100, expected 60

asyncio.run(main())

Subtract the entry size inside _remove_from_tracking and remove the duplicate subtraction from delete_dir.

Tests: 2 new tests fail on main; the whole tests/test_experimental/test_cache_store.py file passes with the fix (61 passed).

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