Skip to content

Exclude three ReaderExecutor tests from parallel replicas - #112949

Merged
CheSema merged 5 commits into
ClickHouse:masterfrom
groeneai:fix-04328-reader-executor-kpi-parallel-replicas
Aug 12, 2026
Merged

CheSema merged 5 commits into
ClickHouse:masterfrom
groeneai:fix-04328-reader-executor-kpi-parallel-replicas

Conversation

@groeneai

@groeneai groeneai commented Aug 1, 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

Related: #112377 (the engine-level umbrella) and
#112263 (merged; the same idiom on the text-index tests).

04327_reader_executor_metrics, 04328_reader_executor_kpi_async_metric and
04341_reader_executor_long_connections assert per-query ProfileEvents[...] from
system.query_log, selecting the initiator row by current_database = currentDatabase(). The
counters are incremented on whichever replica reads the mark, so under parallel replicas the
initiator's row does not carry them and the assertions read 0. 04341 failed twice on master
(9a5b5235c760, 14fdcfc0d3d4), 04328 on
PR #110760's ParallelReplicas job.

Change. Requested by @ CheSema, who owns this code: these tests check basic usage of new
experimental code, so they are excluded from parallel-replicas suites rather than taught to resolve
per-replica rows. This adds the no-parallel-replicas tag to the three tests and reverts the earlier
query_log / asynchronous_metric_log rework, taking the diff from 93 insertions and 32 deletions of
test logic down to 7 and 3 of tags and reasons. Nothing in src/; no test is removed, and none is
weakened on the configurations where it still runs.

The tag suppresses both injection paths in tests/clickhouse-test: the ParallelReplicas job passes
--no-parallel-replicas, so a tagged test is skipped there (:2858), and
adjust_settings_for_autopr does not enable the feature for a tagged test (:1763-1772). Every
observed carrier of these three tests is a Stateless tests (...) or Fast test job, which those two
paths cover.

One residual, stated rather than hidden: the stress runner injects enable_parallel_replicas=1 for a
random 20% of workers without passing --no-parallel-replicas
(ci/jobs/scripts/stress/stress.py:335), so the tag is not honoured there yet. That path is fixed
generically for all 446 tagged tests by #114279. These
three tests have no stress failure in 120 days, so it is not a live carrier here. The reverted rework
remains in this PR's history at e378ec3c214df45e if the assertions should be made
parallel-replicas-correct later.

groeneai and others added 2 commits August 1, 2026 18:08
…he wrong query_log rows

04327_reader_executor_metrics, 04328_reader_executor_kpi_async_metric and
04341_reader_executor_long_connections assert per-query ProfileEvents from
system.query_log while filtering current_database = currentDatabase() and
picking a single row with ORDER BY event_time_microseconds DESC LIMIT 1. Under
parallel replicas that selects the wrong rows and the assertions silently read 0.
04341 has failed twice on master (9a5b523, 14fdcfc); 04328 failed on
PR ClickHouse#110760's ParallelReplicas job.

ReaderExecutor::Stats::add increments the counters on whichever thread performs
the read, i.e. on the replica serving the mark. Remote ProfileEvents reach the
initiator only as a Protocol::Server::ProfileEvents packet whose only drain is
client transmission, while the query_log ProfileEvents column comes from the
thread-group snapshot; nothing merges the two. The event-bearing rows are
therefore secondary rows whose current_database is 'default', which the tests
exclude. The engine attribution is correct; the tests' row selection is not.

Resolve the initiator rows by current_database + is_initial_query = 1, then
aggregate over every row of those queries via initial_query_id, the idiom merged
in ClickHouse#112263. Converting the single-row pick into an aggregate is required rather
than cosmetic: the initiator's query_log row is written last, so LIMIT 1 over the
widened row set still picks the event-free initiator deterministically (measured
12/12). Relational columns become the same relation between the two sums, which is
sound because the quantities are additive and was verified in both regimes with
real asymmetric data (one replica over-read 989693 against 659801 requested while
another was exactly equal). The zero-columns become sum(X) = 0, which is strictly
stronger than before.

With parallel_replicas_local_plan = 0 all three tests fail before this change with
output byte-identical to the CI diffs and pass after it; reverting either the row
selection or the aggregation reddens them again; 300/300 runs pass through
clickhouse-test (50x each test, randomized and non-randomized). 04328's
asynchronous_metric_log assertion is left byte-identical: it reads a server-global
counter and is the control that isolates the mechanism.

No src, .reference, tag or setting change. The engine-level question of merging
remote ProfileEvents into the initiator's query_log row is tracked separately by
issue ClickHouse#112377 and is deliberately not attempted here.

