Skip to content

Split out and skip the statements that create a table from a SQL-created named collection on the replicated-database CI arm - #117234

Merged
alexey-milovidov merged 1 commit into
ClickHouse:masterfrom
groeneai:skip-named-collection-table-tests-on-replicated-database
Sep 6, 2026
Merged

alexey-milovidov merged 1 commit into
ClickHouse:masterfrom
groeneai:skip-named-collection-table-tests-on-replicated-database

Conversation

@groeneai

@groeneai groeneai commented Aug 31, 2026 •

Copy link
Copy Markdown
Collaborator

Related: #112052
Related: #112247

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

Two stateless tests are skipped on the replicated-database CI arm, and two are split so their remaining assertions keep running there.

Description

@ alexey-milovidov asked for this on #112052;
#112247's CI ledger owns 04511.

04511_remote_named_collection_complex_overrides, 04327, 04320 and 04626 fail the main pass
on every run of both Stateless tests (amd_llvm_coverage, ..., DBReplicated, ...) jobs with
Code: 159 ... ReplicatedDatabase DDL task ... is not finished on 2 of 3 hosts. The diagnostics
rerun drops --replicated-database and passes, so its flaky label force-sets coverage jobs to
OK unless the rerun also fails: over 25,000 such rows in 21 days, no genuine pass.

CREATE NAMED COLLECTION is server-global, not database-scoped, so it applies only on the receiving
host. CREATE TABLE inside a Replicated database is a replicated DDL entry, replayed on every
replica, where the collection is absent: it fails Code: 669 NAMED_COLLECTION_DOESNT_EXIST, then
enters lost-replica recovery, which replays the same metadata and fails identically. Raising
distributed_ddl_task_timeout cannot help, the entry never completes.

no-replicated-database is the repository's existing declaration for this: 18 of the 35 stateless
tests with CREATE NAMED COLLECTION already carry it, 8 with this reason string verbatim. These
four are the whole class. A dictionary built from its own collection is not a carrier: its
SOURCE resolves at load.

Only the refused statements are declared unsupported. 04511 and 04327 take the tag whole, every
assertion they make needs the collection. 04320 and 04626 do not, so their collection sections
move into new tests carrying the tag and the parents keep running: 9 of 12 reference lines for
04320, 19 of 22 for 04626, confirmed from the job's own query_log. Those parents assert
positional URL(...)/S3(...) table definitions, replicated DDL entries no other arm replays.

Not fixed here: the timeout reports the replicas as still executing after both failed
non-retriably; the recovery retry is unbounded.

CI report:
https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=112247&sha=66ee0b152db689826f5509ce55b0845246e1ae70&name_0=PR&name_1=Stateless%20tests%20%28amd_llvm_coverage%2C%20old%20analyzer%2C%20s3%20storage%2C%20DBReplicated%2C%20parallel%2C%201%2F3%29


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

…ted named collection on the replicated-database CI arm

`04511_remote_named_collection_complex_overrides`, `04327_s3queue_server_credentials`,
`04320_url_engine_dispatch_partition_and_format` and `04626_s3_base_setting` fail the main
pass on every run of the two `Stateless tests (amd_llvm_coverage, ..., DBReplicated, ...)`
jobs with

  `Code: 159. ReplicatedDatabase DDL task .../log/query-00000000NN is not finished on
  2 of 3 hosts (2 of them are currently executing the task, 0 are inactive).`

`CREATE NAMED COLLECTION` is server-global, not database-scoped, so it is not a `Replicated`
database DDL entry and is applied only on the host that receives it. A `CREATE TABLE` inside
a `Replicated` database is a replicated DDL entry and is replayed verbatim on every replica,
where the collection is absent, so it fails with `Code: 669 NAMED_COLLECTION_DOESNT_EXIST`
(retriable false). It is retried `max_retries_before_automatic_recovery` (10) times at about
5 s, then drives the replica into lost-replica recovery, which replays the same unloadable
metadata and fails identically: `DatabaseReplicatedWorker.cpp:122-134` retries
`initializeReplication` every 5 s with no bound. The initiator, which does have the
collection, creates the table locally and then waits out `distributed_ddl_task_timeout`.

