Skip to content

Fix: max_execution_timeout_leaf with parallel replicas - #69540

Merged
alexey-milovidov merged 57 commits into
masterfrom
fix-pr-max-execution-timeout-leaf
Sep 12, 2026
Merged

alexey-milovidov merged 57 commits into
masterfrom
fix-pr-max-execution-timeout-leaf

Conversation

@devcrafter

@devcrafter devcrafter commented Sep 11, 2024 •

Copy link
Copy Markdown
Member

max_execution_time_leaf and timeout_overflow_mode_leaf settings are now effective for queries with parallel replicas.

Previously these settings were silently ignored for task-based parallel replicas when the local replica pipeline was used (the leaf timeout was substituted into max_execution_time only for remote replicas, while the local replica shares the initiator's QueryStatus and was therefore unbounded). This is fixed for both SELECT and INSERT SELECT (with parallel_distributed_insert_select = 2) by skipping the local pipeline when the leaf timeout is set, so all leaf reading happens on remote replicas where the leaf timeout is honored.

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):

Fixed max_execution_time_leaf and timeout_overflow_mode_leaf being ignored for queries executed with parallel replicas (including INSERT SELECT with parallel_distributed_insert_select = 2). The settings were silently not applied when the local replica pipeline was used; now they are honored.

Information about CI checks: https://clickhouse.com/docs/en/development/continuous-integration/

CI Settings (Only check the boxes if you know what you are doing):

  • Allow: All Required Checks
  • Allow: Stateless tests
  • Allow: Stateful tests
  • Allow: Integration Tests
  • Allow: Performance tests
  • Allow: All Builds
  • Allow: batch 1, 2 for multi-batch jobs
  • Allow: batch 3, 4, 5, 6 for multi-batch jobs

  • Exclude: Style check
  • Exclude: Fast test
  • Exclude: All with ASAN
  • Exclude: All with TSAN, MSAN, UBSAN, Coverage
  • Exclude: All with aarch64, release, debug

  • Run only fuzzers related jobs (libFuzzer fuzzers, AST fuzzers, etc.)
  • Exclude: AST fuzzers

  • Do not test
  • Woolen Wolfdog
  • Upload binaries for special builds
  • Disable merge-commit
  • Disable CI cache

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

Version info

  • Merged into: 26.9.1.1233 (included in 26.9 and later)

@robot-ch-test-poll3 robot-ch-test-poll3 added the pr-not-for-changelog This PR should not be mentioned in the changelog label Sep 11, 2024
@hanfei1991 hanfei1991 self-assigned this Sep 11, 2024
@clickhouse-gh

clickhouse-gh Bot commented Oct 15, 2024

Copy link
Copy Markdown
Contributor

Dear @hanfei1991, this PR hasn't been updated for a while. You will be unassigned. Will you continue working on it? If so, please feel free to reassign yourself.

@alexey-milovidov

Copy link
Copy Markdown
Member

@devcrafter, it needs to be properly merged with the master branch.

@alexey-milovidov alexey-milovidov self-assigned this Dec 28, 2024
@clickhouse-gh

clickhouse-gh Bot commented Feb 7, 2025 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [7bd6034]

@clickhouse-gh

clickhouse-gh Bot commented Mar 11, 2025

Copy link
Copy Markdown
Contributor

Dear @alexey-milovidov, this PR hasn't been updated for a while. You will be unassigned. Will you continue working on it? If so, please feel free to reassign yourself.

@clickhouse-gh