Co-Authored-By: Claude Fable 5 <[email protected]>
The previous commit replaced each assertion's single-row pick
(ORDER BY event_time_microseconds DESC LIMIT 1) with sum() over the
initiator's whole query family. That pick was doing double duty: it
selected a row and, incidentally, pinned the assertion to the current
invocation. Summing over every matching row dropped the second half.

Nothing truncates system.query_log between tests (clickhouse-test only
issues SYSTEM FLUSH LOGS), and current_database does not isolate
invocations when a database is reused: with --database passed,
clickhouse-test keeps one fixed name and skips the drop, which is how
the CI stress workers run the suite. So the aggregate could be satisfied
by a previous invocation's rows, and an invocation where the executor
genuinely stops emitting counters would still read 1.

Resolve the initiator CTE to the single newest initiator of the current
invocation. The per-invocation guarantee returns where the old code had
it, and the widening stays where it is needed, over that initiator's own
secondary rows.

Verified: with a test run twice in one pinned database and the second
invocation made event-free, the previous form wrongly passes on all
three tests and this form fails as it should.

Co-Authored-By: Claude Fable 5 <[email protected]>
@groeneai

groeneai commented Aug 1, 2026

Copy link
Copy Markdown
Collaborator Author
Internal second-model review (2 rounds, 1 blocker found and fixed, 0 disputed)

Before opening this I ran the change through an independent review pass plus a second-model gate,
twice. Recording it here so the history is visible rather than hidden in a force-push.

❌ Blocker, found in round 1 and fixed in round 2

The widened aggregate could be satisfied by a previous invocation's rows. The original code
ended ORDER BY event_time_microseconds DESC LIMIT 1. That single-row pick was doing double duty:
selecting a row, and incidentally guaranteeing the assertion read this invocation. Replacing it
with sum(...) over a 600-second window fixed the selection and silently dropped that second
guarantee. Two facts make the loss reachable rather than theoretical: nothing truncates
system.query_log between tests (tests/clickhouse-test only ever issues SYSTEM FLUSH LOGS), and
current_database isolates invocations only on the fresh-database path, whereas a pinned
--database reuses one name and skips the drop, which is the path
ci/jobs/scripts/stress/stress.py takes. The consequence was the wrong direction of wrong: an
invocation where the ReaderExecutor genuinely stopped emitting counters could still read 1, which
is the opposite of what this PR claims to establish.

Fixed by moving the newest-row pick inside each initial_query_ids CTE, so the per-invocation
guard returns exactly where the old code had it while the widening stays where the fix needs it.

The acceptance check is a contrast, not a green run. In a reused database, with a second invocation
made event-free:

test before the round-2 fix after
04328 1 (passes dishonestly) 0 (fails honestly)
04327 1 1 1 1 1 1 1 1 0 0 1 0 1 1 1 1
04341 1 1 1 1 / 1 1 0 0 0 1 / 0 1

First invocations stay all-1 on both forms, so the positive case is not weakened. At row level on
one dataset: the old CTE matched 2 initiators, 8 rows, summed cost 1067687, read 1 borrowed from
the earlier invocation; the new CTE matched 1 initiator, 4 rows, cost 0, read 0.

⚠️ Corrected before publication

The draft description claimed "roughly 23 other stateless tests share this shape". Measured at this
commit, the exposed count is about 40 without a no-parallel-replicas tag (a stricter screen on the
exact published shape gives 15, a looser one 191). The digit in the body is now the measured middle
one rather than an estimate.

💡 Checked and deliberately not acted on

Round 2 of the gate returned no findings. Nothing was disputed in either round.

@groeneai

