Repository navigation
Use global stopMergesAndWait in replacePartitionFrom to fix race - #97105
Conversation
…eplacePartitionFrom` The per-partition blocker has a race: in `scheduleDataProcessingJob`, a mutation can be selected inside `currently_processing_in_background_mutex`, but the per-partition `isCancelledForPartition` check happens outside the mutex. This allows a mutation to slip through after the blocker is set but before `removePartsInRangeFromWorkingSet` runs, "resurrecting" old data. The global blocker's `isCancelled` check is inside the mutex, preventing any mutation from being selected while the blocker is active. Co-Authored-By: Claude Opus 4.6 <[email protected]>
|
Workflow [PR], commit [35b9687] Summary: ❌
|
| merges_blocker = stopMergesAndWaitForPartition(partition_id); | ||
| } | ||
|
|
||
| /// We use the global `stopMergesAndWait` (not the per-partition variant) because the |
There was a problem hiding this comment.
This is a big change.
There was a problem hiding this comment.
I think it essentially undoes some incorrect optimizations from someone of @Enmk @zvonand @ilejn @MyroTk @myrrc @mkmkme @arthurpassos @ianton-ru.
|
I don't understand how this patch fixes the race.
Looks like CI proves that the fix doesn't work, but degrade existing workloads: https://play.clickhouse.com/play?user=play#U0VMRUNUIGNoZWNrX3N0YXJ0X3RpbWUsIHB1bGxfcmVxdWVzdF9udW1iZXIsIGNoZWNrX25hbWUsIHRlc3RfbmFtZSwgdGVzdF9zdGF0dXMsIHJlcG9ydF91cmwgRlJPTSBjaGVja3Mgd2hlcmUgdGVzdF9uYW1lID0gJzAzOTIwX3JlcGxhY2VfcGFydGl0aW9uX211dGF0aW9uX3JhY2UnIGFuZCBjaGVja19zdGFydF90aW1lID49IHRvRGF0ZVRpbWUoJzIwMjYtMDEtMDEgMDA6MDA6MDAnKSBhbmQgdGVzdF9zdGF0dXMgaW4gKCdGQUlMJywgJ0VSUk9SJykgYW5kIHB1bGxfcmVxdWVzdF9udW1iZXIgIT0gOTY5NTUgb3JkZXIgYnkgY2hlY2tfc3RhcnRfdGltZSA7 |
Summary
stopMergesAndWaitForPartitionwithstopMergesAndWaitinreplacePartitionFromto fix a remaining race condition from Fix race between REPLACE PARTITION and background mutations #96955scheduleDataProcessingJobhappens outsidecurrently_processing_in_background_mutex, allowing a mutation to slip through after the blocker is set but beforeremovePartsInRangeFromWorkingSetremoves old partsDetails
PR #96955 moved the
ActionLock merges_blockerto function scope, but the test03920_replace_partition_mutation_racestill failed ~20% of the time. The root cause:stopMergesAndWaitForPartitionusescancelForPartition, which only sets a per-partition blocker. InscheduleDataProcessingJob, the globalisCancelled()check (line 1714) is inside the mutex, but the per-partitionisCancelledForPartition()check (lines 1736-1742) is outside the mutex. This creates a race window where a mutation can be selected inside the mutex, pass the per-partition check outside the mutex, and get scheduled after the blocker was set.Using
stopMergesAndWait()(global blocker) instead eliminates this race because the globalisCancelled()check is insidecurrently_processing_in_background_mutex, preventing any mutation from being selected while the blocker is active.Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes to CHANGELOG.md):
Fix remaining race condition between
REPLACE PARTITIONand background mutations inMergeTreetables that could cause old data to reappear.🤖 Generated with Claude Code
Version info
26.2.1.909