Skip to content

Detach tables permanently in part-loading-tree rollback tests - #111055

Merged
alexey-milovidov merged 8 commits into
masterfrom
fix-04241-plt-stress-restart
Jul 23, 2026
Merged

alexey-milovidov merged 8 commits into
masterfrom
fix-04241-plt-stress-restart

Conversation

@alexey-milovidov

@alexey-milovidov alexey-milovidov commented Jul 20, 2026 •

Copy link
Copy Markdown
Member

Description

Since 2026-07-19, stress test runs across sanitizers fail with Cannot start clickhouse-server: the server cannot load the table created by one of the part_loading_tree_rollback tests (04241_part_loading_tree_rollback_contains, 04063_part_loading_tree_rollback_reparent, 04417_part_loading_tree_rollback_evict_reinsert_contains, 04500_part_loading_tree_rollback_tmp_metadata) because its fabricated transaction metadata is corrupted, throwing Cannot parse input from VersionInfo::readFromMultiLineBuffer (or Part ... intersects previous part ... and the transaction metadata of at least one of them could not be read) at startup. This hits master and many unrelated PRs.

These tests fabricate part directories out-of-band (cp -r, printf > txn_version.txt.tmp, mv) while the table is only non-permanently DETACH-ed. Stress tests restart the server at arbitrary moments; a plain DETACH does not survive a restart, so the table is loaded again at startup while the script is still fabricating files inside its data directory, and the server's version-metadata machinery (VersionMetadataOnDisk) races with the script on the same txn_version.txt(.tmp) files, leaving corrupted metadata behind. Once corrupted, every subsequent server start fails, failing the whole stress run.

Fix: DETACH TABLE ... PERMANENTLY in all four tests of the family, which keeps the table detached across restarts; the explicit ATTACH TABLE in the tests still re-attaches it.

Additionally (per review), the detach client call alone is not a sufficient gate: the scripts run under plain bash, so a failed detach (e.g. a restart landing on it) would fall through into the file-fabrication block. Each test now verifies the detach postcondition — the table is absent from system.tables and present in system.detached_tables with is_permanently = 1 — and fails fast before touching anything under the table's data path.

Also per review, cleanup now handles a permanently detached table: DROP TABLE IF EXISTS silently does nothing on it while its name still blocks CREATE TABLE, so on failure paths that exit before ATTACH TABLE succeeds the table used to leak for the rest of the run. If the table is still detached, cleanup first removes the fabricated part directories (whose transaction metadata is exactly what could have made ATTACH throw), re-attaches the table, and then drops it.

Closes: #111053
Caused by: #100992
Related: #110246
Related: #109004

