Skip to content

Pin part_loading_tree_rollback tests to the local default storage policy - #111922

Merged
alexey-milovidov merged 2 commits into
ClickHouse:masterfrom
groeneai:harden-plt-rollback-upgrade-check
Jul 28, 2026
Merged

alexey-milovidov merged 2 commits into
ClickHouse:masterfrom
groeneai:harden-plt-rollback-upgrade-check

Conversation

@groeneai

@groeneai groeneai commented Jul 25, 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

Related: #111053

The five part_loading_tree_rollback tests (04063/04241/04417/04500/04624) fabricate MergeTree parts out of band: they cp -r a committed part directory and write a raw plaintext txn_version.txt into it, then attach or restart-recover and assert PartLoadingTree rollback behavior. This has two hard dependencies on the table living on the local default disk:

  1. On an object-storage disk every file in a part directory must be in DiskObjectStorageMetadata format, so the raw plaintext txn_version.txt fails to parse (Code 27). The loader then treats the transaction status as unreadable and, for the fabricated intersecting part pairs, throws CORRUPTED_DATA:
Cannot parse input: expected '\n' before: 'version: 1\nstoring_version: 0\ncreation_tid: (2, 33, ...)'
MergeTreeData: Failed to read version metadata for part all_1_5_4_1: Code: 27
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. ... (CORRUPTED_DATA)
  1. Each test's cleanup / recover_leaked_table computes the fabricated-part path from the default disk (SELECT path FROM system.disks WHERE name = 'default'), which is only correct if the table's data actually lives there.

The tests do not pin the storage policy, so any harness that sets an object-storage default MergeTree policy without passing --s3-storage / --azure-blob-storage to clickhouse-test (those flags are what arm the no-object-storage tag) runs them in a broken configuration. The Stress check is exactly such a harness: stress_runner.sh never forwards --s3-storage / --azure-blob-storage to clickhouse-test, while its policy randomization makes an object-storage default in roughly two thirds of runs. On those runs the tag is inert and the fixture attach fails, so 04063/04241/04417/04500 report FAIL: ATTACH TABLE threw an exception for a configuration problem rather than for the rollback regression they exist to catch, and 04624 fails differently and silently: its uuid-based recovery rm -rf is computed from the default disk and misses the real object-storage data path.

Fix: pin all five tests to SETTINGS storage_policy = 'default' (04624 on both of its CREATE TABLE statements). A policy named default is never redefined by the test configs, and StoragePolicySelector synthesizes it over the local default disk when it is not explicitly configured, so this makes both dependencies correct by construction on any server default policy and restores the tests' intended coverage on object-storage-default Stress runs. The part-loader CORRUPTED_DATA guard is left untouched: it must keep failing loud on genuine corruption. No assertions change.

The same signature also fires in the Upgrade check, for example https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=108091&sha=8397a5cad3ccb556cbda7e2a4f56cdf789169737&name_0=PR&name_1=Upgrade%20check%20%28amd_release%29 (Upgrade check (amd_release)). That check does pass --s3-storage, but it runs the previous release copies of the test files, which no change to master's tests can reach. It is addressed separately by #111772, which forwards the storage flags in the runner so the skip tags fire there. This PR is complementary: it removes the tests' dependency on the server default policy at the source, which acts immediately in the Stress check where those flags are not forwarded. There is no file overlap and no ordering constraint between the two.

The pin mechanism was originally in #110999, which was closed as superseded by #111055; #111055 fixed the separate stress-restart poisoning but not the object-storage mismatch, which is what this PR addresses (now also extended to 04624).

Verified locally: on an object-storage-default server the unpinned CREATE reproduces the failure (attach -> Code 246, plus the startup errors quoted above after a restart), and the pinned CREATE on the same server attaches cleanly with correct part active states and zero startup errors. The family passes 50x (04417) and 15x each (siblings), and all five pass against their .reference.

Version info

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