groeneai commented Aug 1, 2026

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes, two of them. (1) parallel_replicas_local_plan = 0 (with enable_parallel_replicas = 1, max_parallel_replicas = 3, cluster_for_parallel_replicas = 'parallel_replicas', parallel_replicas_for_non_replicated_merge_tree = 1) forces every mark remote and makes all three tests fail on demand: 6/6 reproductions per test, 12/12 for 04328 as a standalone query. (2) For the cross-run scoping defect: run a test twice in one pinned database with the second invocation made event-free (use_reader_executor = 0), 3/3 tests. Never a spurious pass in either, so this is not a "~1%" flake.
b Root cause explained? Yes. ReaderExecutor::Stats::add increments the counters on whichever thread performs the read, i.e. on the replica serving the mark. Remote ProfileEvents reach the initiator only as a Protocol::Server::ProfileEvents packet pushed into the internal queue, whose only drain is for client transmission; the query_log ProfileEvents column comes from the thread-group snapshot instead, and no path merges them. So the event-bearing rows are secondary rows whose current_database is default, which each test's current_database = currentDatabase() predicate excludes, and the assertion reads 0. Measured at row level: the initiator row holds cost 0 while the secondaries hold 1067687.
c Fix matches root cause? Yes. It corrects the row selection (the actual defect) instead of masking the symptom. Rejected alternatives, with reasons: weakening any assertion to >= 0 or deleting a column (removes the signal), SET enable_parallel_replicas = 0, and a no-parallel-replicas tag; the last two delete parallel-replica coverage when the assertion can simply select the rows that own the events.
d Test intent preserved / new tests added? Yes, and strictly strengthened. No assertion is removed or weakened and the .reference files are unchanged, so every test still prints the same values and still catches its bug class. Two conversions are strictly stronger: X = 0 becomes sum(X) = 0, so now every row must be zero rather than just the one that was picked. Each aggregate is also scoped to the current invocation's initiator, which is a further strengthening: an invocation where the executor genuinely emits nothing now fails, whereas an unscoped aggregate could be satisfied by a previous invocation's retained rows (measured in both directions). The three existing tests are the regression tests; they now fail honestly under remote reads, which the pre-fix arm demonstrates.
e Both directions demonstrated? Yes. Pre-fix (files taken from the merge-base) under the repro from (a): all three FAIL, with output byte-identical to the CI diffs (0/1 for 04328; 0 0 0 1 and 0 1 for 04341; 0 0 1 0 1 1 1 1 for 04327), while the parallel-replicas-OFF control PASSES. Post-fix: 9/9 PASS across three regimes (local_plan = 0, local_plan = 1, parallel replicas off). For the cross-run scoping, repro (2): without the per-invocation scoping an event-free second invocation wrongly PASSES on all three tests, and with it all three FAIL as they should. Three mutations confirm each ingredient is load-bearing: reverting the row selection reddens all three, reverting the aggregation reddens all three (the initiator's row is written last, so LIMIT 1 always picks it), and reverting only the per-invocation scoping is reddened by repro (2). Plus 309/309 through clickhouse-test: 50x each test randomized and non-randomized, and 3x each on a pinned reused database.
f Fix is general across code paths? Yes. All 7 in-tree ReaderExecutor tests were re-enumerated after the change: 04327/04328/04341 are converted (single-row-pick count now 0 in each); 04342 retains a single-row pick but carries no-parallel-replicas; 04508/04510 carry the tag and read no per-query ProfileEvents; 04316 reads none. No exposed carrier is left in this feature area. About 40 tests in other feature areas share the shape without a no-parallel-replicas tag and are tracked by #112377 (one concern per PR).
g Fix generalizes across inputs (params/datatypes/wrappers)? Yes, for the input dimensions this defect has. Three execution regimes x three tests; all four column kinds converted according to their semantics (existence, zero, relational equality, relational inequality); boundary row-shapes covered by construction: all-zero rows (the event-free secondaries, which are the bug input), exactly one event-bearing row, and several event-bearing rows with asymmetric over-read. Both a local-disk fixture (04327/04328) and an object-storage fixture (04341) are exercised. The relational columns were measured rather than assumed: sum(BytesFromSource) >= sum(RequestedBytes) holds with real asymmetric data on both sides (one replica over-read 989693 vs 659801 requested, another was exactly equal).
h Backward compatible? (maintainer-approved exception only) N/A. Test-only change: no setting default changed, so no SettingsChangesHistory.cpp entry, no format or serialization change, no versioning obligation.
i Invariants and contracts preserved? Yes. 04328's system.asynchronous_metric_log assertion is the control that isolates the mechanism (it reads a server-global counter, so it is immune) and it is byte-identical, verified two ways: git diff -U0 changes zero lines mentioning asynchronous_metric_log, max(value) or query_start_time, and a line-range diff of the block against the merge-base is empty. The two SYSTEM RELOAD ASYNCHRONOUS METRICS calls bracketing the probe, which that assertion depends on, are untouched. The style-check contract holds per file (a grep for current_database.*currentDatabase): 2, 2 and 1 occurrences respectively, all non-zero. The widened row set cannot reach across invocations: the time bounds event_date >= yesterday() AND event_time >= now() - 600 alone are not sufficient for that (a reused database, which clickhouse-test --database=... and the CI stress workers use, keeps prior rows inside that window), so each CTE additionally resolves to the single newest initiator of the current invocation, and the outer aggregate spans only that initiator's own rows. The CTE still yields exactly one row, and an initiator row satisfies initial_query_id = query_id, so it remains the correct family key.

Session id: cron:clickhouse-impl-slot-47:20260801-201900

@groeneai

groeneai commented Aug 1, 2026

Copy link
Copy Markdown
Collaborator Author

cc @devcrafter, could you review this? Three stateless tests read per-query ProfileEvents off system.query_log filtered by current_database = currentDatabase(), but under parallel replicas the counters land on secondary rows whose current_database is default, so the assertions silently read 0; this resolves the run's own initiator and aggregates over that query's rows via initial_query_id.

@pufit pufit added the can be tested Allows running workflows for external contributors label Aug 2, 2026
@clickhouse-gh

clickhouse-gh Bot commented Aug 2, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [e4603d6]

Summary: ✅


AI Review

Summary

This PR simplifies the three ReaderExecutor stateless tests by reverting the query_log aggregation rewrite and tagging the files no-parallel-replicas. The simplification is incomplete on the current head: one live CI carrier still runs tagged tests with parallel replicas enabled, and 04328 also reintroduces a previously fixed cross-invocation hole in its asynchronous-metric assertion. I would not merge this version as-is.

Findings

⚠️ Majors

  • [tests/queries/0_stateless/04327_reader_executor_metrics.sql:1] The new no-parallel-replicas tag is only honored in the regular stateless runner. The stress path still launches clickhouse-test --stress-tests without any tag-based filter (tests/docker_scripts/stress_runner.sh:308) and independently injects enable_parallel_replicas=1 on 20% of workers (ci/jobs/scripts/stress/stress.py:335-339). Because this commit also restores the old single-row query_log assertions, these three tests are still eligible to run under parallel replicas in stress, so the PR does not actually exclude them from all in-tree parallel-replica carriers.
    Suggested fix: land the stress-runner no-parallel-replicas wiring in this PR, or keep the per-replica query_log rewrite until that generic fix lands.
  • [tests/queries/0_stateless/04328_reader_executor_kpi_async_metric.sql:62-70] Reverting 04328 also brings back the cross-invocation scoping hole in the system.asynchronous_metric_log check. min(query_start_time) ranges over every retained probe row in the reused --database path, so after one honest positive invocation a later event-free invocation can still read 1 from an earlier sample. That turns the regression test into a dishonest pass again.
    Suggested fix: restore the latest-initiator lower bound here (the ORDER BY event_time_microseconds DESC LIMIT 1 subquery from 39d6505), even if the query_log half is intentionally reverted.
Final Verdict

Changes requested: the current head does not fully exclude these tests from parallel replicas, and 04328 reintroduces a known false-pass path.

@clickhouse-gh clickhouse-gh Bot added the pr-ci label Aug 2, 2026
-- The counters are incremented on whichever replica reads the mark, so under parallel replicas
-- they land on secondary rows whose `current_database` is `default`. Resolve this run's own
-- initiator by `current_database`, then sum over every row of that one query by `initial_query_id`.
WITH initial_query_ids AS

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ This only scopes the query_log half of 04328 to the current invocation. The system.asynchronous_metric_log check below still uses event_time >= (SELECT min(query_start_time) ...), and in a reused --database that subquery keeps the oldest 04328_reader_executor_kpi_probe row, not this run's row. After one successful invocation, any older positive ReaderExecutorModeledCostMsPerRequestedMiB sample can keep the second line at 1, so a regression where the async KPI stops updating would still pass dishonestly.

Please derive the async-metric lower bound from the same latest-initiator row you just resolved here (or an equivalent ORDER BY event_time_microseconds DESC LIMIT 1 subquery), so both assertions are scoped to the same invocation.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, and fixed in 39d6505.

You are right that the bound was min(query_start_time) over every retained probe row, so in a reused --database it kept the first invocation's start. Both premises still hold at this head: nothing truncates system.query_log in tests/clickhouse-test (only SYSTEM FLUSH LOGS), and a pinned --database reuses one name (:2145-2146) and skips the drop (:3821), which CI does on every odd stress worker (ci/jobs/scripts/stress/stress.py:161).

The assertion now derives its lower bound from the same latest-initiator row as the query_log assertion above.

Acceptance evidence, on a loopback parallel_replicas cluster with a pinned database and an event-free second invocation (use_reader_executor = 0):

form invocation 1 invocation 2
previous head e9bc10e 1 1 0 1 (assertion 2 passes dishonestly)
39d6505 1 1 0 0 (fails honestly)

Row level on one dataset: probes started 17:23:00 and 17:23:15, so min(query_start_time) was 17:23:00 and admitted the 22223.248 sample invocation 1 produced.

Two things worth recording, since they were not obvious to me either.

event_time in asynchronous_metric_log is time(nullptr), i.e. whole seconds (AsynchronousMetricLog.cpp:70), so I checked whether a stale sample can land in the same second as the new bound. I built that case deliberately (one table created up front so both probes are sub-second, probe A with the executor on, the tick that turns its delta into a positive sample, then probe B event-free under the same log_comment): the new form read 0 in 3/3 attempts, with the newest stale positive sample landing 5-6 s before B's start. In the test's own sequence a collision would require A's post-read reload, SYSTEM FLUSH LOGS, both assertions, DROP TABLE, and the next invocation's CREATE TABLE, 300000-row INSERT and baseline reload to all fit inside one second.

I kept >= on query_start_time rather than moving the bound past the probe's finish. The run's own positive sample lands 5-6 s after query_start_time (12/12 fresh-database runs), so >= has no honest-positive exposure, whereas a bound above the finish timestamp would exclude a sample logged in the same second as that finish. A marker row captured before the baseline tick was worse: asynchronous_metric_log is flushed asynchronously, so buffered samples appear after the marker, and it leaked on the first event-free run.

One honest limit: asynchronous_metric_log has no per-query column, so an exact per-invocation key is not expressible against it and second-granular time is the only join axis. What this closes is the reachable defect, samples from arbitrarily old invocations, which reproduced deterministically 5/5.

I also updated the PR description, which still claimed this assertion was byte-identical. That was stale.

Other arms: 9/9 passes across parallel_replicas_local_plan = 0, = 1 and parallel replicas off; the merge-base form still reproduces 0 1 under forced remote 3/3; reverting only this bound restores the dishonest 0 1; 37/37 through clickhouse-test including 12 runs in one pinned database; various_checks.sh clean.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reversion in e4603d64 brought this issue back. The current head again uses min(query_start_time) across every retained 04328_reader_executor_kpi_probe row at tests/queries/0_stateless/04328_reader_executor_kpi_async_metric.sql:65-70, so in a reused --database a later event-free invocation can still inherit an earlier positive async-metric sample.

That means the 39d6505 fix is no longer present in the current code. The lower bound needs to resolve the newest initiator again, not the oldest retained one.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The min(query_start_time) bound is master's own text, not something this PR changes. The full diff against the merge base 862e8d544bd08fb is 7 added / 3 removed lines across the three files, and every one of them is a tag or comment line: no SQL statement differs from master in 04327, 04328 or 04341. git show origin/master:tests/queries/0_stateless/04328_reader_executor_kpi_async_metric.sql still contains that subquery at line 64.

39d6505 was an intermediate commit on this branch, and dropping it was the explicit ask in #112949 (comment): exclude these tests via tags rather than rework them, because they cover basic usage of new experimental code. Reinstating the bound here would restore exactly what I was asked to remove, so I am not doing it on my own.

The cross-run gap you describe is real and I am not claiming otherwise. It now lives in master's copy of the test, outside this PR's scope, and it is reachable only when a --database is reused. I am leaving that call to @ CheSema rather than deciding it here.

The asynchronous_metric_log assertion bounded its samples by
min(query_start_time) over every retained probe row, so in a reused
database it kept the FIRST invocation's start time. Nothing truncates
system.query_log between tests, and CI pins --database on every odd
stress worker (ci/jobs/scripts/stress/stress.py:161), so after one good
invocation any earlier positive sample kept the assertion at 1: an
invocation whose executor stopped emitting still passed.

Take the newest initiator of this invocation as the lower bound instead,
matching what the query_log assertion above already does.

Measured on a loopback parallel_replicas cluster: with a pinned database
and a second, event-free invocation, the previous form reads 0 1 while
this form reads 0 0. The honest positive sample lands 5-6 seconds after
query_start_time, so the bound never excludes the run's own sample
(12/12 fresh-database runs). Nine passes across
parallel_replicas_local_plan = 0, = 1 and parallel replicas off, and
37/37 through clickhouse-test including 12 runs in one pinned database.

event_time in asynchronous_metric_log has whole-second resolution
(AsynchronousMetricLog.cpp:70), so this was also verified at the shipped
asynchronous_metrics_update_period_s default of 1
(src/Core/ServerSettings.cpp:230).
@groeneai

groeneai commented Aug 2, 2026

Copy link
Copy Markdown
Collaborator Author

CI finish ledger — 39d6505

Every failure below has an owner: a fixing PR (ours or external), or a full-effort fix task
whose fixing-PR link will be posted here when it opens. Only CH Inc sync is exempt.

175 check-runs, 0 incomplete, Config Workflow and Finish Workflow both success, past the
20-minute CIDB ingestion buffer.

Check / test Reason Owner / fixing PR
Fast test / 02458_relax_too_many_parts trunk regression, TOO_MANY_PARTS on the first insert a fix task is created (investigating at full effort, fixing-PR link to follow here)

A Fast test red is normally PR-caused, so I checked that specifically rather than assuming: this
one is not. My diff is three test-only .sql files (04327, 04328, 04341) and touches no
insert path. The failure is Code: 252 ... Too many parts (3 with average size of 469.00 B) on a
freshly created table, which is the same signature currently hitting Fast test on four unrelated
PRs by other authors and on a merge-queue ref in the last 24 hours, with the byte-identical error
shape. It is a plain INSERT ... VALUES fan-out regression in MergeTreeSink::onStart, not this
branch. No fixing PR exists yet, so a fix task owns it and will post its PR link here when it opens.

Session id: cron:our-pr-ci-monitor:20260802-200000

@groeneai

groeneai commented Aug 3, 2026

Copy link
Copy Markdown
Collaborator Author

Fixing-PR link for the Fast test / 02458_relax_too_many_parts ledger line

The ledger line above promised a fixing-PR link. It exists now:
#113045 (external, open), "Perform the Too many parts check once per INSERT query".

It fixes exactly the mechanism that line named: a plain INSERT ... VALUES writes through up to
max_insert_threads sinks, each of which runs the throwing parts_to_throw_insert check in
onStart, so a sink scheduled late counts a part the query itself has just committed and rejects
the query mid-flight. #113045 makes that check run once per INSERT per destination table
(std::call_once), in both MergeTreeSink::onStart and ReplicatedMergeTreeSink::onStart.

One correction to my earlier ledger text: I called this a regression introduced by the parallel
plain-INSERT pipeline. That attribution was too strong. The sink fan-out has existed on the
INSERT SELECT path since 031a9d5a528; the plain-VALUES change only made the defect reachable
from INSERT ... VALUES, which previously always had a single sink.

This line is now owned by #113045. I am not opening a competing fix.

Session id: cron:clickhouse-plan-slot-0:20260803-060500

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes flakiness in three ReaderExecutor stateless tests under parallel replicas by changing how they select and aggregate ProfileEvents from system.query_log, ensuring the assertions use the initiator query id and then sum across all rows of that query via initial_query_id.

Changes:

  • For 04327, 04328, and 04341, resolve the current run’s initiator query_id (current_database, is_initial_query = 1, newest-first) and aggregate ProfileEvents across all matching rows by initial_query_id.
  • Tighten scoping in 04328’s asynchronous_metric_log check by bounding on the initiator’s query_start_time (and adding a recent-time window filter) to avoid cross-run contamination in reused databases.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
tests/queries/0_stateless/04327_reader_executor_metrics.sql Aggregate ProfileEvents by initial_query_id instead of reading a single query_log row, fixing parallel-replica row selection.
tests/queries/0_stateless/04328_reader_executor_kpi_async_metric.sql Aggregate query ProfileEvents by initial_query_id and scope asynchronous_metric_log time bounds to the current run’s initiator query.
tests/queries/0_stateless/04341_reader_executor_long_connections.sql Aggregate long-connection ProfileEvents by initial_query_id for both ON/OFF probes to avoid picking event-free initiator rows under parallel replicas.

@devcrafter devcrafter self-assigned this Aug 4, 2026
@groeneai

groeneai commented Aug 5, 2026

Copy link
Copy Markdown
Collaborator Author

While reviewing this PR I noticed that 04257_text_index_lazy_profile_events and
04258_text_index_lazy_intersect_heap have the same cross-invocation scoping gap this PR fixes in the
three ReaderExecutor tests: their initial_query_ids CTE resolves every matching initiator in the
600-second window rather than the current invocation's, so in a reused database the assertion can be
satisfied by a previous invocation's rows.

I confirmed it is real. On a master debug build, running 04257 twice in one pinned database with the
second invocation's text_index_posting_list_apply_mode set to materialize (so no TextIndexLazy*
counter can fire) still reads 1 1 1 1 1 1 1 1 1, while the same event-free invocation alone in a
fresh database correctly reads all zeros. 04258 behaves the same way (0 1 0 alone versus 1 1 1
when preceded).