Raising `distributed_ddl_task_timeout` is not the fix: the entry can never complete at any
speed. The queue is not stalled either, since every one of the more than 25,000 CIDB rows
that carry this message, for these four tests over 21 days, reports `0 are inactive`. Nor is
the coverage build part of the mechanism, since `Code: 669` is deterministic and
speed-independent, so the change is not scoped to the coverage flavour.

Almost every occurrence is then force-set to `OK`. The reproducibility rerun cannot reproduce
the failure as `diag_command` (`ci/jobs/functional_tests.py:1395-1403`) is built, because it
carries no `runner_options`, the only carrier of `--replicated-database`: `get_db_engine`
(`tests/clickhouse-test:860-872`) then creates the rerun's test database without the
`Replicated` engine, so the `CREATE TABLE` is host-local and succeeds.
`tests/clickhouse-test:4754-4758` sees `fail_n < total_n`, labels the test `flaky`, and
`ci/jobs/functional_tests.py:1433-1438` turns a `flaky` label into `Result.Status.OK` on
coverage jobs, which is why only these two lanes hide it. The linked report shows the same
mechanism from the other side: it comes from a branch that does forward those options, and
there the rerun reproduced the failure on every attempt with randomization disabled, kept the
`reproducible` label and left the job red. A job where more than ten tests fail also stays red,
since the diagnostics step is then skipped entirely (`:1385-1392`) and no label is produced.
The main pass fails every time; only the label varies. Each occurrence also wastes 120 s and
leaves both replicas' DDL worker wedged until the test drops its database.

`no-replicated-database` is this repository's existing declaration for such a test: 18 of
the 35 stateless tests containing `CREATE NAMED COLLECTION` already carry it, among them
`04512_remote_missing_named_collection.sh` (the sibling of `04511`) and
`04318_remote_storage_engine_access.sh` (the same `Remote(<collection>)` shape); 8 of the 18
use this exact reason string. None of the four tests `DatabaseReplicated` itself.

`04003_named_collection_drop_dependency_check_dict` and
`04010_mongodb_dictionary_named_collection` also build an object from their own collection
but are deliberately left untagged: a dictionary's `SOURCE` is resolved when the
dictionary is loaded rather than when it is created (`dictionaries_lazy_load` defaults to 1,
`src/Core/ServerSettings.cpp:1419`) and loading is local and on demand, so the replicated
DDL succeeds. Both are `OK` on every one of their more than 6,000 rows on the `DBReplicated`
arms over 21 days; tagging them would delete working coverage.

Only the refused statements are declared unsupported, so the granularity differs per file.
`04511_remote_named_collection_complex_overrides.sh` and `04327_s3queue_server_credentials.sh`
take the tag whole: every assertion they make needs the collection, and `04511`'s only
collection-independent statements are `remote(...)` table functions that execute locally and
replay no table definition. `04320_url_engine_dispatch_partition_and_format.sh` and
`04626_s3_base_setting.sh` are split instead. Their collection sections move into

  tests/queries/0_stateless/04320_url_engine_dispatch_partition_and_format_named_collection.sh
  tests/queries/0_stateless/04626_s3_base_setting_named_collection.sh

which carry the tag, and the two parents lose it and keep running: 9 of 12 reference lines for
`04320` and 19 of 22 for `04626`. That is coverage only this arm provides, because those
retained lines include positional `CREATE TABLE ... ENGINE = URL(...)` and `ENGINE = S3(...)`
definitions, which inside a `Replicated` database are themselves replicated DDL entries; the
17-21 other arms all use `Atomic` databases and never replay a table definition through a DDL
log. The failing job's own `query_log` artifact confirms it rather than inferring it: every
statement that stays in a parent finished with `exception_code = 0` on that arm, and the only
exceptions in either test are the four named-collection statements that move into the children
(`Code: 159`) plus `04626`'s deliberate no-scheme error (`Code: 36`), which is itself one of
the retained assertions.

