Skip to content

fix(chunk_engine): preserve pending removal intent across uncommitted chunk recovery - #462

Merged
SF-Zhou merged 1 commit into
deepseek-ai:mainfrom
ApacheWang:fix/chunk-engine-uncommitted-remove
Nov 27, 2026
Merged

SF-Zhou merged 1 commit into
deepseek-ai:mainfrom
ApacheWang:fix/chunk-engine-uncommitted-remove

Conversation

@ApacheWang

Copy link
Copy Markdown
Contributor

Summary

Persist pending is_remove intent in the writing_chunk journal and restore it during uncommitted chunk recovery (Engine::open and Engine::handle_uncommitted_chunks), preventing aborted or crashed uncommitted removals from resurrecting deleted chunks or creating phantom zero-length chunks.

Root Cause

When an uncommitted removal (UpdateReq { is_remove: true }) is started via Engine::update_chunk, MetaStore::persist_writing_chunk previously serialized only ChunkMeta and WritingHolder did not record is_remove. If the operation aborted or the storage node crashed before commit_chunk(s), Engine::handle_uncommitted_chunks reconstructed WritingChunk with is_remove: false, committing the chunk as a live 0-byte chunk instead of applying the pending deletion.

Changes

  • src/storage/chunk_engine/src/meta/meta_store.rs:
    • Introduce UncommittedChunk and append an optional 1-byte WRITING_REMOVE_MARKER trailer after ChunkMeta in persist_writing_chunk only when is_remove == true (preserving exact legacy byte layout for ordinary writes and full backward compatibility on read).
    • Decode the optional trailer in query_uncommitted_chunks and carry is_remove through occupy_uncommitted_positions / vacate_uncommitted_positions.
  • src/storage/chunk_engine/src/alloc/writing_chunk.rs & src/storage/chunk_engine/src/core/engine.rs:
    • Track is_remove on WritingHolder.
    • Persist remove-intent transitions to the journal before publishing into writing_list.
    • Batch non-existent chunk journal cleanup via remove_writing_chunk_mut inside commit_chunks.
    • Propagate holder.is_remove when constructing WritingChunk in handle_uncommitted_chunks.
    • Add regression tests test_engine_recovers_aborted_uncommitted_removes and test_engine_recovers_uncommitted_removes_after_reopen covering existing chunk deletion, missing chunk cleanup, overwriting an aborted removal with an ordinary zero-length write, and used_size accounting.

Verification

Rebased on main (cdded47) and ran the full chunk_engine unit test suite:

cd src/storage/chunk_engine && cargo test -- --test-threads=1
# test result: ok. 49 passed; 0 failed; 0 ignored

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.

… chunk recovery

Signed-off-by: bc15575202581 <bc15575202581@gmail.com>

@SF-Zhou SF-Zhou left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

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.

2 participants