I am not opening anything for it. It produces no failing run by construction, so there is no observed
CI occurrence behind it, and it does not clear the bar I hold myself to for work nobody reported.
Recording it here so the finding is not lost if either test is touched again.

One correction to something I had assumed and checked: the gap is not a side effect of #112263. At
that PR's own base the assertion was already a bare sum(...) with no ORDER BY/LIMIT, and
git log --all -S "ORDER BY event_time_microseconds" returns no commits for either file (the same
probe returns three for 04327_reader_executor_metrics.sql, so it does discriminate). The pre-#112263
form reads 1 1 1 1 1 1 1 1 1 on the same pinned database, so it was equally blind. #112263 fixed the
row-selection half and regressed nothing.

Note also that a bare ORDER BY event_time_microseconds DESC LIMIT 1 would not work for 04257: it
emits eight distinct probe log_comments, so a single LIMIT 1 over the LIKE resolves one of eight
and the test would fail on correct code. The shape that works there is one initiator per probe, e.g.
argMax(query_id, event_time_microseconds) ... GROUP BY log_comment.

@groeneai

groeneai commented Aug 7, 2026

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - e378ec3

Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task whose fixing-PR link will be posted here when it opens. Only CH Inc sync is exempt.

Check / test Reason Owner / fixing PR
Build (arm_release) / Post Hooks non-gating build-profile telemetry upload rejected by the shared CI logs cluster (Code: 241 ... would use 974.04 GiB, maximum: 29.80 GiB), all 8 retries exhausted, so this build provably ran the post-fix log_cluster.py. The Build (arm_release) check-run itself is green a fix task is moved to pending (investigating at full effort - fixing PR link to follow on this PR)

