Skip to content

Fix flaky test_storage_iceberg_concurrent (thread-pool oversubscription) - #108075

Merged
alexey-milovidov merged 1 commit into
ClickHouse:masterfrom
groeneai:fix-flaky-test_storage_iceberg_concurrent-thread-oversubscription
Jun 22, 2026
Merged

alexey-milovidov merged 1 commit into
ClickHouse:masterfrom
groeneai:fix-flaky-test_storage_iceberg_concurrent-thread-oversubscription

Conversation

@groeneai

@groeneai groeneai commented Jun 21, 2026 •

Copy link
Copy Markdown
Collaborator

Changelog category (leave one):

  • CI Fix or Improvement (changelog entry is not required)

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

...

Description

Requested by @ alexey-milovidov on #108049 (the failure surfaced there; the ZSTD PR is unrelated).

test_storage_iceberg_concurrent::test_concurrent_reads runs 25 concurrent SELECT * queries against one accumulating Iceberg table while 15 Spark writers commit in parallel, for 10 rounds. By default each SELECT fans out to ~max_threads (number of CPU cores) internal read threads, so 25 simultaneous readers request hundreds of threads at once. On a loaded CI shard this oversubscribes the global thread pool and a single SELECT gets starved past the 300s client receive_timeout:

QueryRuntimeException: Return code: 159 ... Timeout exceeded while receiving data from server.
Waited for 312 seconds, timeout is 300 seconds. (query: SELECT * FROM test_concurrent_reads_s3_...)

Timeout-class failures (30d), all on the loaded amd_asan_ubsan, db disk, old analyzer, 5/6 shard:

Fix: pin max_threads=4 on the concurrent SELECT so the readers' aggregate thread demand stays bounded. This does not change what the test verifies: all 25 readers still race all 15 writers across every round and the exact row-count assertion is unchanged. Only the per-query intra-read parallelism is capped, which is irrelevant to concurrent-read snapshot consistency.

Local validation (debug build, both directions):

  • Pristine test: FAILS at round 2 with Code 439 CANNOT_SCHEDULE_TASK (threads=1000, jobs=1000) (the same oversubscription, manifesting as outright thread-pool exhaustion on my 96-core box).
  • With max_threads=4: PASSES all 10 rounds, twice (147s, 152s).

Version info

  • Merged into: 26.6.1.1096

