Repository navigation
fix(chunk_engine): copy-on-write shrinking truncate to protect pinned concurrent readers - #461
Merged
SF-Zhou merged 1 commit intoNov 27, 2026
Conversation
… concurrent readers Signed-off-by: bc15575202581 <bc15575202581@gmail.com>
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
Route shrinking
truncateoperations (req.is_truncate && req.offset < old_chunk.meta().len) throughChunk::copy_on_writeinstead of mutating the existing chunk in place.Root Cause
Previously,
Chunk::safe_writehandled shrinking truncates in place by mutatingself.meta.lenandself.meta.checksumon the existing chunk slot. If a concurrent reader still holds a pinnedChunkArcreferencing that slot (or before commit completes), mutating the backing position/metadata breaks copy-on-write snapshot isolation for pinned readers.Changes
src/storage/chunk_engine/src/alloc/chunk.rs:Chunk::copy_on_writewith atruncate: boolflag so shrinking truncates allocate a new chunk of sizeoffset, copy the retained[0..offset]prefix, zero-fill alignment padding, recompute the CRC32C checksum, and keep incrementingmetrics.safe_write_truncate_shorten.Chunk::safe_writewithError::InvalidArg("shrinking truncate requires copy-on-write").src/storage/chunk_engine/src/core/engine.rs:copy_on_writeinEngine::update_chunkwhenreq.is_truncate && req.offset < old_chunk.meta().len, while preserving the existing in-place path for extending truncates.test_engine_truncate_shrink_preserves_readerandtest_engine_truncate_extend_in_place.Verification
Rebased on
main(cdded47) and ran the fullchunk_engineunit test suite:AI-assisted development disclosure: AI coding tools assisted with root-cause analysis, patch drafting, and regression test authoring; all changes and tests were reviewed and verified locally.