Skip to content

Do not enable parallel replicas for tests tagged no-parallel-replicas - #114279

Merged
PedroTadim merged 2 commits into
ClickHouse:masterfrom
groeneai:groeneai/no-parallel-replicas-tag-beats-injected-client-option
Aug 12, 2026
Merged

PedroTadim merged 2 commits into
ClickHouse:masterfrom
groeneai:groeneai/no-parallel-replicas-tag-beats-injected-client-option

Conversation

@groeneai

@groeneai groeneai commented Aug 11, 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 in #112052 (comment). Stress test (*) aborts servers with Logical error: 'Coordination mode mismatch for stream <db>.testing_105153: got Default, expected WithOrder', 20 times in 30 days across 20 unrelated pull requests and 10 stress jobs, 0 on master. This fixes the 18 carried by 04241_parameterized_view_used_twice; the other 2 are untagged tests enabling parallel replicas deliberately, a coordinator issue left to @ nickitat / @ devcrafter per #112052, so this PR does not eliminate the signature.

Root cause. The stress runner appends enable_parallel_replicas=1 (and async_insert=1) to --client-option for a random ~20% of its workers, ignoring test tags. clickhouse-test puts --client-option after the randomized settings on purpose, so under --allow_repeated_settings (last occurrence wins) nothing could turn the feature off again, and the tag's only other enforcement is a skip gated on --no-parallel-replicas, which the stress job never passes. All 440 tagged tests therefore ran with parallel replicas on there. 04241 aborts that way: it reads one table both in order and unordered in one query, and the coordinator map is keyed on stream_id alone.

Change. Append a tag-derived feature-off override last, where --allow_repeated_settings makes it win. A SET or SETTINGS clause still beats a client command line value, so the 15 tagged tests that manage parallel replicas themselves keep working. Same defect and fix for no-async-insert. Nothing in src/; no test is skipped or weakened, and the tag already gates the other injection path this way (adjust_settings_for_autopr).

Validation. Reproduced 04241's abort locally, then confirmed it passes, asserting the effective setting from system.query_log rather than only the verdict. A negative control disabling just the override brings the abort back. Across 55 tagged tests, in two arms differing only in tests/clickhouse-test, none regresses; of the 40 that do not manage the feature themselves, 16 go from failing to passing.

Fixed by this change (40 ordinary tagged tests, injection forced on)

Base 18 OK / 22 FAIL, with fix 34 OK / 6 FAIL. FAIL -> OK:

00944_minmax_nan, 01231_operator_null_in, 01891_not_in_partition_prune,
02346_text_index_dictionary_cache, 02346_text_index_drop_caches,
02346_text_index_header_cache, 02346_text_index_hint_profileevents,
02346_text_index_postings_cache, 02354_vector_search_drop_table_clear_cache,
02354_vector_search_quantize_codec_prewhere, 02354_vector_search_rescoring_and_prewhere,
02354_vector_search_rescoring_distance_in_select_list,
02679_explain_merge_tree_prewhere_row_policy, 02771_ignore_data_skipping_indices,
02798_explain_settings_not_applied_bug, 02835_join_step_explain.

The 6 remaining failures are identical in both arms (single-node harness: absent cluster
members, no minio). Their tags say why they wanted the feature off, for example
00944_minmax_nan: -- no-parallel-replicas: EXPLAIN output differs for parallel replicas.

Failing CI run:
https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=114085&sha=df7c307c738b4e8c97832dce3a735b541fd5d31c&name_0=PR&name_1=Stress%20test%20%28arm_asan_ubsan%2C%20s3%29

The stress runner appends enable_parallel_replicas=1 (and async_insert=1) to
--client-option for a random ~20% of its workers, without looking at test tags.
clickhouse-test deliberately places --client-option values after the randomized
settings, so with --allow_repeated_settings (last occurrence wins) nothing
downstream could turn the feature back off, and the tag's only other enforcement
is a skip gated on --no-parallel-replicas, which the stress job never passes.
Every one of the 447 tagged tests therefore ran with parallel replicas on in
those workers.

04241_parameterized_view_used_twice aborts the server that way: its first query
reads one table both in order (outer ORDER BY) and unordered (two IN-subqueries
through a parameterized view), the coordinator map is keyed on stream_id alone,
and the second announcement throws

  Logical error: 'Coordination mode mismatch for stream <db>.testing_105153:
  got Default, expected WithOrder'