clickhouse-gh Bot commented Aug 8, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 36e6c1ef8 with master b682283f8 (stripped binary size, per-symbol sizes and ThinLTO time; object sizes against the warmup build of 974267656; 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

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

Median compile-time ratio to the baselines is ×1.08 (machine-speed difference or a change affecting every TU); per-TU deltas below are relative to that ratio.
The matched translation units cost +36.0 s (+9%) in total before that adjustment.

Job report

@alexey-milovidov

Copy link
Copy Markdown
Member

🕵 Investigated the remaining Bugfix validation (unit tests) failure at dbaee9309309: it is inconclusive before any test runs because the historical merge-base 7570b20ad2c7 has different submodule revisions from the checkout (.gitmodules, AMQP-CPP, NuRaft, llvm-project, musl, silk, simdjson, and sz3). The validator intentionally refuses to build its before-worktree with mismatched submodules.

The current net diff against master contains only the eight intended timeout implementation/test files and no submodule changes; all other CI checks and review threads are green/resolved. Re-running this check will produce the same result. Clearing it needs a CI-validator policy change for long-lived branches with merged master history, or history rewriting; the latter is not appropriate for this published PR.

@alexey-milovidov

Copy link
Copy Markdown
Member

🕵 Merged current master into the PR branch (commit c1d7119decf6) and pushed it. The merge was conflict-free; the net diff against current master remains limited to the eight intended leaf-timeout implementation/test files (393 insertions, 10 deletions), with no submodule changes.

The prior Bugfix validation (unit tests) error was the validator's deliberate before-worktree safety stop for this long-lived branch's historical submodule mismatch, before tests ran; refreshing the branch gives CI a current base/submodule state. All review threads remain resolved.

@clickhouse-gh

clickhouse-gh Bot commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

Dear @hanfei1991, 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.

@alexey-milovidov

Copy link
Copy Markdown
Member

🕵 Merged current master into the branch (head 35afb9248f21); the previous head 551f01bd431c was fully green (164 checks ✅, 18 skipped), AI Review ✅ Approve, zero unresolved threads.

The merge was a criss-cross one: git merge-base --all returns two bases (2bb9dae14497, the master merged on 2026-08-18, and ecbe3697aa9f), so the ort virtual base is garbage and a plain merge produced 292 conflicts although this PR touches only 8 files. Resolved mechanically by taking master verbatim for every file outside the PR's own set and re-applying the PR delta three-way against the real base. Verified invariant: git diff --cached origin/master --numstat is byte-identical to the pre-merge git diff 2bb9dae14497..HEAD --numstat — 8 files, +392/-10 — and the contrib gitlinks match master exactly, so the merge is master plus the intended leaf-timeout change and nothing else.

Verification after the merge:

  • ninja clickhouse builds cleanly against current master.
  • 04042_parallel_replicas_max_execution_time_leaf passes against a local server with test_cluster_one_shard_three_replicas_localhost.
  • Re-checked the limits_fast.yaml interaction that caused the earlier Fast test breakage: the 128 parallel_replicas stateless tests were run under an emulated max_execution_time = 60, max_execution_time_leaf = 60 profile — 120 pass; the 8 failures (s3_cache storage policy, MinIO, localhost:9000) fail identically on a baseline run without those options, i.e. they are limitations of the minimal local server, not behavior changes.

No code changes; awaiting a fresh CI run on the merged head.

@alexey-milovidov

Copy link
Copy Markdown
Member

🕵 Merged current master into the branch (head 0c0ec97775b8) to refresh CI. The four reds at the previous head 35afb9248f21 were all unrelated to this PR:

State otherwise: AI review verdict ✅ Approve, zero unresolved threads, approved by @alexey-milovidov. The criss-cross merge situation persists (two merge bases), so the merge was again done by taking master verbatim and re-applying the PR delta three-way against the real base 62320728c4d0; the net diff against master is byte-for-byte identical to the previous head (8 files, +392/−10). ninja clickhouse builds cleanly on the merged head.

@abashkeev abashkeev added the comp-parallel-replicas Parallel reading from replicas for query speed (not data replication consistency). label Sep 3, 2026
alexey-milovidov and others added 2 commits September 11, 2026 23:17
…af timeout test

A review comment suspected that the analyzer/planner `SELECT` path
(`ClusterProxy::executeQueryWithParallelReplicas` with a query tree, used for a
non-replicated `MergeTree` with `parallel_replicas_for_non_replicated_merge_tree = 1`)
re-serializes the top-level `SETTINGS` clause into the query text sent to the
replicas, so that an outer `max_execution_time` would override the leaf value
substituted into the shipped context.

That does not happen: `buildQueryTreeForShard` calls `QueryNode::clearSettingsChanges`
on the top-level query node before the shipped AST is built, exactly so the query
settings are not sent in the query text (they travel with the context instead).
Verified on a local three-replica cluster: the shipped text is
`SELECT sum(...) FROM ... AS __table1` with no `SETTINGS` clause, and with
`max_execution_time = 100, max_execution_time_leaf = 1` a remote replica throws
`TIMEOUT_EXCEEDED` after ~1 s.

Add the corresponding regression cases so the behaviour stays pinned.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@alexey-milovidov

Copy link
Copy Markdown
Member

🕵 Status update (2026-09-12):

  • Merged master (the branch was 14 days stale, ~7.9k commits; single merge base, conflict-free). ninja clickhouse is clean — no API drift in the four touched translation units.
  • Addressed the one remaining unresolved review thread (@qoega's ping on the clickhouse-gh finding): the finding is refuted — buildQueryTreeForShard clears QueryNode::settings_changes on the top-level query node, so the analyzer/planner SELECT path never re-serializes the outer max_execution_time into the query text sent to the replicas. Details and the local three-replica evidence are in the thread reply.
  • Added the regression coverage the finding asked for: the non-replicated MergeTree planner path (parallel_replicas_for_non_replicated_merge_tree = 1) is now pinned in 04042_parallel_replicas_max_execution_time_leaf.sql, both for the outer-vs-leaf timeout and for a differing timeout_overflow_mode.
  • 04042_parallel_replicas_max_execution_time_leaf passes locally against a three-replica cluster.

Head is now 36e6c1ef8ce4; awaiting fresh CI.

@alexey-milovidov alexey-milovidov self-assigned this Sep 12, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Sep 12, 2026
Merged via the queue into master with commit 51a5711 Sep 12, 2026
175 checks passed
@alexey-milovidov
alexey-milovidov deleted the fix-pr-max-execution-timeout-leaf branch September 12, 2026 08:50
@robot-ch-test-poll3 robot-ch-test-poll3 added the pr-synced-to-cloud The PR is synced to the cloud repo label Sep 12, 2026
@clickgapai

clickgapai commented Sep 12, 2026 •

Copy link
Copy Markdown
Contributor
Reproducer
-- Server started with the stateless-test config (defines
-- test_cluster_one_shard_three_replicas_localhost); no Keeper needed.
CREATE TABLE t (key UInt64) ENGINE = MergeTree ORDER BY key SETTINGS index_granularity = 10;
INSERT INTO t SELECT number FROM numbers(1000);

SELECT sum(sleepEachRow(0.01)) FROM t
SETTINGS allow_experimental_parallel_reading_from_replicas = 2, max_parallel_replicas = 3,
         cluster_for_parallel_replicas = 'test_cluster_one_shard_three_replicas_localhost',
         parallel_replicas_for_non_replicated_merge_tree = 1, automatic_parallel_replicas_mode = 0,
         max_threads = 1, max_block_size = 1,
         max_execution_time_leaf = 1;

-- 26.8.2.7 (and every release down to 25.8.33.6): returns 0 after ~10s
--   -> max_execution_time_leaf silently ignored.
-- master (26.9.1.1273, with #69540): Code: 159 TIMEOUT_EXCEEDED after ~1s, raised on a remote replica.
-- Control on the same build: replacing max_execution_time_leaf = 1 with
-- max_execution_time = 1 DOES abort at 1s, so the query really runs >1s.

Results:

  • Reproduces on: 26.8, 26.7, 26.6, 26.3
  • Does not reproduce on: master
  • Tested versions: master, 26.8, 26.7, 26.6, 26.3
  • Also tested (unsupported, context only): 26.2 reproduces
  • ✓ Fix is on master — this PR's change fixes the bug on master. The releases listed above still have the bug and need the backport.

Backport the fix to 26.8, 26.7, 26.6, 26.3.

CC component owner: @devcrafter @nickitat

Analysis metadata

comp-parallel-replicas · Severity P2 · Finding phase_d_pr69540

  • Verified against master build 3476b12ea2ce (aarch64)
Introducing change: predates `v23.12.6.19` (oldest testable release)
  • v23.12.6.19 is the oldest release with a downloadable binary for this reproducer, and it already reproduces — the introducing change predates it and cannot be identified from release builds.
  • Walked 6 release(s) below the supported window: still reproduces down to 25.8.
  • Secondary components: comp-sql-syntax

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

Labels

comp-parallel-replicas Parallel reading from replicas for query speed (not data replication consistency). 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.

8 participants