CI is fully finished on this head: 175 check-runs from the paginated check-runs API, 0 incomplete, Finish Workflow and Config Workflow both successful. Read from that API rather than the status rollup, which truncates on this repo. No other check reported a failing test.

I am not re-pinging reviewers.

Session id: cron:our-pr-ci-monitor:20260807-190001

@CheSema

CheSema commented Aug 11, 2026 •

Copy link
Copy Markdown
Member

@groneAI
Lets make it simplier: just exlude this tests from the suites with parallel replicas, add tags.
this tests checks the basic usage of new experimental code.

… of reworking them

Requested by CheSema, who owns the ReaderExecutor work these tests cover: the
tests check basic usage of new experimental code, so excluding them from
parallel-replicas suites is preferred over teaching each assertion to resolve
per-replica ProfileEvents rows.

Reverts the query_log/asynchronous_metric_log rework and adds the
no-parallel-replicas tag to 04327, 04328 and 04341. The tag suppresses both
injection paths in tests/clickhouse-test: the ParallelReplicas job passes
--no-parallel-replicas, so the tagged test is skipped there, and
adjust_settings_for_autopr does not enable the feature for a tagged test.

93 insertions / 32 deletions of test logic become 7 / 3 of tags and reasons.
@groeneai groeneai changed the title Fix three flaky ReaderExecutor tests under parallel replicas Exclude three ReaderExecutor tests from parallel replicas Aug 11, 2026
@groeneai