which kills the worker and loses every remaining test in it. That accounts for
12 of the 14 stress hits of this signature in the last 30 days, across 12
unrelated pull requests and 8 stress jobs.

Append a tag-derived feature-off override last, where --allow_repeated_settings
makes it win. A SET or SETTINGS clause inside a test still beats a client
command line value, so the 15 tagged tests that manage parallel replicas
themselves keep working; this was verified from system.query_log in both the
.sql and .sh channels. The same defect and the same fix apply to
no-async-insert.

Measured on the 40 ordinary tagged tests exercised with the injection forced on:
16 go from failing to passing and none regress. Their tags say why, for example
00944_minmax_nan: "no-parallel-replicas: EXPLAIN output differs for parallel
replicas".

This does not skip, weaken or blacklist any test, and it does not touch the
coordinator. The remaining 2 of 14 hits come from untagged tests that enable
parallel replicas deliberately; that is a coordinator issue and is left to its
owners.

Related: ClickHouse#106039
@groeneai

Copy link
Copy Markdown
Collaborator Author
Internal second-model review (cold review + independent gate, 3 findings, 0 blocking)

Reviewed independently of the author, without the implementation notes, then a second model
re-reviewed the whole diff cold. Findings and my verdicts:

# Finding Verdict
💡 The new pytest binds the imported TestCase under its own name, so pytest emits one PytestCollectionWarning. ci/tests/test_expect_debuglog_separation.py aliases the same class to a non-Test* name for exactly this reason. Agreed, not blocking. Confirmed: pytest ci/tests/ --co collects 928 tests and emits exactly one such warning, from this file. Job status comes from per-test outcomes only, so it cannot turn CI Tests red, and all 5 tests pass. Cosmetic; happy to rename if a reviewer prefers.
💡 In the branch of add_effective_settings where there are neither randomized settings nor a --client-option value, the returned option string carries the override but not --allow_repeated_settings. Agreed, not blocking. With both inputs empty there is no earlier occurrence to repeat, so the single occurrence parses; .sh tests read the environment, which does carry the flag. The stress job always supplies --client-option, so this is not the shape being fixed.
⚠️ The module docstring is long. Disagreed. Consistent with neighbouring ci/tests files, which carry longer background blocks.

Also checked and clean, in case it saves a reviewer the trouble:

  • Every channel the tag has to reach. .sql (returned option string), .sh
    (CLICKHOUSE_CLIENT_OPT via shell_config.sh) and .expect
    (CLICKHOUSE_CLIENT_EXPECT_OPT, derived from the same variable, one tagged carrier exists)
    all get the override. The HTTP channel needs nothing: a --client-option value only reaches
    CLICKHOUSE_URL_PARAMS in cloud mode.
  • The one class that could have made this wrong is empty. Seven tagged tests set these
    settings on their own client command line rather than in SQL; all seven pass 0, never 1,
    so no test's own command line value is now beaten by the override. The 18 that opt back in do
    it with SET or SETTINGS, which is applied after the command line.
  • No test observes what changed. The three tests reading async_insert or
    enable_parallel_replicas out of system.settings or query_log are all untagged. The one
    tagged test asserting a Settings map checks named keys, never the key set or its size.
  • Tag counts, from clickhouse-test's own parser: 446 no-parallel-replicas,
    72 no-async-insert.
  • Zeroing only the enable_parallel_replicas alias is sufficient and is the narrower choice:
    every parallel-replicas entry gate requires that one field to be positive, and the non
    parallel-replicas readers of max_parallel_replicas are not newly reachable by it.

Same pattern at the same site as my open #109130, so whichever of the two merges second needs a
trivial rebase.

Session id: cron:clickhouse-review-slot-9:20260811-045300

