Skip to content

fix(chunk_engine): persist writing journal before publishing the holder - #466

Closed
SF-Zhou wants to merge 1 commit into
deepseek-ai:mainfrom
SF-Zhou:fix/chunk-engine-persist-journal-before-publish
Closed

SF-Zhou wants to merge 1 commit into
deepseek-ai:mainfrom
SF-Zhou:fix/chunk-engine-persist-journal-before-publish

Conversation

@SF-Zhou

@SF-Zhou SF-Zhou commented Nov 27, 2026

Copy link
Copy Markdown
Collaborator

Summary

Engine::update_chunk inserted the in-memory WritingHolder before persisting the writing-chunk journal. If the RocksDB put failed, the holder stayed in writing_list with abort = false: the chunk looked uncommitted, query_all_chunks reported a phantom pending version, and every later update returned InvalidArg("chunk ... is in writing") until the process restarted.

Root Cause

The update path had no rollback for the holder registration: persist_writing_chunk was called after writing_list.entry(...).insert_entry(...) and its error propagated while the in-memory state stayed published.

Changes

  • src/storage/chunk_engine/src/core/engine.rs
    • Persist the journal first and publish the holder only after the put succeeds.
    • This also keeps the ordering introduced for remove intent in fix(chunk_engine): preserve pending removal intent across uncommitted chunk recovery #462: the journal always reflects is_remove before the holder becomes visible.
    • Add test_engine_update_failure_does_not_leave_stuck_writing_holder, using a thread-local test-only fault injection that makes the next journal put fail. The test asserts the writing list and query_uncommitted_chunks stay empty and that the same chunk can be written immediately afterwards.

Verification

cargo test -p chunk_engine --lib
# test result: ok. 55 passed; 0 failed; 0 ignored

The regression test fails when the holder is published before the journal (verified by temporarily restoring the old order). The fault injection is thread-local so parallel tests cannot observe each other's injected failure.

Compatibility

No on-disk format change. Only the failure path changes: a failed journal put now returns the RocksDB error without leaving stale in-memory state.

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.

Engine::update_chunk inserted the in-memory WritingHolder before putting
the writing-chunk journal. When the journal put failed (RocksDB error),
the holder stayed in writing_list with abort=false, so the chunk was
reported as uncommitted and every later update on it failed with
"chunk is in writing" until restart.

Persist the journal first and only publish the holder after it succeeds.
This also keeps the ordering introduced for remove intent: the journal
always reflects is_remove before the holder becomes visible.

Tests: cargo test -p chunk_engine --lib. Add
test_engine_update_failure_does_not_leave_stuck_writing_holder, which
injects a journal persist failure and asserts the writing list stays
empty and the same chunk can be written again. The test fails when the
holder is published before the journal.
@SF-Zhou SF-Zhou closed this Nov 27, 2026
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