Example report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=110246&sha=72768ce112527547fd077031893e6c2c7404b30f&name_0=PR&name_1=Stress%20test%20%28arm_msan%29
Example report (04417, on #109004): https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=109004&sha=e26111dca401681dbc6b4ba4a9c42b6fe23a4a36&name_0=PR&name_1=Stress%20test%20%28amd_tsan%29

Changelog category (leave one):

  • CI Fix or improvement (changelog entry is not required)

The `04241_part_loading_tree_rollback_contains` and
`04063_part_loading_tree_rollback_reparent` tests fabricate part
directories out-of-band while the table is `DETACH`-ed. A plain
`DETACH` does not survive a server restart, and stress tests restart
the server at arbitrary moments — the table is then loaded again at
startup while the script is still writing `txn_version.txt(.tmp)`
files, and the server's version-metadata machinery races with the
script on those files, leaving corrupted metadata behind. Every
subsequent server start then fails with `Cannot parse input` while
loading the table, which fails the whole stress run with "Cannot
start clickhouse-server".

Use `DETACH TABLE ... PERMANENTLY` so the table stays detached across
restarts; the explicit `ATTACH TABLE` still re-attaches it.

Closes: #111053
Example report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=110246&sha=72768ce112527547fd077031893e6c2c7404b30f&name_0=PR&name_1=Stress%20test%20%28arm_msan%29

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

clickhouse-gh Bot commented Jul 20, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [bf7895c]

Summary: ✅


AI Review

Summary

This PR updates the four part_loading_tree_rollback shell tests to keep the table detached across stress-test restarts, gates the out-of-band filesystem mutations on the permanent-detach postcondition, makes cleanup recover leaked permanently detached tables before re-attaching and dropping them, and adds 04624_part_loading_tree_rollback_startup_recovery to cover the previously missing startup-recovery path. I re-read the current diff, prior review threads, and the current Praktika report, and I did not find any remaining correctness issues in the current head.

Final Verdict

Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-ci label Jul 20, 2026
… tests

The `04417_part_loading_tree_rollback_evict_reinsert_contains` and
`04500_part_loading_tree_rollback_tmp_metadata` tests fabricate part
directories out-of-band while the table is `DETACH`-ed, exactly like
their siblings already fixed in this PR, and hit the same corruption
under stress-test restarts: a stress run of #109004 failed with
`Part all_5_6_1_0 intersects previous part all_1_5_4_1 and the
transaction metadata of at least one of them could not be read` while
loading `t_plt_evict_reinsert` at startup, failing the run with
"Cannot start clickhouse-server".

Use `DETACH TABLE ... PERMANENTLY` in these two tests as well.

Example report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=109004&sha=e26111dca401681dbc6b4ba4a9c42b6fe23a4a36&name_0=PR&name_1=Stress%20test%20%28amd_tsan%29
Related: #109004

Co-Authored-By: Claude Fable 5 <[email protected]>
…ondition

The `DETACH TABLE ... PERMANENTLY` client call alone is not a sufficient
gate: `clickhouse-test` runs `.sh` tests under plain `bash`, so if the call
fails (e.g. a stress-test server restart lands on it), the script would keep
running and mutate a table directory that may still be attached, re-opening
the `txn_version.txt` corruption race. Verify that the table is absent from
`system.tables` and present in `system.detached_tables` with
`is_permanently = 1`, and fail fast before touching anything under the
table's data path.

#111055
@alexey-milovidov

Copy link
Copy Markdown
Member Author

The single stateless failure 04507_mvt_encode_state_serialize (Stateless tests (amd_llvm_coverage, ParallelReplicas, s3 storage, parallel)) is unrelated to this PR: it is CANNOT_CONVERT_TYPE when a folded Variant constant is serialized back to AST for a distributed/parallel-replicas query (FunctionCast::createColumnToVariantWrapper). A fix is already in progress: #111136.

A permanently detached table is invisible to `DROP TABLE` (`DROP TABLE IF
EXISTS` silently does nothing) while its name still blocks `CREATE TABLE`,
so on failure paths that exit before `ATTACH TABLE` succeeds the old
`cleanup` leaked the table for the rest of the run. Now, if the table is
still detached, `cleanup` first removes the fabricated part directories
(whose transaction metadata is exactly what could have made `ATTACH` throw),
re-attaches the table, and then drops it, in all four tests of the family.

Verified against a live server: with an `ATTACH` failure injected in-test,
the new `cleanup` leaves no trace in `system.tables` or
`system.detached_tables`.

Co-Authored-By: Claude Fable 5 <[email protected]>
alexey-milovidov added a commit that referenced this pull request Jul 24, 2026
Pulls in #111055 (fix for the unrelated stress-test startup failure #111053,
'Part all_5_6_1_0 intersects previous part' in 04241_part_loading_tree_rollback)
so the Stress test (amd_tsan) red can clear on the next CI run.
https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=109453&sha=948d74cabe4714a6f98d0d0f0e7e1a6e8518ad19&name_0=PR&name_1=Stress%20test%20%28amd_tsan%29
pull Bot pushed a commit to SINHASantos/ClickHouse that referenced this pull request Jul 24, 2026
…_tree_rollback_startup_recovery`

Two review comments on ClickHouse#111055 arrived
shortly before the merge and were not addressed there:

- The plain `DROP TABLE IF EXISTS` at startup silently does nothing on a table leaked
  in the permanently detached state by a previous run that was killed before its `EXIT`
  trap ran, while the leftover name still blocks `CREATE TABLE`. Call
  `recover_leaked_table` at startup instead, mirroring the rollback tests' `cleanup`.

- The test fabricated a corrupt `txn_version.txt` right after `DETACH TABLE ...
  PERMANENTLY` without verifying the detach postcondition. Under stress a restart can
  land on the detach and, under plain `bash`, the script would fall through and write
  into a still-attached table's directory. Add the same fail-fast gate on
  `system.tables` / `system.detached_tables` with `is_permanently = 1` that the four
  rollback tests use.

Co-Authored-By: Claude Fable 5 <[email protected]>
pull Bot pushed a commit to Mu-L/ClickHouse that referenced this pull request Jul 27, 2026
…-encrypted-storage

The Upgrade check configures the server with object storage as the default
MergeTree policy (configure --s3-storage) and randomly enables encrypted
storage, but ran clickhouse-test without --s3-storage and never forwarded
--encrypted-storage. So clickhouse-test had args.s3_storage / args.encrypted_storage
= False and ignored its storage skip tags (no-object-storage, no-s3-storage,
no-encrypted-storage): those branches in should_skip_test fire only when the
matching argument is set. Tests declared incompatible with the configured
backend then ran on an unsupported one.

This produced the Upgrade check (amd_release) Code 27 / Code 246 failures on
the four 04063/04241/04417/04500_part_loading_tree_rollback_* tests (all tagged
no-object-storage): they fabricate a raw plaintext txn_version.txt in a part
directory (valid only on a local disk), which is unreadable on an object-storage
disk, so PartLoadingTree::add (from ClickHouse#100992) reports CORRUPTED_DATA at the test's
own ATTACH. With --upgrade-check (which implies --fake-drop) the corrupt part
survives into the new server, which logs the parse error at part load.
ClickHouse#111055 / ClickHouse#111661 hardened these tests on master, but the Upgrade check runs the
frozen previous-release test suite, so those changes cannot reach it.

Forward --s3-storage (in the clickhouse-test command) and --encrypted-storage
(mirroring the coin flip, via stress.py) so clickhouse-test matches the server's
actual configuration and skips incompatible tests, as the regular stress runner
already does.

Related: ClickHouse#111053

Co-Authored-By: Claude Opus 4.8 <[email protected]>
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
…ondition

The `DETACH TABLE ... PERMANENTLY` client call alone is not a sufficient
gate: `clickhouse-test` runs `.sh` tests under plain `bash`, so if the call
fails (e.g. a stress-test server restart lands on it), the script would keep
running and mutate a table directory that may still be attached, re-opening
the `txn_version.txt` corruption race. Verify that the table is absent from
`system.tables` and present in `system.detached_tables` with
`is_permanently = 1`, and fail fast before touching anything under the
table's data path.

ClickHouse#111055
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
…ress-restart

Detach tables permanently in part-loading-tree rollback tests
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
…_tree_rollback_startup_recovery`

Two review comments on ClickHouse#111055 arrived
shortly before the merge and were not addressed there:

- The plain `DROP TABLE IF EXISTS` at startup silently does nothing on a table leaked
  in the permanently detached state by a previous run that was killed before its `EXIT`
  trap ran, while the leftover name still blocks `CREATE TABLE`. Call
  `recover_leaked_table` at startup instead, mirroring the rollback tests' `cleanup`.

- The test fabricated a corrupt `txn_version.txt` right after `DETACH TABLE ...
  PERMANENTLY` without verifying the detach postcondition. Under stress a restart can
  land on the detach and, under plain `bash`, the script would fall through and write
  into a still-attached table's directory. Add the same fail-fast gate on
  `system.tables` / `system.detached_tables` with `is_permanently = 1` that the four
  rollback tests use.

Co-Authored-By: Claude Fable 5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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.

Stress tests: Cannot start clickhouse-server — corrupted txn_version.txt of fabricated parts from 04241_part_loading_tree_rollback_* tests

3 participants