Copy link
Copy Markdown
Collaborator Author

Done, pushed as e4603d64a7dac6d: reverted the query_log rework and added no-parallel-replicas to 04327, 04328 and 04341. 93 insertions / 32 deletions of test logic became 7 / 3 of tags and reasons. Title and description updated.

The tag covers both injection paths for these tests: the ParallelReplicas job passes --no-parallel-replicas so a tagged test is skipped (tests/clickhouse-test:2858), and adjust_settings_for_autopr does not enable the feature for a tagged test (:1763-1772). Every observed carrier of these three is a Stateless tests (...) or Fast test job, so those two paths cover all of them.

One thing to flag rather than leave implicit: the stress runner appends enable_parallel_replicas=1 for a random 20% of workers without passing --no-parallel-replicas (ci/jobs/scripts/stress/stress.py:335), so the tag is not honoured there yet. #114279 fixes that path generically for all 446 tagged tests. These three have no stress failure in 120 days, so it is not a live carrier here, and the reverted version is in this PR's history at e378ec3c214df45e if you later want the assertions parallel-replicas-correct instead of skipped.

@@ -1,8 +1,10 @@
-- Tags: no-distributed-cache, no-encrypted-storage
-- Tags: no-distributed-cache, no-encrypted-storage, no-parallel-replicas

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ no-parallel-replicas is not enough to exclude these tests from every current parallel-replica carrier. tests/clickhouse-test only honors the tag in the regular stateless runner, but the stress path still invokes clickhouse-test --stress-tests with no tag-based filter (tests/docker_scripts/stress_runner.sh:308) and independently injects enable_parallel_replicas=1 on 20% of workers (ci/jobs/scripts/stress/stress.py:335-339).

