Skip to content

Fix Deadlock in Parquet::ReadManager in the stages before ColumnData - #133083

Merged
nickitat merged 3 commits into
masterfrom
fix-parquet-privileged-early-stages
Nov 20, 2026
Merged

nickitat merged 3 commits into
masterfrom
fix-parquet-privileged-early-stages

Conversation

@nickitat

@nickitat nickitat commented Nov 19, 2026 •

Copy link
Copy Markdown
Member

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 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, the later one waited in ColumnData to become first, and the reader threw Deadlock in Parquet::ReadManager. It needs 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 now privileged in them unconditionally, as before that commit.

Locally, a clickhouse-local stress 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):

  • Bug Fix (user-visible misbehavior in an official stable release)

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

Fix a Deadlock in Parquet::ReadManager exception when reading Parquet files with a small input_format_parquet_memory_high_watermark.

🤖 Generated with Claude Code


Workflow [PR]
Sync PR [sync-upstream/pr/133083]

Version info

  • Merged into: 26.12.1.52-master (included in 26.12 and later)

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]>
@clickhouse-gh

clickhouse-gh Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [29417ad]

Summary: ❌

job_name test_name status info comment
Finish Workflow FAIL
python3 ./ci/jobs/scripts/workflow_hooks/new_tests_check.py FAIL IGNORED

AI Review

Summary

PR #133083, reviewed at 29417ad2b09ba02fc410003d5d340aa8f42430d5, lets the first incomplete Parquet row group progress through stages before ColumnData despite memory throttling, resolving the reported scheduling deadlock. No actionable findings. The author reports 100 deadlocks in 6000 queries before the fix and none after; the current smoke test passed Fast test in 0.35 seconds. No local runtime tests were run.

Final Verdict

Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Nov 19, 2026
nickitat and others added 2 commits November 20, 2026 10:34
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]>
@clickhouse-gh

clickhouse-gh Bot commented Nov 20, 2026

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 29417ad2b with master eb7319d04 (stripped binary size, per-symbol sizes and ThinLTO time; compile times per translation unit against the most recent warmup build that recompiled it).

✅ No significant changes.

Binary sizes

programs/clickhouse-stripped: smaller than the master baseline by the known offset between the two builds, so the difference is not shown. A delta that differs from the offset by more than 50% of it is shown, in either direction.

The official master build is compiled with -g and a pull request build is not, and XRay counts debug instructions towards its instrumentation threshold, so master instruments thousands of functions more and its binary is ~0.4% larger no matter what the pull request does.

Compile time of recompiled translation units

7 translation units recompiled, 11 s compile time in total, 7 of them have a recent master baseline.

Job report

@nickitat

Copy link
Copy Markdown
Member Author

@groeneai, please investigate the CI failures in this PR (commit 29417ad) and fix them, or link existing fixes.

CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=133083&sha=29417ad2b09ba02fc410003d5d340aa8f42430d5&name_0=PR

Failures without a known issue:

  • python3 ./ci/jobs/scripts/workflow_hooks/new_tests_check.py in Finish Workflow

@nickitat
nickitat added this pull request to the merge queue Nov 20, 2026
Merged via the queue into master with commit d46e8a8 Nov 20, 2026
382 of 385 checks passed
@nickitat
nickitat deleted the fix-parquet-privileged-early-stages branch November 20, 2026 14:07
@robot-ch-test-poll4 robot-ch-test-poll4 added the pr-synced-to-cloud The PR is synced to the cloud repo label Nov 20, 2026
@groeneai

Copy link
Copy Markdown
Collaborator

The only failure on 29417ad is new_tests_check.py. Both Bugfix validation (functional tests, amd64) and (aarch64) ran 05836_parquet_deadlock_first_row_group_early_stage on master HEAD and it passed there ("Bug does not reproduce on this arch"), so no job reported OK/XFAIL and the post-hook failed. That is expected for a test that rarely hits the race; nothing else failed, and there is nothing to fix in CI.

The deadlock can be made deterministic with one parsing thread. If only the last row group has NULLs in s and s is read as non-nullable, that row group skips the bloom filter stages, takes the Dictionary memory first and then waits in ColumnData, while row group 0 waits in Dictionary:

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 clickhouse local the SELECT throws Deadlock in Parquet::ReadManager (single-threaded) in 20 of 20 runs with a debug build of master e627fea (dump: rg[0] in Dictionary, rg[1] in BloomFilterBlocks, rg[2] in ColumnData) and returns count() = 3 in 20 of 20 runs with this PR's amd_debug build. Reading s as Nullable(String), or the same file without NULLs, does not deadlock. Do you want me to send it as a test-only follow-up PR?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp-parquet-reader-v3 Issues related to the native Parquet reader. pr-bugfix Pull request with bugfix, not backported by default pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Logical error: Deadlock in Parquet::ReadManager with randomized Parquet reader settings

3 participants