Fix race condition in sharded hashed dictionary parallel loading#96953
Merged
alexey-milovidov merged 2 commits intomasterfrom Feb 15, 2026
Merged
Fix race condition in sharded hashed dictionary parallel loading#96953alexey-milovidov merged 2 commits intomasterfrom
alexey-milovidov merged 2 commits intomasterfrom
Conversation
…em.session_log` The `DELETE FROM system.session_log` cleanup at the start of test `02835_drop_user_during_session` creates a synchronous lightweight delete mutation. In ASan stress tests, `system.session_log` receives continuous writes from all concurrent test sessions, causing the mutation to take over 12 minutes. Even though the query gets cancelled (`is_cancelled: 1`), it remains stuck in `StorageMergeTree::waitForMutation`. Fix by making the cleanup DELETE non-blocking with `lightweight_deletes_sync = 0`. This is safe because the test user name includes the PID (`$$`), making collisions from PID reuse extremely unlikely during a single stress test run. https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=96926&sha=724c57e90613f66e2ef897f80a644ba21e98b470&name_0=PR&name_1=Stress%20test%20%28arm_asan%2C%20s3%29 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
There was a TOCTOU race in the worker thread loop: after `tryPop` timed out (confirming the queue was empty), a context switch could allow the main thread to push the final block and call `finish()` before the worker checked `isFinished()`. The worker would then see the queue as finished and exit, leaving the last block unprocessed. This caused occasional loss of ~2000-3000 rows (one shard's portion of the last source block) in sharded dictionaries loaded in parallel. The fix replaces `isFinished()` with `isFinishedAndEmpty()`, which atomically verifies both that the queue is marked finished AND that no items remain. If items were pushed between the `tryPop` timeout and this check, the worker correctly retries and processes them. Closes #84468 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Contributor
Member
Author
|
Amazing finding! |
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
tryPopcould time out on an empty queue, then between checkingisFinished(), the main thread could push the last block and callfinish()— causing the worker to exit with unprocessed blocks still in the queueisFinished()withisFinishedAndEmpty()to atomically verify both that the queue is finished AND empty before the worker exitsCloses #84468
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fix a race condition in sharded
HASHEDdictionary parallel loading that could occasionally cause some rows to not be loaded.🤖 Generated with Claude Code