Repository navigation
Stop the parts cleanup in three transaction tests that read a rolled back part - #118377
Conversation
…back part `01172_transaction_counters`, `04057_transaction_version_metadata_lifecycle` and `04060_transaction_snapshot_visibility` assert that a part created by a rolled back transaction is still listed in `system.parts` with `creation_csn = RolledBackCSN`. Nothing keeps it there. `MergeTreeTransaction::rollback` marks the part `RolledBackCSN` and then removes it from the working set with `clear_without_timeout = true`, which stores `remove_time = 0`. In `grabOldParts` the subtraction is therefore from 0, not from the rollback time, so `time_now - remove_time >= old_parts_lifetime` holds for any lifetime below the current Unix time and the `old_parts_lifetime=3600` these tests set does not hold the part; `VersionMetadata::canBeRemoved` returns true outright for `RolledBackCSN`. The remover is `MergeTreeCleanupThread`, a dedicated `BackgroundSchedulePool` task, and two timers gate it. Its first iteration cannot remove a part, because `start` restarts the parts stopwatch just before scheduling it and the `merge_tree_clear_old_parts_interval_seconds` gate (1 second) is therefore still shut. The next iteration lands `cleanup_delay_period` plus up to `cleanup_delay_period_random_add` later, 30-40 s with defaults, so a run slow enough to still be inside the assertions by then loses the row. `SYSTEM STOP MERGES` does not stop it: merges are gated by `merges_blocker`, the cleanup thread by `IMergeTreeCleanupThread::cleanup_blocker`, which only `ActionLocks::Cleanup` takes. 01172's "stop background cleanup" comment above `system stop merges` was therefore describing something that statement does not do, and is repaired here. `SYSTEM STOP CLEANUP` on its own would leave a narrower version of the same race. `run` tests the blocker once, before `iterate`, and taking the lock only increments an atomic counter, so an iteration that started while the table was being created and is then delayed past the one-second gate still runs its parts pass and still takes the part. `merge_tree_clear_old_parts_interval_seconds` is therefore pinned in each `CREATE TABLE` as well: the stopwatch is restarted inside `start`, so no iteration can reach the pinned interval during the test, in flight or not. `04813_merge_over_rolled_back_gap_part.sh` pins the same setting for the same reason. Pinning `remove_rolled_back_parts_immediately = 0` instead does not work, because it only disables the third disjunct in `grabOldParts` while `reached_removal_time` stays true through `remove_time = 0`. Measured with the cleanup forced: that arm still fails 5/5 on all three tests, while `SYSTEM STOP CLEANUP` passes 5/5. No assertion and no `.reference` byte changes. `01173_transaction_control_queries` has the inverse dependency, needing the rolled back parts of its earlier rollbacks to be gone, which is why this is fixed per test rather than with a server-level `remove_rolled_back_parts_immediately = 0` in `tests/config`. Co-Authored-By: Claude Opus 5 <[email protected]>
Internal second-model reviewIndependent review rounds before publishing. Nothing blocking is left open.
On the published commit an independent read of the tree and the second-model gate both came back |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-4:20260906-034000 |
|
Workflow [PR], commit [73526cd] Summary: ✅ AI ReviewSummaryThis PR stabilizes three transaction stateless tests by explicitly stopping cleanup, pinning Final VerdictStatus: ✅ Approve |
|
cc @tuanpach, could you review this? It stops the parts cleanup in 01172, 04057 and 04060, which assert a rolled back part is still listed in |
|
@groeneai Check the CI failure. |
|
The red on the PR page is a cancelled duplicate workflow run, not a test failure. I re-measured before answering: Two PR workflow runs exist for All 117 CIDB records no test-level failure: SELECT check_name, test_name, test_status FROM checks
WHERE pull_request_number = 118377 AND test_status IN ('FAIL', 'ERROR')0 rows, against 14976 ingested rows for the same commit (14589 of them For a test-only change the flaky check is the signal that matters here, and it has passed on the two arms that have finished: all three changed tests ran 50 times each on CI is not finished, so I am not calling it green yet. I will post the finish ledger here when it completes, and follow up if a real failure appears. |
CI finish ledger - 5e8c8a9CI is fully finished at this commit and no check failed, so no ledger row is owed. The reading in my previous comment holds. Run CIDB agrees at test level: 0 rows with For a test-only change the flaky check is the signal that matters, and it is now green on all five arms ( Session id: cron:our-pr-ci-monitor:20260906-080115 |
`SYSTEM STOP CLEANUP` installs a blocker only when the storage hands back a
non-empty lock. `IStorage::getActionLock` returns `{}` by default
(`IStorage.h:651`) and `ActionLocksManager::add` keeps the lock only
`if (!action_lock.expired())` (`ActionLocksManager.cpp:44`), so on an engine that
does not implement `ActionLocks::Cleanup` the statement succeeds and blocks
nothing. `StorageMergeTree` is the only public engine that implements it
(`StorageMergeTree.cpp:3652`).
`02491_part_log_has_table_uuid.sh` and `02950_part_log_bytes_uncompressed.sh`
already record that `StorageSharedMergeTree` does not implement
`ActionLocks::Cleanup` and removes parts from `PartsKillerThread` on the
server-wide `parts_kill_delay_period` (`ServerSettings.cpp:1379`, "Only available
in ClickHouse Cloud"), which a stateless test cannot pin. Neither guard this PR
adds therefore holds the rolled back part once `--cloud` or
`--replace-non-replicated-with-shared` rewrites `ENGINE = MergeTree` to
`SharedMergeTree` (`clickhouse-test:283` and `:4109-4119`), and the assertions
keep the race they were meant to close.
The tag is enforced at `clickhouse-test:3053` (`--cloud`) and `:3176`
(`--replace-replicated-with-shared`); a lane that sets only
`--replace-non-replicated-with-shared` substitutes the engine without honoring
the tag. Public CI sets none of the three flags, so the public `MergeTree` lanes
run all three tests unchanged: every executed line is byte-identical to the
previous commit, only comments and the `Tags` line move.
CI finish ledger - 58f7c10Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
Control for the rest of the run, so the single red check is stated against a non-empty baseline: 70416 CIDB Session id: cron:our-pr-ci-monitor:20260907-150153 |
|
Fixing PR for the three
Not merged yet, so the row can reappear on a re-run until it lands. Still not caused by this PR's diff. |
…the comment `05136_database_filesystem_missing_path_on_load` sent the second `clickhouse local` invocation's stderr to `/dev/null`, which discarded the only text that identifies the defect: without it a base-build failure is a bare missing-lines stdout diff, on the sole regression test for a "server cannot start" fix. The redirect suppressed nothing that a green run emits. A bare `clickhouse local` sets `logger.level` to `fatal` unless one of `logger.console`, `logger.level`, `log-level` or `logger.log` is given, so the tolerated path's `LOG_WARNING` never reaches stderr; `shell_config.sh` builds `--send_logs_level` into `CLICKHOUSE_CLIENT` only, never into `CLICKHOUSE_LOCAL`; and the first invocation in the same test already ran unredirected. Measured after removing it: stderr is empty on the fix build and 50 randomized runs stay green, while the base build now reports `Code: 36 ... Path does not exist: ... while loading database ... from file metadata/fsdb.sql. (BAD_ARGUMENTS)`. Also reword the second sentence of the `is_internal_metadata_replay` comment. It justified the exclusion by who supplies the path, which is false for the short `ATTACH DATABASE db` form: that reads `metadata/<db>.sql`, replays the stored definition and supplies no path of its own, yet still throws, because `args.internal` is false. Name the discriminator that actually decides it. `RESTORE` is internal too and is excluded by the mode term instead, so the wording claims only what the guard does. https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=118377&sha=58f7c10d1c3a06e4661e9b38aa3d45dc6b268a96&name_0=PR&name_1=Stress%20test%20%28arm_tsan%29 ClickHouse#118377 Co-Authored-By: Claude Opus 5 <[email protected]>
…ssing path
The previous commit's guard was `args.internal && args.mode >= ATTACH`, on the
assumption that `internal` means the server generated the statement. It does
not. `InterpreterParallelWithQuery::executeSubquery` runs every `PARALLEL WITH`
child through `executeQuery(..., QueryFlags{ .internal = true })`, and
`InterpreterExecuteAsQuery::execute` does the same for `EXECUTE AS`, so a
statement a user writes arrives at `DatabaseFactory` with `internal` set.
`PARALLEL WITH` is gated by no setting and DDL children are its canonical use.
Measured on a server: `ATTACH DATABASE d ENGINE = Filesystem('<missing>')` is
rejected with `Code: 36`, while the same statement followed by
`PARALLEL WITH DROP TABLE IF EXISTS <absent>` was accepted, wrote
`metadata/d.sql`, and survived a restart. Both plain forms already threw, so
only the wrapped form reached the tolerant branch.
Add a third conjunct, `args.replays_stored_definition`, computed by the
interpreter one line above the factory call as `create.attach &&
!need_write_metadata`. That expression already means "the definition being
attached is the one stored in `metadata/`", so this reuses the interpreter's own
answer instead of inventing a second notion of replay. A definition supplied
with the query is never a stored one, wrapper or not. The change moves in one
direction only: strictly fewer statements reach the tolerant branch, and a
genuine startup replay still evaluates all three terms true, which
`05136_database_filesystem_missing_path_on_load` continues to assert.
`02921_database_filesystem_path_check` gains the wrapped `ATTACH` arm. Its
sibling is `DROP TABLE IF EXISTS`, whose pipeline is empty, so the assertion
does not depend on the order the children run in or on what `max_threads`
randomizes to. Dropping the new conjunct while keeping the plumbing reddens
that arm with `The query succeeded but the server error '36' was expected`.
The sibling engines that share the two-term predicate are left alone: the same
laundering reaches them, but that belongs with the wrapper rather than with each
engine.
https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=118377&sha=58f7c10d1c3a06e4661e9b38aa3d45dc6b268a96&name_0=PR&name_1=Stress%20test%20%28arm_tsan%29
ClickHouse#118377
Co-Authored-By: Claude Opus 5 <[email protected]>
The previous commit's third conjunct was `create.attach && !need_write_metadata`,
which it described as "the definition being attached is the one stored in
`metadata/`". It does not test that. `need_write_metadata` is
`!create.attach || !existsFile(metadata/<name>.sql)`, so the conjunct only tests
whether the NAME already has a stored definition; whether the definition being
executed came from that file is never checked. The file is read solely in the
short-syntax branch (`!create.storage && create.attach`), which a long-syntax
`ATTACH DATABASE ... ENGINE = ...` skips. `DETACH DATABASE` leaves the metadata
file in place (`DatabaseCatalog` removes it only when dropping, and
`DatabaseFilesystem::shouldBeEmptyOnDetach()` is false), so two ordinary
statements arrange the precondition.
Measured on a server, twice, with `buildId()` asserted against the binary:
CREATE DATABASE d;
DETACH DATABASE d;
ATTACH DATABASE d ENGINE = Filesystem('<missing>')
PARALLEL WITH DROP TABLE IF EXISTS <absent>;
was accepted, and `system.databases` then reported `d` with engine `Filesystem`
over a path that does not exist, while `metadata/d.sql` still held the original
`ENGINE = Atomic` definition. The same shape via short syntax, after removing
the directory of a real `Filesystem` database, was likewise accepted. Both plain
forms threw `Code: 36`, so `internal`, laundered by the wrapper, was again the
term being defeated.
Feed the decision from the loader instead of deriving it from the statement.
`InterpreterCreateQuery` gains `setIsMetadataReplay`, called only from
`executeCreateQuery` in `loadMetadata.cpp`, beside the `setInternal(true)` that
startup metadata replay already performs. Nothing else can reach it: `QueryFlags`
has no route to an interpreter member, so no SQL sets it. A dedicated flag rather
than the adjacent `setLoadDatabaseWithoutTables` because that one means "defer
table loading", not "this is a replay".
With the loader answering directly, `args.internal` leaves the predicate: the
same call site sets both, so it decided nothing. `args.mode >= ATTACH` is kept as
the idiom the sibling engines use; it is not independently provable by mutation
here, because a replayed `Filesystem` definition is always an `ATTACH DATABASE`
statement and therefore always that mode.
`isLoadingFromExistingMetadata` remains unusable for this: a database is replayed
under plain `ATTACH`, unlike tables, which use `FORCE_ATTACH`, so the helper never
matches a database load.
`02921_database_filesystem_path_check` gains the name-aliasing arm in pure SQL,
and re-attaches before dropping, since a database left detached keeps a metadata
file that every later start replays. `05136_database_filesystem_missing_path_on_load`
gains the sharper arm: the definition a start has just replayed is refused to a
user who replays it by hand, plainly and wrapped, and the start after each
rejection attaches the database again. Restoring the previous predicate reddens
both arms, the wrapped `05136` line flipping while its plain line stays green,
which is exactly the statement class that was reachable before.
The sibling engines that share the two-term predicate are still left alone: the
laundering reaches them too, and belongs with the wrapper rather than with each
engine.
https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=118377&sha=58f7c10d1c3a06e4661e9b38aa3d45dc6b268a96&name_0=PR&name_1=Stress%20test%20%28arm_tsan%29
ClickHouse#118377
Co-Authored-By: Claude Opus 5 <[email protected]>
|
@groeneai Check the CI failure. |
…led-back-part-transaction-tests
|
Yes, both of them, and both are already merged. The only red at
Fixing PRs, both merged after that run:
I merged master into the branch ( |
|
@groeneai, any CI jobs or issues linked to this fix? |
|
CI jobs yes, issues none. The provenance here is CI evidence only. The public witness. The exact shape (the rolled back part's row removed and not re-added) has one public row in the last 180 days, and none in the last 90:
Re-measured on The other red rows on these tests are different mechanisms. 67 of 04057's and 67 of 04060's 180-day rows are on Issues. Nothing open. The closed ones on these test names are those other shapes, not this one: #103152, #102932 (04057) and #103151 (04060) are the auto-generated flaky test issues for the AsyncInsert shape; #68165 (01172, 2024) is the If you want an issue tracking this one, say so and I will open it. |
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed a flaky failure of three transaction tests that read a rolled back part from
system.parts.Description
01172_transaction_counters,04057_transaction_version_metadata_lifecycleand04060_transaction_snapshot_visibilityassert that a part created by a rolled back transaction is still listed insystem.partswithcreation_csn = 18446744073709551615. The background parts cleanup can delete it first, and the run loses that line:MergeTreeTransaction::rollbackremoves the part withclear_without_timeout = true, soremove_time = 0andgrabOldPartsmay take it at anyold_parts_lifetime;canBeRemovedis true outright forRolledBackCSN.SYSTEM STOP MERGESdoes not stop that remover:MergeTreeCleanupThreadhas its own blocker, taken only bySYSTEM STOP CLEANUP, so 01172's-- stop background cleanupcomment was wrong and is repaired here. One public sighting, with the query below; 04057 and 04060 carry the identical assertion.Fix, per test:
SYSTEM STOP CLEANUP <table>besideSYSTEM STOP MERGES, plusmerge_tree_clear_old_parts_interval_seconds = 100000in theCREATE TABLE(precedents04338_replace_partition_no_resurrect_after_restart.sql,04813_merge_over_rolled_back_gap_part.sh). The statement alone is not a barrier:runchecks the blocker once, beforeiterate, so the iteration queued atCREATE TABLEcan still run its parts pass; the pinned interval shuts that pass. No assertion or.referencebyte changes. A suite-wideremove_rolled_back_parts_immediately = 0is ruled out by01173_transaction_control_queries.sql:83, and the arm below shows it does not help anyway.All three also take
no-shared-merge-tree:IStorage::getActionLockreturns an empty lock by default andActionLocksManager::addkeeps it onlyif (!action_lock.expired()), so on an engine withoutActionLocks::Cleanupthe statement blocks nothing, and02491_part_log_has_table_uuid.shrecords thatStorageSharedMergeTreeremoves parts fromPartsKillerThreadon the server-wideparts_kill_delay_periodinstead, which a.sqltest cannot pin. The tag is honored under--cloudand--replace-replicated-with-shared; a lane setting only--replace-non-replicated-with-sharedrewrites the engine without honoring it, which I left to the harness rather than change a predicate 111 other tests share. Public CI sets none of the three flags.The public sighting, the measured arms, and why not
remove_rolled_back_parts_immediately = 0The sentinel row has to be removed and not replaced, otherwise the needle also matches the
unrelated non-transactional-insert shape:
04057's and 04060's older
AsyncInsert-lane failures are that different, already-blacklistedmechanism. The forcing below is
merge_tree_clear_old_parts_interval_seconds = 0,cleanup_delay_period = 1and a 2 s delay before the assertions; 5 runs per test per arm, plus 50randomized runs per test on the final tree (150/150).
SYSTEM STOP CLEANUPonlyremove_rolled_back_parts_immediately = 0The statement-only arm is green because this forcing cannot land inside the startup window; that
window is closed by reading
runanditerate, not by an arm.remove_rolled_back_parts_immediately = 0does not help at all: it only disables thecreation_csn == Tx::RolledBackCSNdisjunct ingrabOldPartswhilereached_removal_timestays true throughremove_time = 0. The delay-only armshows the failure comes from the cleanup.
Workflow [PR]
Sync PR [sync-upstream/pr/118377]
Version info
26.10.1.244-master(included in26.10and later)