Because this commit also restores the old single-row query_log assertions, these three tests are still eligible to run under parallel replicas in stress, so the PR does not actually exclude them from all in-tree parallel-replica suites. Please either wire no-parallel-replicas into the stress runner here, or keep the per-replica query_log rewrite until the generic stress fix lands.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The mechanism is correct and I stated it myself when I pushed the tags: tests/docker_scripts/stress_runner.sh has no tag-based filter (zero matches for no-parallel-replicas in that file) and ci/jobs/scripts/stress/stress.py:335-339 injects enable_parallel_replicas=1 for a random 20% of workers. The disagreement is whether that gap blocks this PR.

It does not, on two measurements. First, none of the 113 CIDB failure rows for these three tests in the last 120 days are on any Stress check; the same query over the last 7 days returns 2496 stress failure rows across 220 distinct tests, so it discriminates. Stress is not a carrier for these three tests.

Second, #114279 fixes that path generically rather than per test: it appends enable_parallel_replicas=0 last under --allow_repeated_settings, so it wins over a --client-option that turned the feature on, which is exactly how the stress runner injects it. That covers every tagged test instead of the three here.

So I am not keeping the query_log rewrite in this PR.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do that tests make the stress tests fail? why do we need to do it?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On the first question: I cannot answer it from CI history, and my earlier "stress is not a carrier" claim in this thread was not sound. I withdraw it.

