Repository navigation
Stop stateless tests from leaving the shared database Replicated - #113794
Conversation
Fixes a LOGICAL_ERROR "Digest does not match" server abort in Stress test (arm_tsan), STID 5007-4590. No product code is at fault: the assertion in DatabaseReplicated::commitAlterTable correctly detected a real disk-vs-memory divergence that two tests manufactured between them. In shared-database mode the stress lane points some clients at one long-lived database (ci/jobs/scripts/stress/stress.py:272). That database is created once at startup and never recreated per test, so whatever a test leaves behind persists for the whole run. 03762_create_as_url_cluster.sql re-created it as Replicated and never restored it. The no-replicated-database tag cannot react to that, because the guard reads a static CLI flag (tests/clickhouse-test:2928) and the runner never re-reads the database's actual engine. Later 04545_attach_projection_part_offset_setting_disabled.sh ran in that database; its DETACH was refused with Code: 80, its helper ignored the status, and sed -i rewrote the metadata of a live, attached table. getMetadataHash re-reads that file from disk (src/Databases/DatabaseReplicated.cpp:995-997) while tables_metadata_digest still carried the pre-sed hash, so the next successful ALTER aborted the server. On restart the replica was declared lost and one table was moved to <db>_broken_tables. Two independent halves, tests only: - Fail closed in the two tests that rewrite table metadata, 04545 and 03001, which are the complete in-tree set of such tests: a refused DETACH now prints the server's own error and exits 1 instead of letting the rewrite proceed. exit 1 rather than return 1 is required, because 03001's DETACH is at script top level where bash rejects return and then continues into the rewrite with the script still exiting 0. - Stop the leak at its source: 03762 and 04365 create their Replicated database as CLICKHOUSE_DATABASE_1 instead of re-engining the shared one, with DROP DATABASE IF EXISTS both before and after. The leading drop makes each test immune to a predecessor's leftover scratch database, the trailing one stops it becoming that predecessor. The shared database is never dropped, recreated or re-engined, so the property holds by construction rather than by cleanup. That distinction matters because the lane's background killer SIGTERMs a randomly chosen client on one branch of its three-second loop (ci/jobs/scripts/stress/stress.py:200-209, :755), so a restore-at-the-end fix is skipped on exactly the path where the leak was observed. No .reference file changes: every edit is either a guard that fires only on failure or a database identifier retarget that emits no output. 03224_invalid_alter.sql and 02483_add_engine_full_column_to_system_databases.sql still leave a Replicated shared database behind. Neither is this failure's carrier and both need materially more invasive rewrites, so they are deliberately out of scope here.
Internal second-model review (2 rounds, 3 findings adjudicated)Before publishing I reviewed this change cold against the resulting tree, then had an independent
💡 Under-cited claim (fixed) - the clause about the lane's background killer asserts both the ❌ "Six sibling tests can still leave the shared database The mechanism is real and I concede it: a What fails is the consequence. Reaching the abort additionally requires a test that rewrites on-disk Two further points: none of the six named tests is touched here, so any exposure is pre-existing |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-self-slot-57:20260807-051400 |
|
cc @tuanpach, could you review this? It is test-only: in shared-database mode the stress lane reuses one long-lived database, |
|
@tuanpach I think the logical error is not expected? |
|
Workflow [PR], commit [9060bee] Summary: ✅ AI ReviewSummaryThis PR hardens the two metadata-rewrite tests and moves the four current-database PR Metadata
Findings
|
Review feedback: {CLICKHOUSE_DATABASE_1} is not a per-test name. shell_config.sh:9 derives
it as ${CLICKHOUSE_DATABASE}_1 and clickhouse-test:3685-3695 passes that same value to every
.sql test in the client, so with --database (stress workers i%2==1) it is shared and, per
clickhouse-test:4046, never recreated. A run interrupted between the CREATE and the trailing
DROP therefore leaves the scratch database behind for later tests.
Measured on a leaked Replicated test_1_1: a bare CREATE DATABASE fails Code: 82
DATABASE_ALREADY_EXISTS, an IF NOT EXISTS one silently inherits the Replicated engine, and a
later DETACH TABLE is refused Code: 80. 19 of the 86 in-tree tests that create _1 have no
leading DROP, so the exposure is real.
A genuinely per-test name is not constructible in a .sql test: the runner passes only
CLICKHOUSE_DATABASE, _1 and _2, all derived from the shared name, and
{CLICKHOUSE_TEST_UNIQUE_NAME} resolves to Code: 456 UNKNOWN_QUERY_PARAMETER because it is a
shell-only export. That is why every in-tree Replicated-database-with-unique-name test is a
.sh test. Converting both tests to .sh would be a much larger diff for a narrower gain.
Move to _2 instead, which is a strict improvement on the same one-line shape: contended
consumers drop from 105 files to 3, hard-failing bare creators from 19 to 0, and all three
remaining _2 consumers already bracket with DROP DATABASE IF EXISTS. The bracketing DROPs are
kept, so an interrupted run self-heals on the next run of the test.
Verified: both tests pass in per-test and in shared-database mode; after the shared-database
run the shared database is still Atomic with no leftover; with a Replicated _2 injected
beforehand the test still passes and cleans up. Negative control: the pre-change 03762 passes
green while leaving the shared database Replicated, which is the defect this PR fixes.
The digest LOGICAL_ERROR does not relocate: the only two tests that rewrite on-disk metadata
(03001, 04545 -- the 2 of 7 sed -i users that also read metadata_path) operate in
currentDatabase() and reference neither _1 nor _2.
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
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 units7 translation units recompiled, 7 s compile time in total, 6 of them have a recent master baseline. |
…tch database
02483 and 03224 recreated {CLICKHOUSE_DATABASE} itself as Replicated. With
--database=test_N that name is shared by every test in the client, so both left
the shared database Replicated for whatever ran next, which is the same defect
this PR closes for 03762 and 04365.
Measured in shared-database mode against a plain shared database (26.8.1.1
debug): 02483 passed green and left test_1 Replicated; 03224 likewise. After the
move both leave the shared database Atomic with no scratch leftover, and 03224's
stdout is byte-identical to the pre-change run, so the assertions are unchanged.
02483 pinned its path and its predicate to currentDatabase(); both now name the
scratch database explicitly, and its reference gains the _2 suffix because the
runner only normalizes the base name.
Not touched: 02072, 03321, 03362, 03655 and 04239 delete the shared database
outright rather than re-engining it. That is a separate class from the digest
assertion this PR is about.
Co-Authored-By: Claude Fable 5 <[email protected]>
…cated Retargeting the last phase to the scratch database removed the only cleanup of phase 3's test3: the old DROP DATABASE deleted it. With --database the harness skips per-test cleanup, so test3 survived the run and 03266_with_fill_staleness_cases does a bare CREATE TABLE test3. Verified in shared-database mode: the table was still there afterwards, and is gone now. The DROP pins ignore_drop_queries_probability = 0 because the stress runner sets it to 0.2, which would make the DROP a no-op; 02354_vector_search_concurrent_readers pins it the same way. The retarget itself had no oracle: every renamed database is absent from the output, so reverting it still produced the full expected result while leaking. Assert the invariant instead of a specific engine, since the engine depends on the runner flags. Verified by mutation: with the retarget reverted the new line prints 1 and the test fails; with it in place it prints 0. Co-Authored-By: Claude Fable 5 <[email protected]>
| -- ignore_drop_queries_probability = 0: the stress runner sets it to 0.2, which makes a DROP a no-op. | ||
| DROP TABLE test3 SETTINGS ignore_drop_queries_probability = 0; | ||
|
|
||
| -- {CLICKHOUSE_DATABASE} must not be re-engined: with --database it is shared by every test in |
There was a problem hiding this comment.
03224 still mutates the worker's shared current database earlier in the file: lines 44-46 do DROP DATABASE {CLICKHOUSE_DATABASE} followed by CREATE DATABASE {CLICKHOUSE_DATABASE} ON CLUSTER ... ENGINE = Atomic.
In the odd stress workers, clickhouse-test creates that --database=test_i only once at startup and never recreates it per test, while stress.py can SIGTERM the client mid-file. A kill after the DROP but before the CREATE leaves the shared database missing for later tests in the same worker, so this file still violates the same shared-database isolation invariant that motivated moving the later Replicated phase onto {CLICKHOUSE_DATABASE_2}.
Please move the Atomic phase onto a scratch database as well, or otherwise stop dropping/recreating {CLICKHOUSE_DATABASE} here.
@PedroTadim Do you mean throwing LOGICAL_ERROR when the digests are mismatched? |
|
As the author of the PR this thread is on, the concrete instance that prompted it was test-induced, so the assertion was reporting a real divergence rather than a false one. STID One scope detail, since it is what made this instance hard to diagnose: the throw is guarded by The design call is yours. Whichever way it goes, the failure it caught here was real. |
CI finish ledger - 9060beeCI finished with no failing checks at this head: 177 leaves, 53 OK, 124 skipped, 0 dropped,
The two earlier Session id: cron:our-pr-ci-monitor:20260814-083000 |
I didn't check well. This PR is fixing tests, thanks. |
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
...
Description
Fixes a
LOGICAL_ERROR: Digest does not matchserver abort inStress test (arm_tsan)(STID
5007-4590). No product code is at fault: the assertion correctly detected a divergence twotests manufactured between them.
Root cause. In shared-database mode the stress lane points some clients at one long-lived
database (
get_options,stress.py), created once and never recreated, so leftovers persist forthe whole
run.
03762_create_as_url_cluster.sqlre-created it asReplicatedand never restored it;no-replicated-databasecannot prevent that, because the guard reads a static CLI flag(
should_skip_test,clickhouse-test).04545_attach_projection_part_offset_setting_disabled.shthen ran there,
its
DETACHwas refused withCode: 80, and because the helper ignored that statussed -irewrote a live table's metadata. The next
ALTERcompared that file against the stale in-memorydigest and aborted.
The change, two independent halves, tests only.
04545,03001, the completein-tree set): a refused
DETACHnow prints the server's error andexit 1s instead of lettingthe rewrite proceed.
03762,04365,02483,03224) now build theirReplicateddatabase as{CLICKHOUSE_DATABASE_2:Identifier},bracketed by
DROP DATABASE IF EXISTS. That holds by construction rather than by cleanup,because the lane's killer SIGTERMs a random client on one branch of its 3 s loop
(
RandomQueryKiller._run,stress.py), skipping any cleanup-at-the-end fix._2because thescratch aliases
are shared too (
shell_config.sh) but far less contended: 3 consumers against 105, with 0bare creators against 19.
Validation. Under the
database_replicated_force_metadata_digest_checkfailpoint theALTERaborts before the change with a stack matching the CI artifact frame-for-frame, and after it
succeeds with the database still
Atomic. In shared-database mode,02483and03224previouslypassed green while leaving it
Replicated; now all four leave itAtomic, no scratch leftover.Mutation matrix and scope notes
Each mutant reverts one half and reddens only its own property:
DETACHrefused, metadata not rewritten, no abort: half 1 alone stops the corruptionDROPdeleted, predecessor's scratch database presentCREATEfailsCode: 82; with theDROPit succeedsexit 1toreturn 1at03001's top levelreturn, continues into the rewrite, exits003224retarget reverted, oracle kept1and the test fails; with the retarget,002483's reference pins the database name, so its retarget is self-checking.03224's was not:every renamed database is absent from its output, so reverting it still produced the full expected
result. It now asserts the invariant (
engine = 'Replicated'must be false forcurrentDatabase())rather than a specific engine, since the engine depends on the runner flags. Retargeting its last
phase also removed the only cleanup of its phase-3
test3, so it drops that table explicitly,pinning
ignore_drop_queries_probability = 0as02354_vector_search_concurrent_readersdoes.A per-test database name is not available to a
.sqltest: the runner passes onlyCLICKHOUSE_DATABASE,_1and_2(the--param_CLICKHOUSE_DATABASE*arguments the runnerbuilds), all derived from the shared
name;
{CLICKHOUSE_TEST_UNIQUE_NAME}is shell-only and resolves toCode: 456.Not addressed:
02072,03321,03362,03655and04239delete the shared database outrightinstead of re-engining it, a different class from this digest assertion.
Version info
26.8.1.1393(included in26.8and later)