fix: implement soft-delete for ZipStore (issue #828)#4107
Open
mohammadZuherJaserAsad wants to merge 3 commits into
Open
fix: implement soft-delete for ZipStore (issue #828)#4107mohammadZuherJaserAsad wants to merge 3 commits into
mohammadZuherJaserAsad wants to merge 3 commits into
Conversation
Implement soft-delete via b"" overwrite. supports_deletes=True. Update _get, exists, list, delete, delete_dir.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #4107 +/- ##
==========================================
- Coverage 93.53% 85.12% -8.41%
==========================================
Files 88 90 +2
Lines 11894 15090 +3196
==========================================
+ Hits 11125 12846 +1721
- Misses 769 2244 +1475
🚀 New features to boost your workflow:
|
Contributor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #828 — implements soft-delete for
ZipStoreso thatdelete()anddelete_dir()no longer raiseNotImplementedError.The ZIP format has no native entry-removal API (a known CPython limitation: python/cpython#51067). This PR uses the soft-delete approach suggested by @dcherian in the issue: overwrite the entry with an empty byte sentinel (
b"") and filter it out in all read, exists, and list paths.Changes
src/zarr/storage/_zip.pysupports_deletes = True(wasFalse)_SOFT_DELETE_SENTINEL = b""constantdelete(key): writes sentinel to zip entry; no-op if key is absentdelete_dir(prefix): collects live keys under prefix, callsdelete()on each_get(): reads all bytes first; returnsNoneif content equals sentinelexists(): returnsFalsefor entries whose content equals sentinellist(): deduplicates entries (duplicate names can appear after overwrites) and skips sentinel entrieslist_dir(): consumes filteredlist()output for consistencytests/test_store/test_zip.pydelete_dir, andlist()filteringtest_api_integrationupdated: removed twopytest.raises(NotImplementedError)blocks that are no longer correcttests/test_store/test_stateful.pypytest.skip(reason="ZipStore does not support delete")blocksDesign notes
namelist()returns the name twice.NameToInfotracks the last-written entry, so reading always returns the sentinel.list()uses aseenset to yield each name at most once.delete_dir()holds theRLockwhile callinglist_prefix()and thendelete()(which also acquires it). This works becausethreading.RLockis re-entrant for the same thread.set_if_not_existsedge case: After a soft-delete the name is still innamelist(), soset_if_not_existswill not re-write it. This matches the documented semantics and existing zarr usage patterns.Testing
pytest tests/test_store/test_zip.py -v pytest tests/test_store/test_stateful.py -v -k "not slow_hypothesis"