Nothing is duplicated and nothing is dropped: for each split, the sorted parent and child
`.reference` files together equal the sorted original byte-for-byte, and every executable
statement of the original appears exactly once across the two scripts. The exceptions are
each child's `shell_config.sh` preamble and, for `04626`, its own `BUCKET_URL`/`FILE` and a
re-created seeding `INSERT`; that seed writes 5 rows rather than the parent's 3, because the
count assertion that moves with the section reads the file after the parent's later 5-row
relative `INSERT`.

Each tag sits on its file's single `Tags:` line because `find_tag_line`
(`tests/clickhouse-test:4310-4316`) returns only the first such line, so a second one would
parse as an ordinary comment and the change would be a silent no-op.

CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=112247&sha=66ee0b152db689826f5509ce55b0845246e1ae70&name_0=PR&name_1=Stateless%20tests%20%28amd_llvm_coverage%2C%20old%20analyzer%2C%20s3%20storage%2C%20DBReplicated%2C%20parallel%2C%201%2F3%29
Related: ClickHouse#112247
Related: ClickHouse#112052
@groeneai groeneai added can be tested Allows running workflows for external contributors groeneai-origin-ci-own-pr PR origin: CI on a groeneai PR exposed a separate defect labels Aug 31, 2026
@groeneai

Copy link
Copy Markdown
Collaborator Author
Internal second-model review (click to expand)

Five review rounds before publication: each round an automated cold review of the resulting tree, my
own independent review, and a fresh CI-history sweep. Rounds 1-3 and 5 found only prose defects; the
change itself was modified in exactly one round, round 4, which split two of the four files instead of
tagging them whole.

Finding Verdict
❌ The whole-file tag also removes the collection-independent assertions from three of the files (positional URL, the remote table function, s3/s3Cluster/s3_base); split each file instead. AGREE for 04320 and 04626, fixed by splitting them. Their retained assertions are CREATE TABLE ... ENGINE = URL(...) / ENGINE = S3(...) statements plus DETACH/ATTACH, and a CREATE TABLE inside a Replicated database is a replicated DDL entry replayed on every replica, so that lane covers something the other lanes (all Atomic) do not. Measured from the reference files, a whole-file tag would have dropped 9 of 12 lines in 04320 and 19 of 22 in 04626. DISAGREE for 04511: its two recoverable lines are remote(...) table-function SELECTs that execute locally and replay no table definition, so they add nothing that lane uniquely provides, and recovering them would mean duplicating its table and both collections. 04327 keeps the whole-file tag because it has no collection-independent assertion at all.
❌ Rewriting the description for the split dropped a qualification agreed in round 2: it again read as if the reproducibility check always force-sets these rows to OK. AGREE, restored: it does so unless the rerun also fails. The gate was then re-run against the corrected description, so the reviewed contract is the published one.
❌ The commit message cited the wrong line for the reproducibility whitewash. AGREE, fixed. The label decision is tests/clickhouse-test:4754-4758 and the force-to-OK is ci/jobs/functional_tests.py:1433-1438, which is also why only the coverage flavours hide this.
❌ The convention argument's three counts were wrong. AGREE, fixed. 35 tests contain CREATE NAMED COLLECTION (3 of the 38 matches are .reference files), 18 already carry a tag the runner parses, and 8 use this exact reason string.
❌ 04512 and 04318 were presented as examples of the tests using this exact reason string. AGREE, fixed. Both carry the tag, but for unrelated reasons; they now exemplify the 18 tag-carriers, with the 8 exact-reason files stated separately.
❌ The validation table claimed Failed 3 out of 3 reruns for all rows, contradicting the whitewash it relies on. AGREE, fixed. More than 25,000 rows report Failed 0 out of 3 reruns and every one is OK; exactly one row says 3 out of 3, and it stayed FAIL.
❌ The rerun was said to usually fail to reproduce the failure, printed next to a quoted Failed 0 out of 3 reruns that appears to refute it. AGREE, fixed. It cannot reproduce it at all: diag_command (ci/jobs/functional_tests.py:1395-1403) is built without runner_options, the only carrier of --replicated-database, so get_db_engine (tests/clickhouse-test:860-872) creates the rerun's database without the Replicated engine and the CREATE TABLE is host-local and succeeds. The single 3 out of 3 row comes from a branch that does forward that option, so it is the same failure seen from the other side.
❌ The commit message omitted the supplied CI report URL and its corresponding pull requests, and left literal SQL, class and setting names outside code spans. AGREE, both fixed.
⚠️ The description was over its length budget, and several counts were stated as absolutes although the 21-day window slides. AGREE, fixed. Condensed twice; each such figure is now a floor or a qualitative bound.
💡 Relationships should be full-URL lines, one relationship per line. AGREE, fixed. Raised in two separate rounds, so it is fixed rather than overridden. The template's own Related: lines sit inside an HTML comment, which does not render and creates no cross-reference; two visible Related: lines now precede the template block. The other half of that finding, moving the description above the changelog block, remains DISAGREED: reordering the ### headers makes the CI config workflow fail to parse. No header was moved, renamed or added.
💡 Tagging also skips these tests in the stress threads that run with a replicated database. DISAGREE, no change. That is the established behaviour of this tag; only the i % 3 == 2 threads pass --replicated-database, so the same file still runs in the others.

