mirror of
https://github.com/deepseek-ai/3FS.git
synced 2026-11-05 00:47:47 +00:00
[PR #322] [MERGED] Fix race condition in chunk removal and compaction leading to metadata corruption #369
Labels
No labels
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
deepseek-ai/3FS#369
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/deepseek-ai/3FS/pull/322
Author: @cccshuang
Created: 8/19/2025
Status: ✅ Merged
Merged: 8/19/2025
Merged by: @SF-Zhou
Base:
main← Head:bugfix-chunk-removal-and-compaction-race-condition📝 Commits (2)
5ae844cFix race condition in chunk removal and compaction leading to metadata corruption44f0781remove useless enumerate in batch_remove📊 Changes
1 file changed (+14 additions, -9 deletions)
View changed files
📝
src/storage/chunk_engine/src/core/engine.rs(+14 -9)📄 Description
Issue
When performing chunk deletion alongside compaction in the
chunk_engineof the storage component, metadata inconsistency issues can occur due to a race condition.Specifically:
ck1) may still appear in the metadata as if it exists.pos1) previously used byck1is later reused by another chunk (ck2).ck1 → pos1,ck2 → pos1.Root Cause
The issue arises from a concurrency problem between:
commit_chunkmove_chunkBoth operations modify the
meta_storeandmeta_cache, but their updates are not atomic and lack proper synchronization. For example:commit_chunkdeletesck1from the store but leaves it in the cache;github.com/deepseek-ai/3FS@394583dbf0/src/storage/chunk_engine/src/core/engine.rs (L475-L480)move_chunkchecks the cache and mistakenly assumesck1is valid;github.com/deepseek-ai/3FS@394583dbf0/src/storage/chunk_engine/src/core/engine.rs (L230-L240)ck1, causing corruption.A similar issue also exists in
batch_remove.github.com/deepseek-ai/3FS@394583dbf0/src/storage/chunk_engine/src/core/engine.rs (L666-L670)Example Flow
commit_chunk, check ifchunk.is_removedmeta_store:ck1 -> pos1,pos1 -> ck1meta_cachelockchunk1exists in the cache. If yes:meta_store:- Remove
ck1 -> pos1,pos1 -> ck1- Insert
ck1 -> pos2,pos2 -> ck1ck1 -> pos2meta_cachelockmeta_cachelockChunkArcreference count drops to zero, chunk is dereferenced, releasingpos1andpos2meta_cachelockchunk1no longer exists in cache, but metadata still containsck1 -> pos2,pos2 -> ck1pos2, insert metadatack2 -> pos2,pos2 -> ck2, overwritingpos2 -> ck1chunk1no longer exists in cache, but metadata still containsck1 -> pos2Solution
This PR introduces proper locking around
commit_chunkandbatch_removeoperations to ensure all changes tometa_cacheandmeta_storeare synchronized and atomic. This prevents race conditions and ensures consistent metadata across concurrent chunk removal and compaction's move chunk workflows.🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.