Repository navigation
Conversation
PR ClickHouse#107805 sized the parallel replicas reading coordinator by the number of active replicas (excluding registered-but-inactive ones) so mark segments are not assigned to replicas that never participate. The mark_segment_size heuristic in ReadFromMergeTree still derived its work-distribution denominator from getAllNodeCount() (the registered count), so the two sizings disagreed when a replica was registered but inactive. Source ParallelReadingExtension::total_nodes_count from the active replica count via a shared ClusterProxy::getActiveReplicasCountForParallelReplicas helper that mirrors the coordinator sizing (active count when liveness is known, registered count otherwise, with a zero-active safety net). This keeps the segment-size denominator consistent with the coordinator. It cannot go out of range and only makes segments smaller, which balances work no worse. Co-Authored-By: Claude Opus 4.8 <[email protected]>
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-worker-slot-1:20260703-215400 |
|
cc @tiandiwonder @nickitat — this is the optional |
|
Workflow [PR], commit [5d6927b] Summary: ✅
AI ReviewSummaryReviewed #109377 at Missing context / blind spots
Final VerdictStatus: ✅ Approve |
…through it Addresses two parity gaps in the mark-segment-size heuristic raised in review. 1. getActiveReplicasCountForParallelReplicas recomputed only a partial copy of the coordinator's sizing: it excluded inactive replicas but did not force the initiator's own replica active, nor cap by max_parallel_replicas. So total_nodes_count could still diverge from the coordinator (3 active + max_parallel_replicas=2: coordinator 2, helper 3; transient-missing local znode + 1 peer: coordinator forces local back in = 2, helper 1). The coordinator sizing (initiator-force + count + cap) is now factored into two shared free functions (findLocalReplicaIndexForLiveness, countAndCapReplicas) used by both prepareConnectionPoolsForParallelReplicas and the heuristic, so they size by the same count. The two test-only failpoints stay coordinator-only. 2. Both PoolSettings.total_query_nodes populators in ReadFromMergeTree still used min(getAllNodeCount(), max_parallel_replicas), the registered-and-capped count. On remote-disk reads that value drives calculateMinMarksPerTask (sum_marks / (threads * total_query_nodes) / 2), the other half of chooseSegmentSize, so fixing only total_nodes_count left the heuristic partly keyed off the registered count and could be a no-op when that term dominates. Both now use the active-and-capped helper. Tests: extend the local-disk skip-inactive test with a max_parallel_replicas cap case and a total_query_nodes assertion; add an S3-backed test that exercises the remote-disk task-size path (a local-disk test cannot reach it). Verified each new assertion fails before and passes after. Co-Authored-By: Claude Opus 4.8 <[email protected]>
|
Both addressed in 500fb8a. 1. Exact coordinator parity. The coordinator's sizing (initiator-force + count +
The two test-only failpoints stay coordinator-only (not applied in the heuristic; the 2. Remote-disk Tests. The local-disk test cannot reach the remote-disk branch, as you noted, so I added |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-worker-slot-3:20260703-233900 |
merge_tree_min_bytes_per_task_for_remote_reading = 0 made the second term of calculateMinMarksPerTask's min() zero, so heuristic_min_marks collapsed to 0 and total_query_nodes could not change min_marks_per_task or the segment size. The test only proved the total_query_nodes trace line, not the remote-disk outcome finding ClickHouse#2 is about. Use a large positive merge_tree_min_bytes_per_task_for_remote_reading so the marks term wins the min(), pin max_threads = 1, and use a small index granularity so sum_marks / (threads * total_query_nodes) / 2 stays above the floor for both replica counts. Read sum_marks from system.parts and assert the resulting min_marks_per_task equals the active-count value (195) and not the registered-count value (130). Segment size cannot isolate this because number_of_replicas is already the active count; min_marks_per_task is the only quantity total_query_nodes alone drives. Verified: fails before the total_query_nodes fix (logs min_marks_per_task=130), passes after (195).
getActiveReplicasCountForParallelReplicas reads live liveness state, and after routing both total_query_nodes and the ParallelReadingExtension node count through it, ReadFromMergeTree called it at several independent sites within a single read. If a replica dropped or came back between two of those calls, calculateMinMarksPerTask (via PoolSettings.total_query_nodes) and chooseSegmentSize (via ParallelReadingExtension::total_nodes_count) could size against different denominators on the same query. Compute the count once per ReadFromMergeTree step (memoized) and reuse it at every segment-sizing consumer, so both halves of chooseSegmentSize always see the same active-and-capped replica count. Each node builds its own ReadFromMergeTree, so the snapshot stays per-node-per-read. Co-Authored-By: Claude Opus 4.8 <[email protected]>
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 64/84 (76.19%) · Uncovered code |
CI finish ledger — ab625acCI fully finished: Finish Workflow and Mergeable Check both green, no queued/running jobs. There are no failed checks on this head, so no failure needs an owner. All five clickhouse-gh[bot] review findings on earlier commits were addressed in-thread; the non-local-plan cross-node parity residual is tracked as a separate follow-up. Advancing to review. Session id: cron:our-pr-ci-monitor:20260704-073000 |
|
Dear @nickitat, you haven't been active on this PR for 30 days. You will be unassigned. Will you continue working on it? If so, please feel free to reassign yourself. |
…licas-active-total-nodes-count
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Object file sizes492 object files changed (+72.69 KiB total), 0 added.
716 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only Compile time of recompiled translation units1490 translation units recompiled, 7756 s compile time in total, 1490 of them have a recent master baseline. |
CI finish ledger - 5a733c6Every failure below has an owner: a fixing PR (ours or external), or a full-effort fix task
The abort is a DISTINCT-in-order sorted-range assumption in Session id: cron:our-pr-ci-monitor:20260818-160000 |
…licas-active-total-nodes-count
|
🕵 Merged |
# Conflicts: # src/Processors/QueryPlan/ReadFromMergeTree.cpp
|
🕵 Merged |
…of worker startup order The coordinator can hand all ranges to the first replica that asks and cancel the others before their queries start, so counting nodes with a secondary query in `query_log` (`test_parallel_replicas_alien_shard_scope`) or requiring a log line from `n2`/`n3` after a single query (`test_parallel_replicas_plan_based_replica_count`) could fail on a correct parallel-replicas execution. - `test_parallel_replicas_alien_shard_scope`: prove engagement by the query-scoped `Creating parallel replicas coordinator with replicas_count=` line of shard 1's secondary query, and require a count of at least 2. - `test_parallel_replicas_plan_based_replica_count`: use small granules so the read splits into many segments, and repeat the query (bounded) until `n2` or `n3` has sized its segments, keeping the assertions that the workers consume the propagated count. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…he plan-based replica count test Retrying the query did not guarantee that `n2` or `n3` would ever size their segments, because the coordinator could give all ranges to `n1` and cancel the other workers on every attempt. The test now enables the one-shot `parallel_replicas_wait_for_unused_replicas` failpoint on the initiator. Unused workers are then not cancelled, so each of them builds its read pool and logs `number_of_replicas`. The retry loop is removed, and the test now requires both checked workers to log the propagated count. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
🕵 Merged |
# Conflicts: # src/Interpreters/ClusterProxy/executeQuery.cpp
|
🕵 Merged |
…icas skip-inactive tests `master` now answers `sum` without `GROUP BY` and filters from per-part statistics (`use_statistics_for_sum_avg_aggregation`, enabled by default), so `SELECT sum(key)` in these tests read no data and the parallel replicas read pool never logged `number_of_replicas=` / `min_marks_per_task*threads=`. Disable the optimization for these queries, the same way `master` did in `test_parallel_replicas_protocol`. CI report: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=109377&sha=e11eb8bca0f283dc8ba6897ea9a095b5fa66504e&name_0=PR PR: ClickHouse#109377 Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
🕵 Merged
|
The new `Stateless tests (arm_asan_ubsan, azure, targeted)` job (ClickHouse#131576) runs the test 50 times on one server with fixed settings. `query_23` (`... WHERE URL LIKE '%google%' ORDER BY EventTime LIMIT 10`) is a TopK read: with the default `use_query_condition_cache = 1` every run stores the granules the TopK filter dropped, and the next run starts from them. The selection shrinks run over run (CI: 383, 26, 16, 9 marks), `ReadCompressedBytes` falls more slowly than the estimate, and the ratio crosses the test's 2x bound once it converges (2.005x / 2.022x on ClickHouse#109377 and ClickHouse#129198). Randomized jobs never converge because the cache and TopK settings are re-drawn per run. Pin `use_query_condition_cache=0` test-wide, as the sibling estimation tests 03801 and 04102 already do; the cache with autopr stays covered by 03783_autopr_dataflow_cache_reuse_qcc. Locally, unpatched at CI's thread count: red from run 4-5 (8-9 marks, 2.02-2.04x); patched: 10/10 with a constant 1084 marks, and 50/50 with random settings. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Resolve the conflict in `SelectStreamFactory` with https://github.com/ClickHouse/ClickHouse/pull/ (`b50f2e6cdf7f`, "Plan a distributed query once for all remote shards"), which removed the AST overload of `createForShard` and caches the query AST per factory: take master's version, add the `shard_scope_identity` parameter back, and strip `cluster_for_parallel_replicas` from the cached AST when it is built.
ClickHouse#130655 and `fa76a947810d` ("Do not use inactive replicas as `make_distributed_plan` workers") on `master` renamed the static `getActiveReplicasForParallelReplicas(context, cluster)` to the exported `getReplicasLiveness(cluster_name, cluster)`. The merge kept the new name, but the call in `getActiveReplicasCountForParallelReplicas` added by this PR still used the old one. Pass the `cluster_for_parallel_replicas` setting as the cluster name, which is what the old function read. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
🕵 Merged
The only red check was |
|
The fix is #131870 (
#130682 does not cover this run: the query has no aggregate function. |
|
🕵 Merged Public CI on 67718c1 had no failed tests; the only red was |
|
🕵 Public CI on 5d6927b is green apart from |
@groeneai how this can possible take 1.5K lines of slop? |
|
You're right, the size is not justified for a heuristic.
The parity premise was not needed. Two options:
Which one do you prefer? |
do (1) |
|
Acknowledged. I'll open the minimal PR from current |
|
The minimal PR is #133260 (+81/-8: 50 lines in |
Related: #107805
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Parallel replicas now size the automatic
parallel_replicas_mark_segment_sizeby the number of active replicas, consistent with the reading coordinator, so registered-but-inactive replicas no longer skew segment sizing.Description
Follow-up to #107805 (the optional
total_nodes_count/mark_segment_sizealignment noted in review).#107805 made the parallel replicas reading coordinator size itself by the number of active replicas (excluding registered-but-inactive ones), so mark segments are not assigned to replicas that never participate. The automatic
mark_segment_sizeheuristic inReadFromMergeTree, however, still derived its work-distribution denominator fromgetAllNodeCount()(the registered count viaParallelReadingExtension::total_nodes_count). When a replica was registered but inactive the two sizings disagreed.This sources
ParallelReadingExtension::total_nodes_countfrom the active replica count through a sharedClusterProxy::getActiveReplicasCountForParallelReplicashelper that mirrors the coordinator's sizing exactly: the active count when liveness is known, the registered count when it is not (or when it does not line up with the cluster definition), and a zero-active safety net that falls back to the registered count.total_nodes_countfeeds onlychooseSegmentSize, whose result is clamped to{128, 1024, 16384}and is never used for indexing, so this cannot go out of range (replica numbering stays bounded by the registered count) and can only make segments smaller, which balances work no worse.The existing integration test
test_parallel_replicas_skip_inactive_replicasis extended to assert the segment-sizing heuristic sees the active replica count (2), not the registered count (3), when one of three replicas is stopped. Verified the added assertion fails before this change and passes after; theall_groupssibling test is unaffected.Workflow [PR]
Sync PR [sync-upstream/pr/109377]