DictStore: a multi-chunk external leaf can be read across a concurrent overwrite, mixing two generations
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 5/5
- Thời gian dự kiến
- Hơn một tuần
- Mức phù hợp với người mới
- 35/100
Hướng nghiên cứu
Bắt đầu với DictStore.getitem, đường dẫn đọc chunk ở lớp C và bài kiểm thử hiện có test_dict_store_read_during_overwrite; tái hiện trường hợp nhiều chunk được mô tả trong issue. Thay đổi được xem là hoàn tất khi các lần ghi đè đồng thời không còn khiến một lần đọc kết hợp các chunk từ các thế hệ khác nhau, đồng thời xem xét workaround locking đã được ghi chép và các hướng dẫn bị ảnh hưởng.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Overwriting an external DictStore leaf while another process reads it can hand that reader an array assembled from two different generations of the value. No error is raised and the data is not corrupt — the array simply never existed as a stored value.
Cause
The handle DictStore.__getitem__ returns holds no file descriptor. The C layer re-opens the leaf by path for every chunk it decompresses, so one arr[:] over an N-chunk leaf is N independent opens. A concurrent __setitem__ on the same key swaps a new leaf into place between two of those opens, and the read takes its low chunks from the old file and its high chunks from the new one.
This is the layer underneath #692. That one was about readers hitting a partial file and failing with RuntimeError: Error while getting the buffer; the fix (build the leaf beside its final name, os.replace() it in) made every file a reader can open complete. Chunks now decompress correctly — but not necessarily all from the same generation.
Reproducer
A 40-chunk leaf, one reader handle, a writer process atomically replacing the file in a loop. Each generation i is np.full(N, i), so any mix is visible as more than one distinct value:
N, CHUNK = 4_000_000, 100_000
blosc2.asarray(np.full(N, 0, dtype=np.int64), chunks=(CHUNK,), urlpath=path, mode="w")
handle = blosc2.open(path, mode="r")
# writer process, in a loop:
# blosc2.asarray(np.full(N, i, dtype=np.int64), chunks=(CHUNK,), urlpath=tmp, mode="w")
# os.replace(tmp, path)
data = handle[:]
assert len(np.unique(data)) == 1 # fails
Result on an M4 Pro (macOS, blosc2 4.10.1.dev0):
TORN on read 27: generations [34 35] ... (2 distinct)
reads=249 torn=38 runtime_errors=0
38 of 249 reads straddled a swap. runtime_errors=0 confirms the atomic replace is working; this is a separate failure mode.
Scope
- Needs a concurrent overwrite of the same key — a write-then-read store never sees it.
- Single-chunk leaves are immune (one open per read). That is why
test_dict_store_read_during_overwritenever caught it: its leaf is 800 bytes. - Scales the wrong way: the bigger the leaf, the more opens per read and the wider the window.
Possible fixes
- Versioned leaf names (
hot.<tick>.b2nd): an overwrite writes a new path, and the reader keeps reading the generation it resolved under the lock. The real fix — MVCC in effect — at the cost of a reclamation story for stale versions. - Hold the store lock across the whole read:
__getitem__could no longer return a lazy handle; callers would need a context manager or a read-into-memory API.
Documented as an accepted race for now (DictStore docstring and the "Sharing Containers Across Processes" guide), with holding_lock() around a copy-out as the workaround.
- Ngôn ngữ chính
- Python
- Star
- 211
- Fork
- 63
- Merge trung bình
- 1 ngày 7 giờ
- Pull request đã merge (30 ngày)
- 5
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của Blosc/python-blosc2
-
Improve the remote array guide Đang mởdocumentation sustain-2026
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
Blosc/python-blosc2#710 ·
-
documentation sustain-2026
Độ khó 2/5 Nửa ngày Mức phù hợp với người mới 74/100
Blosc/python-blosc2#651 · 1 bình luận ·
-
documentation good first issue sustain-2026
Độ khó 2/5 Nửa ngày Mức phù hợp với người mới 74/100
Blosc/python-blosc2#650 ·
-
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 35/100
Blosc/python-blosc2#689 ·
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 48/100
Blosc/python-blosc2#664 · 1 bình luận ·
Tất cả issue của Blosc/python-blosc2
Issue tương tự
-
documentation help wanted
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 90/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 90/100
simonw/sqlite-utils#872 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100