Repository navigation
Convert part_loading_tree_rollback tests from stateless to integration - #112000
alexey-milovidov merged 8 commits into
Conversation
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
…ctive Review fix round r1 on the part_loading_tree_rollback conversion. test_evict_reinsert_contains asserted only the active part set, so a regression that dropped the orphan all_2_3_1_0 instead of covering it with the reinserted container all_2_4_2_0 passed identically. It now asserts the full name-to-active map after SYSTEM WAIT LOADING PARTS, which Outdated parts require because they load asynchronously. A mutation expecting the orphan absent rather than inactive fails, so the new dimension is live. Its docstring claimed the test pins the (level, mutation) descending sort in evict_and_reinsert. It does not: collect walks children, a std::map keyed on MergeTreePartInfo, so the container 2-4 is already emitted before the part 2-3 it contains, and the incoming 5-6 is disjoint from both. Removing the sort leaves the outcome unchanged. The docstring now says so explicitly, and notes that all_2_3_1_0 and all_5_6_1_0 share (level, mutation) = (1, 0) while build uses a non-stable std::sort, so their relative order is unspecified and the asserted outcome holds either way. The module-scope SYSTEM STOP MERGES was inert. startStopAction with no table locks only the tables that exist at that moment, keyed per IStorage, and the fixture ran before any CREATE TABLE; the lock also does not survive the DETACH/ATTACH cycle that destroys the storage instance. Merges are now stopped per table after CREATE and again after each ATTACH. Co-Authored-By: Claude Fable 5 <[email protected]>
A background merge would rewrite the part set these tests assert on. Issuing SYSTEM STOP MERGES after ATTACH TABLE cannot prevent that: ATTACH runs IStorage::startup() before it returns, and StorageMergeTree::startup schedules the background assignee immediately, so a merge can be selected before the next statement reaches the server. The fabricated parts are byte-identical clones of one small part, so they are structurally mergeable and the window is narrow rather than closed. Setting max_bytes_to_merge_at_max_space_in_pool = 0 in the table metadata makes the storage come up with merging already off on every startup, including the one inside ATTACH. It is enforced before any merge selector runs: getMaxSourcePartsBytesForMerge returns 0 and the merge selection short-circuits with "Current value of max_source_parts_bytes is zero". The per-table SYSTEM STOP MERGES is kept as a redundant second line and its docstring no longer claims to close the startup window.
…nction references Two docstrings presented a tied (level, mutation) pair as a determined sequence. PartLoadingTree::build sorts with a non-stable std::sort keyed only on (level, mutation), so in test_contains the pair all_1_2_1_0 / all_3_4_1_0 (both (1, 0)) and in test_tmp_metadata the pair all_2_3_0_0 / all_1_1_0 (both (0, 0)) may be inserted in either order. Simulating PartLoadingTree::add over both permutations gives the same active set in both tests, so the assertions are correct as written and unchanged; only the descriptions were over-precise. test_reparent gets no such note - its parts have a strict total order under the sort key, so a tie disclaimer there would be false. Also write prose references to functions as f rather than f(), per AGENTS.md. No executable code changed: the module's AST with docstrings stripped is byte-identical to the previous commit.
…nous The helper detaches the table so its part directory can be edited, and every test re-attaches it afterwards. Without SYNC the detach returns while the storage instance is still tracked in DatabaseAtomic::detached_tables, so a concurrent StoragePtr holder makes the later ATTACH throw TABLE_ALREADY_EXISTS instead of waiting. ServerAsynchronousMetrics is such a holder: it iterates a snapshot of the database's tables on its own timer, which is exactly the case InterpreterCreateQuery warns about. SYSTEM WAIT LOADING PARTS and the filesystem work in between only narrow that window. SYNC is per statement, so nothing else in the module changes semantics, unlike setting database_atomic_wait_for_drop_and_detach_synchronously. No assertion, fixture or part lattice changed: the module's AST with docstrings stripped differs from the previous commit only by the added SYNC token. Co-Authored-By: Claude Fable 5 <[email protected]>
…e in inline code AGENTS.md asks for literal names from ClickHouse SQL, classes and functions, and literal log-message excerpts to be wrapped in inline code blocks. The module already did that nearly everywhere; five lines were left bare. The quoted log excerpt in create_table_with_one_part moves from double quotes to backticks rather than carrying both. The bare part names in the numbered insertion-order tables stay bare on purpose: backticks would break the column alignment those tables rely on, and flowing prose already backticks part names. Docstrings and comments only. With docstrings stripped, the module's AST is byte-identical to the previous commit, so the mutation matrix and the DETACH SYNC liveness proof carry over unchanged.
Internal second-model review (6 rounds, 0 open blockers)Before opening this PR I ran an independent review lane over it: a cold code review by a
💡 Noted, not blocking
Session id: cron:clickhouse-review-slot-10:20260727-010500 |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-4:20260726-210100 |
|
cc @alexey-milovidov — first PR of the conversion series from the plan you approved: the five |
|
Workflow [PR], commit [80c2e96] Summary: ✅ AI ReviewSummaryThis PR converts the five Findings
Final VerdictNeeds changes before merge. |
…policy The converted integration test still inherited whichever storage policy the server config exposes as the `merge_tree` default, and derived the part directory from `system.tables.data_paths[1]`. Both are hidden storage-layout assumptions, the same ones the stateless tests carried. Measured on a scratch module configured with an object-storage default policy over minio: without the pin three of the four tests fail with `Code: 246 ... Cannot parse input: expected '\n' before: 'version: 1 ... (CORRUPTED_DATA)`, which is the signature the stateless tests produce in the Stress and Upgrade checks. With the pin all four pass against that same config. `arrayElement(data_paths, 1)` names a volume of the storage policy, not the directory the part is in. Measured on a two-volume policy after `ALTER TABLE ... MOVE PART ... TO DISK`: `data_paths[1]` is the first volume's directory while the part lives under the second, so the fabricated siblings would be created next to no part at all. `system.parts.path` is `DataPartStorageOnDiskBase::getFullPath` for the one part being cloned, so its parent is the directory the fabrication has to target. The derivation asserts that the last path component really is the part name, so a future layout change fails the test instead of fabricating parts in a parent directory. Suggested by clickhouse-gh[bot] in review. CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=112000&sha=latest&name_0=PR Co-Authored-By: Claude Opus 5 <[email protected]>
CI finish ledger — 6548b0bEvery failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
Neither failure is caused by this PR's diff, which only converts the
Session id: cron:our-pr-ci-monitor:20260727-143000 |
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.
A transient AWS SSM failure while configuring log export aborted a whole Stateless sanitizer job before a single test ran, so the lane reported `failure` having tested nothing and a real regression in it was invisible for that run. `configure_log_export` sits in the mandatory command list of the `Install ClickHouse` result. It calls `create_log_export_config`, whose `Secret` fetch runs `Shell.get_output(..., strict=True)`, which raises on any nonzero AWS CLI exit; `Result.from_commands_run` maps the exception to a failing result, so the step fails and every later stage is skipped. Three shapes were observed in CI: exit 254 `An error occurred (502) when calling the GetParameters operation ... Bad Gateway`, exit 255 `Connect timeout on endpoint URL: "https://ssm.us-east-1.amazonaws.com/"`, and exit 253 `An error occurred (NoCredentials): Unable to locate credentials.` Log export is telemetry, and an unconfigured export is already a supported state: `start_log_exports` guards on `log_export_host`, the start step already reports a lapse as a workflow warning, and the llvm-coverage stateless configs skip configuring it outright while running their full suites. Only the configure step was fatal; that asymmetry is the gap ClickHouse#98153 already claimed to have closed. Each of the three fatal call sites now catches the failure, records a workflow warning and continues, leaving `log_export_host` unset so the existing supported path takes over. The tolerance returns a truthy value because `from_commands_run` treats a `False` return as a failed command, and `ClickHouseService` separately raises when a config hook returns exactly `False`. `ci/praktika/secret.py` is deliberately untouched, so the other secret consumers - release, docker, jepsen, cidb, copilot - stay fatal, as do a missing or empty SSM parameter. The fourth call site, `clickhouse_proc.py`'s `logs_export_config` `__main__` branch, was already tolerant and is unchanged. A retry was rejected: `Result` asserts `retries == 1` for python callables, and a retry would not bound the blast radius once exhausted. The new `ci/tests/test_log_export_non_fatal.py` drives the real production code against a fake `aws` on PATH. It pins that the job survives all three shapes, that the warning carries the cause, that a non-telemetry consumer still fails loudly, and that a real failure elsewhere in the same step still fails it. The call sites are AST-extracted from the job scripts and executed rather than pattern-matched, so deleting a handler, deleting the append, or retargeting it to a list no result runs cannot leave the suite green. Sightings: ClickHouse#112025 (comment) and ClickHouse#112000 (comment)
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
...
Description
Related: #111053
Related: #111922
First PR of the conversion series requested in
#111922 (comment): functional tests must
not fabricate or manually intervene with data parts outside the ClickHouse API surface. I enumerated
the 25 violating stateless tests and proposed converting them one integration module per mechanism
in #111922 (comment), which was approved
in #111922 (comment). This PR converts
the first group, the five
part_loading_tree_rollbacktests.A stateless test that writes a plaintext file into a part directory silently assumes the part lives
on a local
defaultdisk. On an object-storage disk every file inside a part directory must be inDiskObjectStorageMetadataformat, so a raw plaintexttxn_version.txtcannot deserialize and partloading fails with
CORRUPTED_DATA; the cleanup path derived its target from thedefaultdisk andso leaked the poisoned part, breaking every later server start. That assumption cannot be expressed
in a stateless test, because the harness owns and randomizes the disk configuration. An integration
test owns its own server and disk configuration, so the assumption becomes explicit and enforced by
construction rather than by a skip tag.
New
tests/integration/test_part_loading_tree_rollback/, one instance, four tests, +339 lines,replacing 767 lines of shell and their 8 reference lines:
PartLoadingTree::addbehavior under testtest_reparent04063_part_loading_tree_rollback_reparenttest_contains04241_part_loading_tree_rollback_containsOutdatedtest_evict_reinsert_contains04417_part_loading_tree_rollback_evict_reinsert_containstest_tmp_metadata04500_part_loading_tree_rollback_tmp_metadatatxn_version.txt.tmpmeans the creating transaction never committedCoverage is moved, not reduced: each scenario keeps its fabricated part lattice and its transaction
metadata payload byte for byte, and the assertions are strengthened from per-part active counts to
whole-active-set equality for three scenarios, plus an explicit active/inactive presence map for
test_evict_reinsert_contains, which is the one case where a regression could drop an orphaninstead of covering it and stay invisible to an active-only check. All four intended code paths are still exercised, which I verified by
mutation: breaking each scenario's fabrication produces exactly the failure that scenario exists to
catch, and the failures differ per scenario.
test_containsis the interesting one - thecontainment arm never consults the transaction status, so its mutation lets
ATTACHsucceed andonly the active-set assertion catches the regression.
04624_part_loading_tree_rollback_startup_recoveryis deleted without a replacement. Its subjectwas the stateless-only
DETACH TABLE ... PERMANENTLYcleanup helper: recovering a leakedpermanently-detached table whose name still blocks
CREATE. That machinery only existed to survivea stress-test server restart landing mid-script, and an integration test owns its server, so the
subject ceases to exist. Its reference output was three catalog counts plus
OK; nothing in itreached
PartLoadingTree::add.This removes the Stress-suite failures, which run the master tree's test files. It does not affect
the
Upgrade checkcolumn:tests/docker_scripts/upgrade_runner.shclones the previous release tagand runs
clickhouse-test --queries=previous_release_repository/tests/queries, so the old scriptsstay active there until the next release rollover, or until #111772 makes the existing
no-object-storageskip tags fire.Two open PRs touch the same five stateless files, so ordering matters. #111922 pins them to the
local default storage policy as a stopgap and is already approved, so it should merge first; this PR
then removes them outright, so once it lands I will merge
masterin and resolve the fivemodify/deleteconflicts in favour of the deletion. Until then GitHub reports this PR asconflicting. #111968 deletes the same ten
files with no replacement; if it merges first the deletions here become no-ops and only the new
integration module remains, which I verified resolves cleanly either way. Whichever lands first, the
part of this PR that matters is the module that keeps the four
PartLoadingTree::addscenarios undertest.
The remaining violators from the enumeration are grouped into follow-up PRs by mechanism, in the
order given in the approved plan: the
txn_versiongroup next, then the rest.Test run:
pytest test_part_loading_tree_rollback/test.py-> 4 passed;--count 10-> 40 passed.Version info
26.8.1.517(included in26.8and later)