Verified independently rather than taken from the change author, since these are the claims a reader
would otherwise have to trust:

  • The four tests are the whole class. Sweeping all 35 named-collection stateless tests on
    check_name LIKE '%DBReplicated%' over 21 days returns exactly these four with is not finished on
    rows, with a control showing 35 of 35 are present on that arm and a bogus test name returning
    nothing. Every other candidate of the same apparent shape is excluded on mechanism and measures 0
    such rows: 03523 builds ENGINE = Kafka(<collection>) but under clickhouse-local; 04408 and
    03201 use only the remote table function; 04325 reaches its collections through s3 and
    BACKUP.
  • Nothing was lost or duplicated in the two splits. For each, sort of the parent plus child
    .reference equals sort of the original byte-for-byte, and every executable statement of the
    original appears exactly once across the two scripts. The one deliberate difference is the child of
    04626 seeding 5 rows where the parent seeds 3: the count assertion that moved with the section sat
    after the parent's later 5-row relative INSERT, so seeding 3 would silently have changed what it
    asserts.
  • No genuine pass is removed. Not one OK row on that arm is free of the timeout text; the only
    rows without it are UNKNOWN, not passes. Elsewhere all four stay green.
  • The timeout bump really is refuted, not merely doubted. Every row carrying the marker also
    reports 0 are inactive, with no exceptions.
  • The two dictionary tests are correctly left alone. Both are OK on every one of their more than
    6,000 rows on these arms, so tagging them would delete working coverage.
  • The tag is live, and its effect is observable. find_tag_line
    (tests/clickhouse-test:4310-4316) returns only the first Tags: comment, so appending to the
    existing line is what makes it parse and a second line would have been a silent no-op;
    should_skip_test consumes it at tests/clickhouse-test:3035. The already-tagged sibling
    04512_remote_missing_named_collection currently reports SKIPPED on both of these jobs, which is
    exactly the state these four will reach.
  • Every style rule that can reach a stateless .sh file was checked against the final tree, with
    the applicable set read off the style job's own dispatcher rather than guessed. Two are worth
    stating: the two new files query system.tables only with database = currentDatabase(), and the
    test-numbering check cannot fire because both reuse a number that is already present.