@groeneai

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. One command, no probability: clickhouse-test --no-random-settings 04241_parameterized_view_used_twice --client-option enable_parallel_replicas=1 max_parallel_replicas=3 cluster_for_parallel_replicas='<3-replica cluster>' parallel_replicas_for_non_replicated_merge_tree=1 -> Reason: server died 32 with Logical error: 'Coordination mode mismatch for stream <db>.testing_105153: got Default, expected WithOrder' and the CI frames getOrCreateCoordinator:1448 / handleInitialAllRangesAnnouncement:1244
b Root cause explained? Yes. stress.py:336-340 injects enable_parallel_replicas=1 at p=0.2 ignoring tags; clickhouse-test places --client-option after the randomized settings so it wins under --allow_repeated_settings (BaseSettingsProgramOptions.h:13 -> values.back()); the tag's only other enforcement (:2883) is gated on --no-parallel-replicas, which the stress job never passes. So all 447 tagged tests ran with the feature on in those workers
c Fix matches root cause? Yes. Makes the existing tag effective in the one channel where it could not be. No widened bound, no reduced dataset, no skip, no blacklist, no defensive guard at the abort site, and no change to the coordinator
d Test intent preserved / new tests added? Yes. No existing test edited or weakened; 04241 keeps its tag. New pytest ci/tests/test_feature_tag_overrides_injection.py (5 tests). The 16 tagged tests that go from failing to passing are the tags' intent being restored, e.g. 00944_minmax_nan: -- no-parallel-replicas: EXPLAIN output differs for parallel replicas
e Both directions demonstrated? Yes. Same command: pre-fix abort, post-fix [ OK ]. Asserted from system.query_log, not just the verdict: the offending query records allow_experimental_parallel_reading_from_replicas = 1 before and unset (default 0) after. Plus a negative control that disables only the override on the fixed tree, which brings the abort back
f Fix is general across code paths? Yes. All three flag-gated tag skips enumerated: no-parallel-replicas (:2883) and no-async-insert (:2889) are settings injections, both fixed by one helper; no-flaky-check (:3035) gates a job mode, not a setting. no-old-analyzer uses a value predicate, a different shape. Fixed at the injection point. Both add_effective_settings branches covered (randomized, and the --no-random-settings upgrade-check shape)
g Fix generalizes across inputs? Yes. Both tags alone and together; tagged vs untagged; tags empty and None; .sql and .sh channels; 55 real tests exercised end to end. HTTP (CLICKHOUSE_URL_PARAMS) deliberately not widened: get_additional_client_options_url is consumed only in the args.cloud branch (:7110), so a --client-option injection never reaches the URL here
h Backward compatible? Yes, trivially. Nothing in src/, no setting default changed, no SettingsChangesHistory.cpp entry needed, no serialization or format change. Test harness only, and only for tests carrying one of the two tags
i Invariants and contracts preserved? Yes. With no tag applying, add_effective_settings returns the byte-identical previous string (pinned by the untagged pytest) and --allow_repeated_settings still appears in both outputs. remove_settings_from_env restores base_client_options unchanged, so nothing leaks between tests. Only the enable_parallel_replicas alias is pinned: all three Context::canUse*ParallelReplicas* gates require that one field > 0, and the other injected settings are inert once it is off

Session id: cron:clickhouse-impl-slot-40:20260811-032600

@groeneai

Copy link
Copy Markdown
Collaborator Author

cc @maxknv, could you review this? The stress job injects enable_parallel_replicas=1 through --client-option, which clickhouse-test places last on purpose, so no-parallel-replicas had no way to take effect there; this appends a tag-derived feature-off override after it, and a query-level SET still wins over both.

@PedroTadim

Copy link
Copy Markdown
Member

@groeneai are you sure this is the soluton? The no-parallel-replicas tag was broken this whole time?

