Skip to content

Harden 04624_part_loading_tree_rollback_startup_recovery against stress restarts and leaked tables - #111661

Merged
alexey-milovidov merged 1 commit into
masterfrom
followup-111055-04624-gate-and-startup-recovery
Jul 24, 2026
Merged

alexey-milovidov merged 1 commit into
masterfrom
followup-111055-04624-gate-and-startup-recovery

Conversation

@alexey-milovidov

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

Copy link
Copy Markdown
Member

Description

Follow-up to #111055, addressing two review comments on the regression test 04624_part_loading_tree_rollback_startup_recovery.sh that arrived shortly before that PR was merged:

  • 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 hard-killed before its EXIT trap ran, while the leftover name still blocks the following CREATE TABLE. The test now calls recover_leaked_table once at startup, mirroring the cleanup of the four part_loading_tree_rollback tests.

  • 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 — the exact metadata corruption Detach tables permanently in part-loading-tree rollback tests #111055 fixes. The test now verifies the same fail-fast gate as the four rollback tests: the table is absent from system.tables and present in system.detached_tables with is_permanently = 1 before anything under DATA_PATH is touched.

The test output is unchanged; it passes locally against a 26.7.1 server.

Related: #111055

Changelog category (leave one):

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

Version info

  • Merged into: 26.8.1.60 (included in 26.8 and later)

…back_startup_recovery`

Two review comments on #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]>
@clickhouse-gh

clickhouse-gh Bot commented Jul 23, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [47763e4]

Summary: ✅


AI Review

Summary

This follow-up switches 04624_part_loading_tree_rollback_startup_recovery.sh to the same startup-recovery and permanent-detach gating pattern used by the other part_loading_tree_rollback tests. The new guard closes the plain-bash fallthrough for DETACH TABLE ... PERMANENTLY, but the script can still pass spuriously if a stress restart interrupts the earlier source-part setup, so I am requesting one more hardening change.

Findings

⚠️ Majors

  • [tests/queries/0_stateless/04624_part_loading_tree_rollback_startup_recovery.sh:64-72] The new postcondition only proves that the table is detached; it does not prove that the source part/path setup succeeded. If a restart lands on INSERT INTO ${TABLE} VALUES (42) or the SELECT data_paths[1] query, the cp/printf block below runs with a missing source part or empty DATA_PATH, those shell failures are ignored under plain bash, and recover_leaked_table later attaches and drops a healthy detached table. The test then still prints the reference output without ever creating the corrupted txn_version.txt it claims to recover from. Derive DATA_PATH only after the detach postcondition holds, and fail unless ${DATA_PATH}all_1_1_0 exists before the out-of-band copy.
Final Verdict

Status: ⚠️ Request changes

@clickhouse-gh clickhouse-gh Bot added the pr-ci label Jul 23, 2026
Comment on lines +64 to +72
DETACHED=$($CLICKHOUSE_CLIENT -q "
SELECT (SELECT count() FROM system.tables
WHERE database = currentDatabase() AND name = '${TABLE}') = 0
AND (SELECT count() FROM system.detached_tables
WHERE database = currentDatabase() AND table = '${TABLE}' AND is_permanently) = 1
")
if [ "${DETACHED}" != "1" ]; then
echo "FAIL: table ${TABLE} is not detached permanently, refusing to modify its data directory"
exit 1

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.

If the stress restart lands on the earlier INSERT INTO ${TABLE} VALUES (42) or SELECT data_paths[1] client call, this new postcondition can still become 1 and we then enter the cp/printf block with a missing source part or an empty DATA_PATH. Under plain bash those filesystem commands fail silently, recover_leaked_table later re-attaches a healthy detached table, and the test still prints the reference 1 / 0 / 0 / OK without ever creating the corrupted txn_version.txt it is supposed to recover from.

To actually harden the test against restarts, please prove the path/source precondition too: derive DATA_PATH only after this check from system.detached_tables.uuid + system.disks, and fail unless ${DATA_PATH}all_1_1_0 exists before the out-of-band copy.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Addressed in a follow-up, since this PR is already merged: #111730 derives DATA_PATH only after the detach gate, from system.detached_tables.uuid + system.disks (the same way recover_leaked_table does), and fails fast unless the source part ${DATA_PATH}all_1_1_0 exists before the out-of-band copy.

@alexey-milovidov

Copy link
Copy Markdown
Member Author

Another data point for this test family: on #110886 (head d9dbe4a6be1, includes #111055), Stress test (amd_asan_ubsan) failed with "Cannot start clickhouse-server" on 04417_part_loading_tree_rollback_evict_reinsert_contains:

Code: 246. DB::Exception: 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. This indicates disk corruption or a partial write: Cannot attach table test_7.t_plt_evict_reinsert ...

Report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=110886&sha=d9dbe4a6be104e3d7653b4f7ea0ff49d2ae15c26&name_0=PR&name_1=Stress%20test%20%28amd_asan_ubsan%29

The permanent-detach gate from #111055 is in that branch, so the stress restart appears to have landed in a window it does not cover — plausibly after the final successful ATTACH TABLE (table re-attached, fabricated parts live) while the rolled-back all_1_5_4_1 was being removed, leaving a partially deleted part directory whose txn_version.txt could not be read at the next startup. The hardening in this PR should probably be extended to 04417 (and the other siblings) as well.

@alexey-milovidov alexey-milovidov self-assigned this Jul 24, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Jul 24, 2026
Merged via the queue into master with commit 5699941 Jul 24, 2026
179 checks passed
@alexey-milovidov
alexey-milovidov deleted the followup-111055-04624-gate-and-startup-recovery branch July 24, 2026 01:50
@robot-ch-test-poll3 robot-ch-test-poll3 added the pr-synced-to-cloud The PR is synced to the cloud repo label Jul 24, 2026
pull Bot pushed a commit to Mu-L/ClickHouse that referenced this pull request Jul 24, 2026
…tree_rollback_startup_recovery`

Follow-up to ClickHouse#111661, addressing the
remaining review comment: the detach-postcondition gate alone did not prove that the
copy source exists. If a stress-test restart lands on the earlier `INSERT` or on the
`SELECT data_paths[1]` client call, the gate could still pass while `DATA_PATH` is
empty or the part `all_1_1_0` is missing; under plain `bash` the `cp`/`printf` would
fail silently and the test would print the reference output without ever fabricating
the corrupted `txn_version.txt` it is supposed to recover from.

Now `DATA_PATH` is derived only after the gate, from `system.detached_tables.uuid`
and `system.disks` (the same way `recover_leaked_table` does), and the test fails
fast unless the source part directory exists before the out-of-band copy.

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
…04624-gate-and-startup-recovery

Harden `04624_part_loading_tree_rollback_startup_recovery` against stress restarts and leaked tables
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
…tree_rollback_startup_recovery`

Follow-up to ClickHouse#111661, addressing the
remaining review comment: the detach-postcondition gate alone did not prove that the
copy source exists. If a stress-test restart lands on the earlier `INSERT` or on the
`SELECT data_paths[1]` client call, the gate could still pass while `DATA_PATH` is
empty or the part `all_1_1_0` is missing; under plain `bash` the `cp`/`printf` would
fail silently and the test would print the reference output without ever fabricating
the corrupted `txn_version.txt` it is supposed to recover from.

Now `DATA_PATH` is derived only after the gate, from `system.detached_tables.uuid`
and `system.disks` (the same way `recover_leaked_table` does), and the test fails
fast unless the source part directory exists before the out-of-band copy.

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.

2 participants