One observation while counting the precedents, noted because a reader who greps will count 19 rather
than 18: 02918_fuzzjson_table_function.sql:1 reads
-- Tags: no-parallel, no-replicated-database: Named collection is used. Tags are comma-split and
matched exactly, so that file's tag is the whole string including its explanation and the skip never
fires. It is not affected by the failure this pull request addresses, since its collection is only
ever read by the fuzzJSON table function, so I have left it alone.

Session id: cron:clickhouse-review-slot-9:20260831-012800

@groeneai groeneai added the groeneai-origin-ci-own-pr PR origin: CI on a groeneai PR exposed a separate defect label Aug 31, 2026
@groeneai

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. In CI it is 100% deterministic, not flaky: it fails the main pass on every run of the two DBReplicated jobs, and more than 25,000 rows in 21 days carry the is not finished on message. Their diagnosis is Failed 0 out of 3 reruns, because the diagnostics rerun is invoked without --replicated-database and so runs without the Replicated database engine, which is exactly what labels them flaky and therefore force-sets them to OK; the one row whose diagnosis said 3 of 3 is from a branch that does forward that option to the rerun, and it correctly stayed FAIL. Locally I reproduced the causal error on demand: CREATE TABLE t ENGINE = Remote(nc_absent, sharding_key = rand()) with no such collection returns Code: 669 ... There is no named collection (NAMED_COLLECTION_DOESNT_EXIST), which is byte-for-byte what the replicas log. The full 3-host Code: 159 needs the 3-server/3-keeper CI cluster, so I read that half verbatim from the job's own clickhouse-server1.log.zst and clickhouse-server2.log.zst at millisecond resolution.
b Root cause explained? Yes. CREATE NAMED COLLECTION is server-global, not database-scoped, so it lands only on the host that receives it. CREATE TABLE inside a Replicated database is a replicated DDL entry and is replayed verbatim on every replica, where the collection is absent, so it fails Code: 669, is retried 10 times at ~5 s (max_retries_before_automatic_recovery), then drives the replica into lost-replica recovery, which replays the same unloadable metadata and fails identically (DatabaseReplicatedWorker.cpp:122-134 retries every 5 s, unbounded). The initiator has the collection, creates the table locally, and waits out the 120 s distributed_ddl_task_timeout.
c Fix matches root cause? Yes. The tag declares the unsupported feature combination, which is exactly what the failure is. It is not a widened bound, a data reduction or a no-random-* blanket. I explicitly refuted the timeout bump on data rather than suspicion: the entry can never complete at any speed, and every one of those rows that carries the message reports 0 are inactive, so the queue is not stalled either. The build speed is not part of the mechanism, so the fix is deliberately not coverage-scoped.
d Test intent preserved / new tests added? Yes, and no assertion was dropped. 04511 and 04327 change only header comment lines (every added and removed line starts with #; comment-stripped bodies byte-identical to base by sha256, with a control proving the stripper is not vacuous). 04320 and 04626 are split instead: their named-collection sections move into two new tests that carry the tag, and the two parents lose it and keep running. Coverage is conserved as a multiset, not by assertion: for each split, sort of parent + child .reference equals sort of the original byte-for-byte, and every executable statement of the original appears exactly once across the two .sh files. Both checks carry a firing control (dropping one reference line makes the comparison differ). The only added statements are each child's two-line shell_config.sh preamble and, for 04626, its own BUCKET_URL/FILE plus a re-created seeding INSERT of 5 rows rather than the parent's 3, because the child's reference line asserts 5; seeding 3 instead makes the child FAIL with result differs, which is how I established the number rather than assuming it. No source code changed, so no new regression test is required.
e Both directions demonstrated? Yes, on the runner's own decision function. Driving TestCase.should_skip_test over a 29-arm matrix: on --replicated-database the decision is None at base (the test runs, then fails as CI shows) and replicated-database with the fix, for all four tests. Same flip on --cloud.
f Fix is general across code paths? Yes. I swept all 35 stateless tests containing CREATE NAMED COLLECTION (38 git grep matches, three of which are .reference files): 18 already carry the tag, 2 create the collection inside clickhouse-local, 11 never create a persistent object from the collection (2 build a dictionary, whose SOURCE resolves at load; 3 reach it only through a table function; 6 never persist it or only name the statement), and 4 are fixed here. A 21-day CIDB sweep over all 35 on the DBReplicated arms shows that only these four produce is not finished on rows, and a presence control confirms 35 of 35 do appear on that arm, so the query missed nothing. The class enumeration is unchanged, still exactly these four carriers, but two of them are now split rather than tagged whole, because the refusal reaches only some of their statements. I read the failing job's own query_log artifact for both (PR 112247 is not the only sighting; I used PR 115623 sha 9b52646c, whose blob for each file is byte-identical to our base): every statement that stays in a parent finished with exception_code = 0 on the DBReplicated arm, and the only exceptions in either test are the four named-collection statements that move into the children (Code: 159) plus 04626's deliberate no-scheme error (Code: 36), which is itself a retained assertion. I also confirmed host-local filesystem paths are not a second carrier: all three CI servers deliberately share one user_files directory, and 04320's file:// arms succeed on that arm in the same run.
g Fix generalizes across inputs (params/datatypes/wrappers)? Yes, across the engines that accept a named collection. The four carriers already span Remote, S3, S3Queue and URL; I checked MySQL, PostgreSQL, MaterializedPostgreSQL, NATS, MongoDB, Kafka and ArrowFlight as well, and every stateless test creating a persistent object from a collection is either already tagged or in the table-function class. CREATE DATABASE ... ENGINE = URL('file://') is not a carrier, since a CREATE DATABASE is not a DDL entry of the test database.
h Backward compatible? (maintainer-approved exception only) N/A. No setting default, no serialization or format change, no new validation, so no SettingsChangesHistory.cpp row is needed. The change is four comment lines in test headers.
i Invariants and contracts preserved? Yes. The invariant being declared is that a persistent DDL object inside a Replicated database must not reference a host-local resource. Nothing executable changed, and the skip decision is identical to base on 108 of 116 arm/file combinations, changing only on the two replicated arms it is meant to change. On --shared-catalog all four were already skipped by an earlier gate, so that arm is untouched too.

Session id: cron:clickhouse-impl-slot-41:20260831-004800

@clickhouse-gh

clickhouse-gh Bot commented Aug 31, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [1ec2a21]

Summary: ✅


AI Review

Summary

This PR splits the named-collection-only assertions out of 04320 and 04626, and adds no-replicated-database to the test cases whose replicated-database failure mode comes from replaying CREATE TABLE against server-local named collections. I did not find an actionable new correctness or coverage problem in the current PR head beyond tradeoffs the author already documented in the PR discussion.

Final Verdict

✅ No new review findings.

@groeneai

Copy link
Copy Markdown
Collaborator Author

cc @tuanpach, could you review this? Four stateless tests create a table from a SQL-created named collection, and a named collection is server-global, so inside a Replicated database that CREATE TABLE is replayed on replicas which do not have the collection and the DDL entry can never complete; two of the four take no-replicated-database whole, and two are split so their collection-independent assertions keep running on that arm.

@clickhouse-gh clickhouse-gh Bot added the comp-testing Test content only (no production code). label Sep 4, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Sep 6, 2026
Merged via the queue into ClickHouse:master with commit 7168724 Sep 6, 2026
175 of 176 checks passed
@robot-clickhouse-ci-2 robot-clickhouse-ci-2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Sep 6, 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 comp-testing Test content only (no production code). groeneai-origin-ci-own-pr PR origin: CI on a groeneai PR exposed a separate defect 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