Repository navigation
Fix Deadlock in Parquet::ReadManager in the stages before ColumnData - #133083
Conversation
The scheduler avoids deadlocks by always letting the first incomplete row group schedule its tasks, whatever the memory usage. Since e7a7ac3 this exemption applied only from `ColumnData` on. Before that, a later row group could get through the bloom filter and `Dictionary` stages first and hold the `Dictionary` stage's memory. The first incomplete row group then waited for that memory in `Dictionary`, while the later row group waited in `ColumnData` to become first, and the reader threw `Deadlock in Parquet::ReadManager`. This is reachable with a small `input_format_parquet_memory_high_watermark`, which CI randomizes since #132712. The stages before `ColumnData` handle the whole row group at once, so the first incomplete row group is privileged in them unconditionally, as it was before e7a7ac3. The new test deadlocked in 4 of 10 runs without the fix, and passed 20 of 20 (with and without settings randomization) with it. In a `clickhouse-local` stress run on a 298-row-group file: 100 deadlocks in 6000 runs before, 0 in 6000 after. CI report: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=133069&sha=a6c84af029f9bdc3526b34b1df2eae0b4b281294&name_0=PR&name_1=Stateless%20tests%20%28arm_binary%2C%20ParallelReplicas%2C%20plan-based%2C%20s3%20storage%2C%20parallel%29 PR: #133069 Closes: #133046 Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Workflow [PR], commit [29417ad] Summary: ❌
AI ReviewSummaryPR #133083, reviewed at Final VerdictStatus: ✅ Approve |
With a 1-byte `input_format_parquet_memory_high_watermark`, the reader schedules roughly one task batch per row group and stage, about 32k batches per query on the 3000-row-group file. In the flaky check, where many copies of the test run at once, those batches stalled on thread-pool locks (145 s of `LocalThreadPoolLockWaitMicroseconds` in one query) and each query took 250-500 s, so the test timed out on every build. The test now reads 30 row groups with 4 concurrent queries. It is a smoke test of this scheduling path; at this size it rarely hits the race itself. CI report: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=133083&sha=latest&name_0=PR PR: #133083 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units7 translation units recompiled, 11 s compile time in total, 7 of them have a recent master baseline. |
|
The only failure on 29417ad is The deadlock can be made deterministic with one parsing thread. If only the last row group has NULLs in INSERT INTO FUNCTION file('t.parquet', Parquet, 'id UInt64, s Nullable(String), u String')
SELECT number, if(number >= 200 AND number % 10 = 5, NULL, toString(number % 100)), toString(intDiv(number, 7) % 50)
FROM numbers(300)
SETTINGS output_format_parquet_row_group_size = 100, output_format_parquet_write_bloom_filter = 1;
SELECT count(), sum(cityHash64(u)) FROM file('t.parquet', Parquet, 'id UInt64, s String, u String')
WHERE s = '12'
SETTINGS input_format_parquet_memory_low_watermark = 0, input_format_parquet_memory_high_watermark = 1,
max_parsing_threads = 1, max_threads = 1;In |
The Parquet reader avoids scheduling deadlocks by always letting the first incomplete row group schedule its tasks, whatever the memory usage. Since e7a7ac39e463e this applied only from
ColumnDataon. Before that, a later row group could get through the bloom filter andDictionarystages first and hold theDictionarystage's memory: the first incomplete row group then waited for that memory inDictionary, the later one waited inColumnDatato become first, and the reader threwDeadlock in Parquet::ReadManager. It needs a smallinput_format_parquet_memory_high_watermark, which CI randomizes since #132712.The stages before
ColumnDatahandle the whole row group at once, so the first incomplete row group is now privileged in them unconditionally, as before that commit.Locally, a
clickhouse-localstress run gave 100 deadlocks in 6000 queries before the fix and 0 in 6000 after. On a 3000-row-group file, 32 concurrent queries deadlocked 19 times without the fix and none with it. The new test reads only 30 row groups so that it stays cheap in the flaky check; it is a smoke test of this scheduling path and rarely hits the race itself.CI report: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=133069&sha=a6c84af029f9bdc3526b34b1df2eae0b4b281294&name_0=PR&name_1=Stateless%20tests%20%28arm_binary%2C%20ParallelReplicas%2C%20plan-based%2C%20s3%20storage%2C%20parallel%29
Closes: #133046
Related: #133069
Related: #132712
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fix a
Deadlock in Parquet::ReadManagerexception when reading Parquet files with a smallinput_format_parquet_memory_high_watermark.🤖 Generated with Claude Code
Workflow [PR]
Sync PR [sync-upstream/pr/133083]
Version info
26.12.1.52-master(included in26.12and later)