@PedroTadim PedroTadim self-assigned this Aug 11, 2026
@@ -0,0 +1,131 @@
"""
Regression test for `no-parallel-replicas` / `no-async-insert` being inert against an

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.

@groeneai remove this test

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.

Removed in 894696d.

Requested by PedroTadim in review r3759637153.

The change in tests/clickhouse-test is covered end to end by the two-arm
sweep over 55 tagged tests recorded in the pull request description, which
exercises the real runner rather than the helper in isolation.
@groeneai

Copy link
Copy Markdown
Collaborator Author

Fair challenge. Yes on the diagnosis, and the honest answer to "the whole time?" is: that tag never worked against this one injection path, and it worked everywhere else. Numbers below are re-measured on the pushed head, not copied from the description.

Where the tag was inert. ci/jobs/scripts/stress/stress.py:336 appends enable_parallel_replicas=1 to --client-option for a random ~20% of workers without looking at tags (:358 does the same for async_insert=1). clickhouse-test places --client-option after the randomized settings deliberately (:2346, so a user value wins under --allow_repeated_settings), and the tag's only other enforcement, :2883, is gated on args.no_parallel_replicas, which only the dedicated ParallelReplicas job passes. So in the stress job nothing downstream could turn the feature back off.

I verified the precedence against the real client rather than assuming it, and the arms discriminate:

client args enable_parallel_replicas
--allow_repeated_settings 1 0 (what this change produces) 0
1 alone (control: injection as it is today) 1
0 then 1 (reversed) 1
1 0 + query-level SET ... = 1 1
1 0 + SETTINGS ... = 1 1
1 0 without --allow_repeated_settings rejected

So order decides rather than the value, and a test that wants the feature still gets it.

Where it worked fine. Everywhere else the tag is honoured: the ParallelReplicas job skips tagged tests, and the other injection path already consults the tag (SettingsRandomizer.adjust_settings_for_autopr). "Broken the whole time" is true only for the stress-runner path, and only for a fifth of its workers.

Scale. 440 tests carry no-parallel-replicas and 71 carry no-async-insert on the current tree. One correction to the description, which I will fix there: it says 446 and 72. Those two figures were counted in a tree that still held leftover gitignored .gen.sql renders, so the 6 .sql.j2 sources were each counted twice. 440 and 71 are the right numbers.

Why it only started aborting now. The injection dates to May 2024 (commit 5102c6e, renamed to enable_parallel_replicas in 32fa241, Sep 2024). The carrier is newer: 04241_parameterized_view_used_twice landed 2026-05-17 and was tagged the next day. It reads one table both in order and unordered in a single query, and the coordinator keys its map on stream_id alone, so the second announcement throws. CI history matches: 20 stress hits in 30 days across 20 pull requests and 10 stress jobs, 0 on master. 18 are this carrier, all of them since 2026-08-08; the other 2 are t1. The description says 14 because that was the count when I opened this yesterday morning; 6 more have landed since, all of them this carrier.

Scope, so this is not oversold. Those 2 t1 hits come from untagged tests that enable parallel replicas on purpose. They are the coordinator defect, they are not addressed here, and I left them to their owners per the discussion on the parent issue. This PR does not eliminate the signature.

Test removed as you asked, in 894696d. The PR is now one file, +25. The precedence and .sh-environment behaviour is still covered end to end by the two-arm sweep over 55 tagged tests in the description, which exercises the real runner; what is gone is the fast unit-level assertion on the option string, so a future refactor of that helper would be caught by the sweep rather than by a targeted test.

@alexey-milovidov alexey-milovidov added the can be tested Allows running workflows for external contributors label Aug 12, 2026
@clickhouse-gh

clickhouse-gh Bot commented Aug 12, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [894696d]

Summary: ❌

job_name test_name status info comment
Stress test (amd_msan) FAIL
Hung check failed, possible deadlock found FAIL cidb IGNORED
Stress test (arm_tsan) FAIL
Hung check failed, possible deadlock found FAIL cidb IGNORED
Stress test (arm_msan) FAIL
Hung check failed, possible deadlock found FAIL cidb IGNORED

AI Review

Summary

This PR makes tests/clickhouse-test append tag-derived enable_parallel_replicas=0 / async_insert=0 overrides after injected --client-option settings so no-parallel-replicas and no-async-insert tags win in the stress/CI harnesses again. I did not find a remaining correctness gap in the current code or in the already-discussed review points.

Final Verdict

✅ Approved

@groeneai

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - 894696d

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.

Check / test Reason Owner / fixing PR
Stress test (amd_msan) / Hung check failed, possible deadlock found cancelled DROP TABLE prometheus wedged in DatabaseCatalog::waitTableFinallyDropped via StorageTimeSeries::dropInnerTableIfAny (root elapsed 474 s) 113397 (external, open)
Stress test (arm_msan) / Hung check failed, possible deadlock found same signature (root elapsed 630 s, with DROP DATABASE ... SYNC and DETACH DATABASE victims behind it) 113397 (external, open)
Stress test (arm_tsan) / Hung check failed, possible deadlock found same signature (root elapsed 1052 s, two DROP DATABASE ... SYNC victims) 113397 (external, open)
CH Inc sync - CH Inc sync (private, not actionable)

All three hung_check.log artifacts read by hand; test_context_raw is truncated for this
signature so a CIDB context grep is not usable here.

Session id: cron:our-pr-ci-monitor:20260812-050000

@PedroTadim
PedroTadim added this pull request to the merge queue Aug 12, 2026
Merged via the queue into ClickHouse:master with commit 57f45c4 Aug 12, 2026
176 of 180 checks passed
@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added the pr-synced-to-cloud The PR is synced to the cloud repo label Aug 12, 2026
@groeneai groeneai added the groeneai-origin-request PR origin: a maintainer pinged or directed groeneai label Aug 19, 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 groeneai-origin-request PR origin: a maintainer pinged or directed groeneai 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.

4 participants