The five part_loading_tree_rollback tests (04063/04241/04417/04500/04624)
fabricate MergeTree parts out-of-band with a raw plaintext txn_version.txt
and remove them via a path derived from the `default` disk. Both steps only
work when the table lives on the local default disk, but harnesses that set
an object-storage default MergeTree policy without passing --s3-storage to
clickhouse-test (the Stress check, and the Upgrade check before ClickHouse#111772) run
these tests anyway: the raw fixture file does not parse as object-storage
metadata (Code 27 -> CORRUPTED_DATA on attach), and the uuid-based recovery
rm -rf misses the real data path. Pinning storage_policy = 'default' makes
the fixture and the recovery path correct on any server default policy and
restores the tests' intended coverage on object-storage-default Stress runs.

Related: ClickHouse#111053
@groeneai

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

Pre-publication review by an independent model (engine: codex; 1 finding), plus my own cold
review of the resulting diff (3 findings) before reading the author's evidence notes.

# Sev Finding Verdict Evidence / action
1 ⚠️ PR description overstated the failure mode: it claimed the coverage loss on object-storage-default Stress runs is silent and that the test self-heals via its cleanup trap AGREE — fixed before publication Not silent for 4 of 5: 04063/04241/04417/04500 gate the attach (if ! ATTACH ... echo 'FAIL: ATTACH TABLE threw an exception'; exit 1, e.g. 04417:150-153), so they record a FAIL. Description now states the accurate split: those four report a FAIL for a configuration problem rather than the regression they exist to catch, and 04624 is the one that fails silently (its uuid-derived rm -rf is computed from the default disk and misses the object-storage data path)
2 ⚠️ Description referenced startup error lines that were not present in the body, and omitted the canonical CI report URL AGREE — fixed before publication Quoted the three-line CORRUPTED_DATA startup signature inline so the reference resolves, and added the full canonical report URL with the check name (Upgrade check (amd_release)). Also documented why the pin provably resolves to a local disk: StoragePolicySelector synthesizes the default policy over DEFAULT_DISK_NAME when it is not explicitly configured (StoragePolicy.cpp:512-516) and no test config redefines a policy or disk named default
3 💡 PR/commit metadata should carry full GitHub URLs and CI report URLs, and the links should be added in a new commit rather than by amending DISAGREE The template's "use full GitHub URLs" governs the relationship block, which is verbatim compliant (Related: https://github.com/ClickHouse/ClickHouse/issues/111053); the extra visible Related: #111053 exists because the HTML comment does not render, and GitHub expands it to the same link. The canonical CI report URL is present in the description. On "new commit rather than amend": this branch has never been pushed, so amending is the history-clean operation and a links-only commit would be pure churn

Severity: ❌ blocker / ⚠️ major / 💡 nit. DISAGREE verdicts carry recorded evidence and are
terminal per finding.

Independently verified and found clean: the pin resolves to a local disk on every harness
(no test config redefines a policy or disk named default; DiskSelector registers a local
DiskLocal named default when absent); the Stress-check exposure is real (stress_runner.sh
randomizes an object-storage default in ~2/3 of runs and never forwards
--s3-storage/--azure-blob-storage, which is what arms the no-object-storage tag); the
Upgrade check runs the previous-release test copies, so this PR correctly claims to complement
#111772 rather than to fix that path; all five family members are pinned (04624 on both of its
CREATE TABLE statements); no assertion was weakened and the part-loader CORRUPTED_DATA guard
is untouched; the sibling raw-txn_version.txt tests are correctly out of scope because they
derive paths from system.parts/system.detached_parts rather than the default disk.

Session id: cron:clickhouse-review-slot-8:20260725-220200