test_concurrent_reads runs 25 concurrent SELECT * queries against one
accumulating Iceberg table while 15 Spark writers commit in parallel, for
10 rounds. By default each SELECT fans out to ~max_threads (number of CPU
cores) internal read threads, so 25 simultaneous readers request hundreds
of threads at once. On a loaded CI shard this oversubscribes the global
thread pool: a single SELECT either gets starved past the 300s client
receive_timeout (Return code 159, seen on the asan/db-disk/old-analyzer 5/6
shard for PRs ClickHouse#100651 and ClickHouse#108049 and on master) or the server rejects the
query outright with CANNOT_SCHEDULE_TASK (Code 439, threads=1000, jobs=1000).

Pin max_threads=4 on the concurrent SELECT so the readers' aggregate thread
demand stays bounded. This does not change what the test verifies: all 25
readers still race all 15 writers across every round and the exact row-count
assertion is unchanged. Only the per-query intra-read parallelism is capped,
which is irrelevant to concurrent-read snapshot consistency.

Locally reproduced both directions on a debug build: pristine test fails at
round 2 with CANNOT_SCHEDULE_TASK; with the cap it passes all 10 rounds
(~150s).
@groeneai

Copy link
Copy Markdown
Collaborator Author

Pre-PR validation gate

# Question Answer
a Deterministic repro? Yes. On a debug build, the pristine test FAILS at round 2 with Code 439 CANNOT_SCHEDULE_TASK (threads=1000, jobs=1000) every run; with the cap it PASSES all 10 rounds. CI shows the same oversubscription as Return code 159 ... Timeout exceeded while receiving data from server. Waited for 312/333s, timeout is 300s on a single SELECT *.
b Root cause explained? Yes. The test issues 25 concurrent SELECT * per round; each defaults to max_threads ≈ CPU-core count internal read threads. 25 simultaneous readers demand hundreds of threads at once. Under load (the asan/db-disk/old-analyzer 5/6 shard, or my 96-core box) this oversubscribes the global thread pool, so one SELECT is starved past the 300s client receive_timeout (CI) or rejected outright with CANNOT_SCHEDULE_TASK (local).
c Fix matches root cause? Yes. max_threads=4 on the concurrent SELECT directly bounds the aggregate thread demand of the 25 readers — the exact mechanism in (b). Not a timeout bump, not a data-size reduction, not a no-parallel/no-random tag.
d Test intent preserved / new tests added? Yes, preserved. All 25 readers still race all 15 Spark writers across every round; the exact row-count assertion (rows_in_ch == expected_rows) is unchanged. Only per-query intra-read parallelism is capped, which is irrelevant to concurrent-read snapshot consistency (what the test verifies).
e Both directions demonstrated? Yes. Pristine: FAILS at round 2 (CANNOT_SCHEDULE_TASK). With max_threads=4: PASSES all 10 rounds twice (147.49s, 152.42s). Both runs on the same debug binary (Build ID 43efb5c8).
f Fix is general, not a narrow patch? This is the only test in the iceberg-concurrent family with the 25×SELECT * reader storm; the fix is scoped to exactly the queries that cause the oversubscription. No source code is touched, so no sibling code-path generalization applies.

Session id: cron:clickhouse-worker-slot-0:20260621-210600

@groeneai

Copy link
Copy Markdown
Collaborator Author

cc @divanik — could you review this test-only fix? It pins max_threads=4 on the 25 concurrent SELECT * queries in test_concurrent_reads so they don't oversubscribe the global thread pool and time out under load on the asan/db-disk/old-analyzer 5/6 shard.

@alexey-milovidov alexey-milovidov added the can be tested Allows running workflows for external contributors label Jun 21, 2026
@alexey-milovidov alexey-milovidov self-assigned this Jun 21, 2026
@clickhouse-gh

clickhouse-gh Bot commented Jun 21, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [0ee2f26]

Summary: ✅


AI Review

Summary
  • This PR caps max_threads on the 25 concurrent Iceberg SELECT * readers in test_storage_iceberg_concurrent::test_concurrent_reads, bounding the reader fan-out that the PR identifies as the source of CI thread-pool oversubscription. The changed query path is the intended one, the 15 concurrent writers and 10 rounds are unchanged, and the final count() assertion still checks the same row-count invariant. I found no review-blocking issue in the current diff or prior discussion.
Final Verdict
  • Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-ci label Jun 21, 2026
@clickhouse-gh

clickhouse-gh Bot commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 85.30% 85.20% -0.10%
Functions 92.60% 92.50% -0.10%
Branches 77.50% 77.50% +0.00%

Changed lines: No C/C++ source files changed — skipping uncovered code analysis.

Newly covered by added/modified tests: 300 line(s), 19 function(s) across 104 file(s) · Details

Top files
  • src/Storages/StorageReplicatedMergeTree.cpp: 34 line(s)
  • src/Storages/WindowView/StorageWindowView.cpp: 22 line(s), 1 function(s)
  • src/Coordination/FourLetterCommand.cpp: 21 line(s), 2 function(s)
  • src/Storages/MergeTree/ReplicatedMergeTreeQueue.cpp: 11 line(s)
  • src/Parsers/parseFieldFromCastedLiteral.cpp: 10 line(s), 11 function(s)

Full report

@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Jun 22, 2026
Merged via the queue into ClickHouse:master with commit a1b1535 Jun 22, 2026
166 checks passed
@robot-ch-test-poll robot-ch-test-poll added the pr-synced-to-cloud The PR is synced to the cloud repo label Jun 22, 2026
alexey-milovidov added a commit that referenced this pull request Jun 22, 2026
Refresh CI on the latest master. The previous run's only red was a job-level
cancellation of the 'Integration tests (amd_asan_ubsan, db disk, old analyzer, 5/6)'
shard: test_storage_iceberg_concurrent/test_concurrent_reads hung (the known-flaky
test fixed by the merged #108075), which pushed the shard past its time budget and
caused the operation to be canceled; the in-flight tests (test_huge_concurrent_restore,
test_azure_disk_unreachable) were marked failed only because of that cancellation.
This merge brings in #108075 (merged after the previous merge-base), which fixes the
hang. The DESCRIBE parser code is unchanged - master touched none of the PR's three
files, so the merge net diff vs master is exactly those files, byte-identical.
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
Refresh CI on the latest master. The previous run's only red was a job-level
cancellation of the 'Integration tests (amd_asan_ubsan, db disk, old analyzer, 5/6)'
shard: test_storage_iceberg_concurrent/test_concurrent_reads hung (the known-flaky
test fixed by the merged ClickHouse#108075), which pushed the shard past its time budget and
caused the operation to be canceled; the in-flight tests (test_huge_concurrent_restore,
test_azure_disk_unreachable) were marked failed only because of that cancellation.
This merge brings in ClickHouse#108075 (merged after the previous merge-base), which fixes the
hang. The DESCRIBE parser code is unchanged - master touched none of the PR's three
files, so the merge net diff vs master is exactly those files, byte-identical.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

can be tested Allows running workflows for external contributors pr-ci 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.

3 participants