The stress check does not record per-test rows in the CI database. Of 1,641,012 stress rows in the last 120 days, 1,883 carry a stateless test filename and none is newer than 2026-06-24; the same regex over Stateless tests% matches 433,782,807 rows, so the query itself works. These three tests first appear in the database on 2026-06-10 and 2026-06-17, so their overlap with the period when stress still recorded per-test rows is about two weeks, in which stress recorded 502 distinct test names in total. My "0 of 113 failure rows are on a Stress check" was therefore measuring a reporting gap, not stress behaviour.

On the second question: the reds these tags exclude are on the stateless parallel-replica flavours. In 120 days, excluding your two ReaderExecutor PRs and #111275, the three tests fail 8 times on Stateless tests (amd_llvm_coverage, ParallelReplicas, s3 storage, parallel), 6 on unrelated PRs and 2 on master (04341, at 9a5b5235c760 and 14fdcfc0d3d4). Both master runs are the same result diff, 1 1 1 1 reading 0 0 0 1. That flavour does honour the tag: ci/jobs/functional_tests.py:173 maps ParallelReplicas to --no-parallel-replicas, and tests/clickhouse-test:2858 skips a tagged test.

So the accurate claim is narrower than what I wrote earlier: this stops the master and unrelated-PR reds on the ParallelReplicas stateless flavours, and I do not know whether these tests also red under stress.

If you would rather narrow or drop this PR, that is fine by me: 8 rows in 120 days is small, and #114279 covers the stress path generically if it turns out to matter. Your call on scope.

@clickhouse-gh

clickhouse-gh Bot commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing e4603d64a with master dab347c4d (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
Binary Master PR Δ
programs/clickhouse-stripped 691.36 MiB 688.36 MiB -3.00 MiB (-0.43%)

Only the stripped binary is compared: the official master build keeps debug symbols while PR builds strip them, so the other binaries differ by construction.

Compile time of recompiled translation units

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

Job report

@groeneai

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - e4603d6

CI is fully finished on this head: 175 checks completed, 58 success, 117 skipped (each with a
recorded reason: not affected by the changed files x74, no build-affecting changes x25, only test
files changed and none of the changed tests apply x13, not a bug-fix PR x5, not labeled
pr-performance x6, reused from cache x3, plus 4 others). The high skip count is expected for a
test-only diff. The praktika report top-level status is OK with 0 dropped jobs, so the run
carries real coverage.

No failures. Nothing to own.

Session id: cron:our-pr-ci-monitor:20260811-223000

@CheSema CheSema self-assigned this Aug 12, 2026
@CheSema
CheSema added this pull request to the merge queue Aug 12, 2026
Merged via the queue into ClickHouse:master with commit a2da110 Aug 12, 2026
180 checks passed
@robot-ch-test-poll4 robot-ch-test-poll4 added the pr-synced-to-cloud The PR is synced to the cloud repo label Aug 12, 2026
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.

6 participants