@groeneai

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. On a local_blob_storage object-storage-default server (mimics an object-storage default merge_tree policy), the unpinned 04417 sequence throws Code: 246 (CORRUPTED_DATA) on ATTACH every run, and after a restart the startup loader logs the exact CORRUPTED_DATA startup signature.
b Root cause explained? Yes. The tests write a raw plaintext txn_version.txt into the part dir and derive the fabricated-part removal path from the default disk. On an object-storage disk the raw file cannot parse (Code 27), so the loader throws CORRUPTED_DATA for the intersecting fabricated pair, and the uuid-based recovery rm -rf misses the real data path. Any harness that sets an object-storage default policy without passing --s3-storage to clickhouse-test (the Stress check) runs the family in this broken configuration; no-object-storage is inert because --s3-storage is not forwarded.
c Fix matches root cause? Yes. Pin the fixture tables to the local default policy so the raw file parses and the recovery path resolves, on any server default policy. The part-loader corruption guard is left untouched (not a band-aid: this pins the tests' own intrinsic local-disk dependency).
d Test intent preserved / new tests added? Yes. All 5 tests keep their exact PartLoadingTree rollback scenarios and assertions; only storage_policy is pinned. No source (product) code changed, so no new regression test is required; the family already IS the regression coverage and still passes 100% locally.
e Both directions demonstrated? Yes. Same binary, config swap as the sole variable: unpinned CREATE on the object-storage-default server FAILS (Code 246 + startup errors); pinned CREATE on the SAME server PASSES (ATTACH succeeds, correct part states, 0 startup errors).
f Fix is general across code paths? Yes. All 5 family members are pinned (not just the 2 firing in CIDB), 04624's second CREATE included, so future members copy the now-pinned pattern. Non-family raw-txn_version.txt fabricators (03752/03916/04104/04492/04493/04507) have 0 upgrade/stress hits in 30d and are out of this PR's scope, noted for monitoring.
g Fix generalizes across inputs (params/datatypes/wrappers)? N/A for type wrappers (no data-type logic touched). The relevant axis is the server default storage policy {local, object-storage} x {5 tests}, covered by the pin (always resolves to local) plus the two-config proof.
h Backward compatible? (maintainer-approved exception only) Yes. Test-only; no settings/format/protocol change, no SettingsChangesHistory.cpp needed. storage_policy='default' is always available.
i Invariants and contracts preserved? Yes. The part-loader CORRUPTED_DATA guard is deliberately untouched (must keep failing loud on genuine corruption). The tests' detach/recover invariants are unchanged; the pin only makes the uuid-based recovery derivation (which targets the default disk) correct by construction.

Session id: cron:clickhouse-review-slot-8:20260725-220200

@groeneai

Copy link
Copy Markdown
Collaborator Author

cc @tiandiwonder - could you review this? Test-only: the five part_loading_tree_rollback tests fabricate a raw plaintext txn_version.txt and derive their cleanup rm -rf path from the default disk, so pinning storage_policy = 'default' is what makes both correct on harnesses that set an object-storage default policy without forwarding --s3-storage to clickhouse-test (the Stress check).

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

clickhouse-gh Bot commented Jul 26, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [305085b]

Summary: ✅


AI Review

Summary

This PR pins the five part_loading_tree_rollback stateless tests to SETTINGS storage_policy = 'default' so their out-of-band part fabrication and cleanup stay on the local default disk even when the harness randomizes an object-storage MergeTree default policy. I reviewed the current diff, the PR discussion, the relevant test scripts, and the current CI state, and I did not find a remaining correctness or coverage gap in the change itself.

Final Verdict
  • Status: ✅ Approve

@groeneai

Copy link
Copy Markdown
Collaborator Author

CI finish ledger — a326008

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
Stateless tests (amd_asan_ubsan, distributed plan, parallel) / 04625_hash_table_sizes_stats_table_expression_modifiers flaky under randomized max_bytes_before_external_group_by (external GROUP BY skips the prealloc path, so the asserted 520000/650000 stats come back 0); 14 distinct PRs + 2 master hits in 30d, none of which touch this test or HashTablesStatistics a fix task is moved to pending (investigating at full effort - fixing PR link to follow on this PR)
CH Inc sync - CH Inc sync (private, not actionable by me)

Not PR-caused: this PR only pins storage_policy='default' in five part_loading_tree_rollback .sh tests. It does not touch 04625, aggregation, or the hash-table-sizes-statistics path.

Session id: cron:our-pr-ci-monitor:20260726-063000

@groeneai

Copy link
Copy Markdown
Collaborator Author

Fixing PR for the 04625_hash_table_sizes_stats_table_expression_modifiers line in the finish ledger above: #111502 (pins max_bytes_before_external_group_by=0 and max_bytes_ratio_before_external_group_by=0 in the test, which is the culprit randomized setting). Verified green on 04625 across every shard of that PR's own run.

@groeneai

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - a326008

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.

Check / test Reason Owner / fixing PR
Stateless tests (amd_asan_ubsan, distributed plan, parallel) / 04625_hash_table_sizes_stats_table_expression_modifiers result-diff under randomized max_bytes_before_external_group_by #111502 (external, open)

Fast test, Style check and Bugfix validation are green on this head; this PR only pins the storage policy of the 04417 part_loading_tree_rollback tests, so the 04625 result-diff is unrelated.

Session id: cron:our-pr-ci-monitor:20260726-163000

@alexey-milovidov alexey-milovidov self-assigned this Jul 26, 2026
@alexey-milovidov

Copy link
Copy Markdown
Member

@groeneai

Functional tests shall not fabricate or manually intervene with the data parts, outside of what is reachable from the ClickHouse API surface. Find all tests that violate this rule and transform them to an integration test.

@groeneai

Copy link
Copy Markdown
Collaborator Author

I enumerated the stateless suite for this rule: 25 tests write into a server-owned part directory at a path derived from system.parts / system.disks / system.tables.data_paths, which is outside the API surface.

Fabricate part directories or raw part metadata (18):

  • 04063_part_loading_tree_rollback_reparent, 04241_part_loading_tree_rollback_contains, 04417_part_loading_tree_rollback_evict_reinsert_contains, 04500_part_loading_tree_rollback_tmp_metadata, 04624_part_loading_tree_rollback_startup_recovery - cp -r a committed part under a fabricated name, then write a plaintext txn_version.txt.
  • 04104_transaction_version_metadata_dummy_tid_load, 04492_attach_as_replicated_clears_tmp_txn_version, 04493_attach_part_clears_tmp_txn_version, 04507_packed_part_stale_txn_version_guard - write txn_version.txt.tmp.
  • 04235_corrupted_columns_substreams_detection, 04401_dynamic_mutation_old_part_no_substreams_file, 04412_mutation_old_part_basic_map_partial - write or delete columns_substreams.txt.
  • 04511_check_table_broken_projection_columns - overwrite p1.proj/serialization.json.
  • 04323_text_index_marks_empty_part - append a byte to skp_idx_idx.mrk4 and delete checksums.txt.
  • 04506_packed_part_fetch_checksum - dd into data.packed.
  • 04151_unique_key_sst_rebuild_on_load - truncate and swap unique_key_index.sst.
  • 04063_drop_detached_part_with_try_n_suffix - cp -r inside detached/.
  • 04246_materialize_index_force_recalc - mkdir detached/<part> and untar a committed fixture into it.

Corrupt or delete parts the server itself wrote (7): 02253_empty_part_checksums, 02254_projection_broken_part, 02255_broken_parts_chain_on_start, 02369_lost_part_intersecting_merges, 02370_lost_part_intersecting_merges, 02444_async_broken_outdated_part_loading, 04215_replicated_missing_covered_part_on_start.

Same rule, not a part directory: 03001_matview_columns_after_modify_query (sed -i on the table's metadata .sql), 04054_backup_restore_validate_entry_paths and 04495_backup_metadata_version_overflow (edit the .backup file on the backups disk).

Checked and excluded as read-only or API-surface: 04093_rename_column_corrupts_columns_substreams, 04326_disks_app_read_checksums, 02980_s3_plain_DROP_TABLE_MergeTree, 02980_s3_plain_DROP_TABLE_ReplicatedMergeTree.

Plan: convert into one integration module per mechanism instead of 25 modules, reusing helpers/corrupt_part_data_on_disk.py and exec_in_container, so each test owns its disk configuration explicitly instead of assuming a local default disk. Order: the five part_loading_tree_rollback tests first, since those are the ones going red on the object-storage and encrypted-storage runs, then the txn_version group, then the rest. I would also add a style check that rejects write-side filesystem operations on paths derived from system.parts / system.disks under tests/queries, so the rule is enforced rather than remembered. Say the word if you would rather not have that check.

On this PR: it only pins storage_policy = 'default' on the five carriers. I read it as the stopgap to land now, with the conversion in separate PRs, and will leave it alone otherwise.

@alexey-milovidov

Copy link
Copy Markdown
Member

@groeneai, go ahead with this plan.

@groeneai

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - 305085b

CI fully finished on this head: Finish Workflow, Mergeable Check, PR, Style check and CH Inc sync all green, no job queued or running, zero FAIL/ERROR test rows across all checks (122528 result rows ingested for this commit).

Check / test Reason Owner / fixing PR
(none) - -

This head is a plain master merge on top of the previously ledgered a326008586918f700a5faf67c93327ea1cf7d4a7. The single red that head carried (Stateless tests (amd_asan_ubsan, distributed plan, parallel) / 04625_hash_table_sizes_stats_table_expression_modifiers) is gone on this build.

Session id: cron:our-pr-ci-monitor:20260728-053000

@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Jul 28, 2026
Merged via the queue into ClickHouse:master with commit 1125231 Jul 28, 2026
178 checks passed
@robot-ch-test-poll2 robot-ch-test-poll2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Jul 28, 2026
groeneai added a commit to groeneai/ClickHouse that referenced this pull request Jul 30, 2026
Master modified all five stateless part_loading_tree_rollback tests that this
branch deletes, so every conflict is a modify/delete pair. Resolved delete-wins:
the conversion supersedes the master-side change.

The master-side commit is a326008 "Pin part_loading_tree_rollback tests to
the local default storage policy" (ClickHouse#111922), the stopgap that pinned
storage_policy = 'default' so a raw plaintext txn_version.txt would still parse
on jobs whose default policy is object storage. That knowledge is already carried
by the integration module: create_table_with_one_part pins the same setting and
documents why. Nothing from the master side is lost by dropping these files.

Coverage was verified before resolving. Four of the deleted tests map one to one
onto test_reparent, test_contains, test_evict_reinsert_contains and
test_tmp_metadata. The fifth, 04624_part_loading_tree_rollback_startup_recovery,
has no counterpart and needs none: its own header states it regression-tests the
bash cleanup helper shared by the other four, recovering from a table leaked in
the DETACH TABLE ... PERMANENTLY state by a run killed before its EXIT trap. The
integration module uses DETACH TABLE ... SYNC, has no shared shell helper, and
creates and tears down its cluster per module, so that leak cannot survive into a
later run. It also derives the part directory from system.parts.path instead of
reconstructing it from the default disk and the table uuid, which is the very
fragility 04624 existed to guard. No ClickHouse behaviour is covered by 04624
alone.
rorylshanks pushed a commit to rorylshanks/ClickHouse that referenced this pull request Jul 31, 2026
Functional tests must not fabricate or manually intervene with data parts
outside what the ClickHouse API surface exposes. A stateless test that writes a
plaintext file into a part directory silently assumes the part lives on a local
default disk: on an object-storage disk every file inside a part directory must
be in DiskObjectStorageMetadata format, so a raw plaintext txn_version.txt
cannot deserialize, part loading fails with CORRUPTED_DATA and the server does
not start. The cleanup path derived its target from the default disk, so on an
object-storage policy it also missed the real data path and leaked the poisoned
part, breaking every later start. That assumption cannot be expressed in a
stateless test because the harness owns and randomizes the disk configuration,
and the no-object-storage skip tags were inert because the harness did not
forward the matching flag. An integration test owns its own server and disk
configuration, so the assumption becomes explicit and enforced by construction.

The four PartLoadingTree::add rollback scenarios move into one module with their
fabricated part lattices and transaction-metadata payloads preserved byte for
byte, and their assertions strengthened from per-part active counts to
whole-active-set equality. Each scenario's liveness was verified by mutation:
breaking its fabrication produces exactly the failure that scenario exists to
catch, and the outcomes differ per scenario - the containment arm never consults
the transaction status, so its mutation lets ATTACH succeed and only the
active-set assertion catches the regression.

04624_part_loading_tree_rollback_startup_recovery is deleted without a
replacement. Its subject was the stateless-only DETACH TABLE ... PERMANENTLY
cleanup helper, machinery that only existed to survive a stress-test server
restart landing mid-script; an integration test owns its server, so the subject
ceases to exist. Nothing in it reached PartLoadingTree::add.

This removes the Stress-suite failures, which run the master tree's test files.
It does not affect the Upgrade check, which clones the previous release tag and
runs its frozen test files.

Related: ClickHouse#111053
Related: ClickHouse#111922
pull Bot pushed a commit to sowelswl/ClickHouse that referenced this pull request Aug 23, 2026
StorageLog::saveFileSizes recorded the size of each stream separately, and
each FileChecker::update does IO that can throw. A throw partway through
left new sizes recorded for streams 0..k-1 and old ones for k..n. Because
the insert had not finished, ~LogSink calls FileChecker::repair(), which
truncates every file to its recorded size, so adjacent streams of one array
column were left at different generations: the outer offsets then described
more elements than the inner streams held, and a sort over such a column
indexed the elements out of bounds.

A throw inside save() has the opposite effect. Its four throw points sit
after the map has been updated, and the data files were appended in place,
so repair() truncates nothing and an insert that reported failure keeps its
rows.

FileChecker::updateAndSave() now collects the sizes into a candidate map,
persists that, and adopts it only once the persist has succeeded, so the
recorded sizes and the files can no longer disagree. StorageStripeLog had
the same defect and is fixed the same way.

The marks file is itself one of the files whose size is recorded, so a
rollback to the old sizes truncates it. saveMarks() had already advanced
num_marks_saved by that point, which left removeUnsavedMarks() discarding
nothing and the in-memory marks describing a file that no longer contained
them. The counter is restored when the size commit fails, in both storages
and on both the insert and the backup restore paths.

LogSource::readData() already validated the type of the column it
deserialized. It now also validates, at every nesting level, that an array's
last offset matches the number of elements it holds, and raises
INCORRECT_DATA naming the column instead of passing a column that lies about
its own length to the query pipeline.

The write defect was found while investigating a ColumnArray::indexImpl
assertion failure in BuzzHouse (amd_tsan), STID 2508-2944. How the table in
that run reached the inconsistent state is not established: its log records
no truncation by repair(), so this commit path is not shown to be what
produced it, which is why the read side is validated as well.

Tests: 04931_log_family_failed_insert_commit covers the write half over Log,
TinyLog and StripeLog and both failure windows, using failpoints conditioned
so they fire on the commit at the end of the insert rather than on the empty
baseline commit the sink makes at construction.
test_storage_log_damaged_array covers the read half; it edits data files
directly, so per ClickHouse#111922 it cannot be a functional test.
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 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