Skip to content

Tests for twelve MergeTree transaction defects, listed as expected to fail - #124485

Open
filimonov wants to merge 40 commits into
ClickHouse:masterfrom
filimonov:txn-draft-failing-tests
Open

filimonov wants to merge 40 commits into
ClickHouse:masterfrom
filimonov:txn-draft-failing-tests

Conversation

@filimonov

@filimonov filimonov commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

Changelog category (leave one):

  • Not for changelog (changelog entry is not required)

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

Tests and failpoints only. Nothing a user can observe changes.


Twelve reproductions of open MergeTree transaction defects, in one integration module
(tests/integration/test_transaction_defects). Nine state behaviour the server does not have and carry
@pytest.mark.xfail(strict=True, raises=AssertionError): fixing a defect turns its test into a
failure of the suite, which is the signal to drop the decorator and keep the test as a regression test.

Two have made that transition already. #122375 landed while this branch was open and repaired the
reload half of #124486, so test_failed_drop_partition_survives_reload and
test_failed_truncate_survives_reload are plain regression tests: they now require the rolled-back
empty covering parts to leave the disk inside the failing statement, which is what keeps the rows.
The twelfth is skipped, because the path #122375 added aborts the server when the rollback itself
fails — see below.

No fixes here. The defects are reproducible, and a fix now has a test waiting for it. The first commit
adds five failpoints and changes nothing else; the rest is tests. Every result below was observed on a
Release build of this branch merged with 4f53afc1bab.

Test What it shows Issue Failpoint
test_snapshot_above_latest_is_refused SET TRANSACTION SNAPSHOT accepts a snapshot far above the latest, instead of INVALID_TRANSACTION #124488 no
test_mutation_at_raised_snapshot_finishes ALTER … UPDATE never finishes after SET TRANSACTION SNAPSHOT raised the snapshot past a later commit. A lowered target hangs the same way #124488 no
test_mutation_covers_part_of_unloaded_commit A snapshot set to a commit the log has not loaded is accepted, and the mutation that follows leaves that commit's part unmutated #124488 transaction_log_pause_before_loading_entries, transaction_force_unknown_state_after_commit
test_lowered_snapshot_keeps_the_part_it_sees The cleanup thread removes a part a lowered snapshot still sees #124488 no
test_failed_drop_partition_leaves_no_removal_stamp A failed DROP PARTITION leaves a part stamped for removal: plain SELECTs read it, transactions do not #124486 non_transactional_removal_store_fail_after_first_part
test_failed_drop_partition_survives_reload Regression test, passes: a failed DROP PARTITION keeps the partition across a reload, and leaves no empty covering part on disk #124486, fixed by #122375 same
test_failed_truncate_survives_reload Regression test, passes: the same for a failed TRUNCATE #124486, fixed by #122375 same
test_failed_replace_partition_leaves_destination_intact A failed REPLACE PARTITION leaves the new part beside the ones it did not replace #124486 same
test_failed_drop_partition_survives_reload_when_rollback_mark_fails When the rollback's own mark fails too, a failed DROP PARTITION still empties the table on reload. Skipped: it also aborts the server, see below #124486 same, plus version_metadata_store_creation_csn_fail
test_drop_partition_racing_a_removal_is_refused A DROP PARTITION racing a transaction that removes one of its parts is accepted; after the rollback the part is active beside the empty part covering it #124489 non_transactional_drop_pause_before_publish
test_acknowledged_insert_survives_kill_during_first_version_metadata_store An acknowledged INSERT is lost when the server is killed between the sync and the rename of the part's first version metadata store #124487 version_metadata_store_pause_before_rename
test_drop_partition_of_uncommitted_creation_is_refused Removing a part whose creating transaction is still running raises LOGICAL_ERROR instead of SERIALIZATION_ERROR #124489 no

The rollback's own failure aborts the server

test_failed_drop_partition_survives_reload_when_rollback_mark_fails is skipped, not deleted. With
the rolled-back CSN store failing as well, rollback throws, and the handler #122375 added evicts the
PreActive parts through removePartsFromWorkingSetImmediatelyAndSetTemporaryState and hands them to
tryRemovePartImmediately, whose Temporary branch skips modifyPartState(..., Deleting):

<Error> while rolling back the empty parts: Code: 294 ... Injected failure of the creation CSN store
removePartsFromWorkingSetImmediatelyAndSetTemporaryState: removing all_1_1_1 (state Temporary)
Trying to immediately remove part all_1_1_1 (state Temporary)
<Fatal> Logical error: 'Cannot remove part all_1_1_1, because it has state: Temporary'

A debug or sanitizer build aborts there and the node is gone for the rest of the module, so the test
cannot run until that is fixed. What it checks still holds: the part the handler could not remove
keeps its final name on disk, and the reload loses the rows.

Why one integration module and not stateless tests

These reproductions cannot share a server, and three of them cannot run on the stateless one at all:

  • A LOGICAL_ERROR aborts the server in a debug or sanitizer build. That is the defect
    test_drop_partition_of_uncommitted_creation_is_refused reports, and it is not expressible as an
    expected failure: the stateless runner reports the server log's Logical error and the failed
    liveness check as failures of their own, whatever the test's own verdict is.
  • The failpoints are global and the removal-store one fires once, for whichever batch of two or
    more parts reaches NonTransactionalRemovalLocks::store first. Both callers pass
    LockKind::REMOVAL, so a merge of any table — a system log included — is indistinguishable there.
    The five tests that use it stop merges server-wide for their duration, which a stateless test may
    not do. The sequencing matters and is easy to get wrong: SYSTEM STOP MERGES without a table
    iterates the tables of every database and takes an action lock per table
    (InterpreterSystemQuery::startStopAction), so it must run after the test's tables exist, and it
    leaves a merge that is already running alone, so system.merges must be drained before the
    failpoint is armed.
  • One state is only reachable by killing the server, and a test may not write into the server's
    data directory to stage it.

Risks / notes

  • cluster.shutdown can exempt a run from its LOGICAL_ERROR and <Fatal> checks, but only the
    whole run, and one reproduction needs both: its logical error aborts a sanitizer build. The
    exemptions are therefore replaced per test — a test must declare the message it may log, and
    every other test must add no logical error and no fatal line of its own.
  • Residual risks, stated rather than papered over: a transient failed restart deliberately stops the
    rest of the module, fail-closed; a restart cannot cancel a client thread that outlived its test;
    and the restart deadline is approximate, because the Docker calls inside
    tests/integration/helpers/cluster.py carry their own 300 s — bounding those means rewriting that
    helper, which does not belong here.

What each reproduction reads has to be dated

A reproduction is only as good as the state it reads, and four of these read state that could
predate the window they measure. Each is now dated against the window:

  • The empty covering parts of a failed removal are not protected by old_parts_lifetime. The
    rollback hands them to removePartsFromWorkingSet with clear_without_timeout, which sets
    remove_time = 0, and grabOldParts then finds the removal time reached whatever the lifetime
    says, so cleanup can delete them at any moment and nothing on disk distinguishes that from the
    statement having removed them. Every test here holds SYSTEM STOP CLEANUP (cleanup runs on its own
    thread under ActionLocks::Cleanup, which SYSTEM STOP MERGES does not cover) and waits out a
    round already past its cancellation test. The two regression tests then require the directories to
    be gone, which is Do not keep a rolled back empty part until the parts in its range are removed #122375's removal and not a cleanup round; the skipped one requires them to be
    there, which is what the reload loses the rows on.
  • A mutation's postpone reason outlives what justified it. selectPartsToMutate clears
    current_parts_postpone_reasons at the start of each pass, so a reason read right after releasing
    what the mutation waited for describes the pass before that. The verdict first makes the scheduler
    write No free threads in pool through mt_select_parts_to_mutate_no_free_threads, which dates
    the map.
  • last_removal_attempt_time is stamped before any test. TRUNCATE cleans up synchronously, so
    a stamp can be from a round that ran while the truncating transaction still protected the part, and
    a round that found the part removable can still skip it under NON_UNIQUE_OWNERSHIP — the
    reference the test's own read of system.parts holds. The lowered-snapshot test gives cleanup one
    round at a time and reads removal_state with cleanup stopped and the round drained.
  • A session times out in 60 s, inside these waits, and the next request opens a new one
    silently, so the test would read the table outside the transaction it believes it is in. Every
    session request carries session_timeout = 3600 and, after the first, session_check.

Testing

test_transaction_defects: 2 passed, 1 skipped, 9 xfailed in 91.58s, exit code 0, on a Release
build of this branch merged with 4f53afc1bab. An earlier revision ran 12 xfailed in 186.45s on an
ASan+UBSan build of 538719e18bb. The time is almost all waiting for the cleanup and selection rounds
above.

Every test fails on its own assertion, and pytest enforces that. An all-xfail module is green
when its tests fail for any reason at all: _pytest/skipping.py absorbs any exception in any phase
into xfail unless raises is set. raises=AssertionError narrows the exception type, which is
the easy half. The reason is the hard half: setup checks, the state a failpoint was supposed to
create and positive controls are assertions too, and 20 of the 38 assertions here were not about a
defect. Those raise Precondition instead, which is deliberately not an AssertionError, so a
reproduction that never reached its defect cannot pass for one that did. A leaked session, a merge
taking the once-only failpoint first, and an error in the module fixture each produced twelve clean
xfailed before that held.

Two tests could report a different defect than the one they name. The unloaded-commit test
assumed the transaction log's updating thread parks after the commit reaches Keeper; it wakes on its
own, so it can park before, and the test then hung on #124488 instead. The CSN entry is also written
before the fault is injected, so a Keeper entry alone does not say the commit is in unknown state:
the test waits for TransactionManager to log that it postponed finalization.

Every request carries an explicit timeout. Instance.query defaults to DEFAULT_QUERY_TIMEOUT
(600 s), which outlasts every budget here, and a polling loop whose own requests are unbounded has
no bound either, so poll hands each predicate the time it has left. restart_clickhouse enforces
no overall deadline — start_clickhouse honours wait_start=False only on the branch where no
process is left, and stop_clickhouse logs a failed kill rather than reporting it, so a surviving
old server would have been accepted as the restarted one. The module kills and verifies that itself.

The two hang reproductions do not wait out a timeout. Part selection records
PostponeReasons::VERSION_NOT_VISIBLE when a part is not visible at the mutation's start CSN, and
system.mutations.parts_postpone_reasons carries it out. That reason is the defect itself, where
elapsed time equally described a slow server, and waiting for it ends the wait as soon as it
appears: 1.7 s and 2.0 s, against 21 s and 43 s on the clock.

On a fresh server transactionLatestSnapshot() is 32 and every CSN up to 32 is reserved, so
SET TRANSACTION SNAPSHOT refuses it, and an empty BEGIN TRANSACTION; COMMIT; allocates no CSN.
Hence the warm-up insert in the module fixture.


Workflow [PR]
Sync PR [sync-upstream/pr/124485]

Related: #122375
Related: #123134
Related: #113961
Related: #124486
Related: #124487
Related: #124488
Related: #124489

filimonov and others added 16 commits October 7, 2026 20:02
Fails on purpose: the reference states the correct behaviour.

Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
Fails on purpose: the reference states the correct behaviour.

Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
Fails on purpose: the reference states the correct behaviour. Needs the failpoints of the probe commit.

Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
Fails on purpose: the reference states the correct behaviour.

Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
Fails on purpose: the reference states the correct behaviour.

Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
Fails on purpose: the reference states the correct behaviour.

Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
Fails on purpose: the reference states the correct behaviour. Needs the failpoints of the probe commit.

Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
Fails on purpose: the reference states the correct behaviour. Needs the failpoints of the probe commit.

Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
Fails on purpose: the reference states the correct behaviour. Needs the failpoints of the probe commit.

Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
Fails on purpose: the reference states the correct behaviour. Needs the failpoints of the probe commit.

Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
Fails on purpose: the reference states the correct behaviour. Needs the failpoints of the probe commit.

Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
Fails on purpose: the reference states the correct behaviour. Needs the failpoints of the probe commit.

Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
Each test states the correct behaviour and fails today. A listed test reports SKIPPED instead of FAIL, and NOT_FAILED once the defect is fixed, which flags the entry for removal.

Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
A line starting with whitespace is a comment and text after a test name is
ignored, so the reason can live beside the entries instead of only in review.

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

clickhouse-gh Bot commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [9556eba]

Summary: ❌

job_name test_name status info comment
Stateless tests (amd_debug, distributed plan, s3 storage, parallel) FAIL
05239_generate_random_json_merge_tree FAIL cidb

AI Review

Summary

PR #124485 adds five failpoints and an isolated integration module for existing MergeTree transaction defects: nine strict expected failures, two regression tests, and one skipped reproduction. Reviewed revision 9556ebaa51ca42491adc8f6109f04dff2aecd0a1. No unresolved findings remain in the current diff; the three outstanding bot threads are addressed and resolved.

Missing context / blind spots
  • ⚠️ Integration results for this revision are not yet available in the Praktika report. The PR reports an earlier Release run with two passes, nine expected failures, and one skip. The current targeted integration jobs will establish whether that result still holds; integration tests were not run locally during this review.
Final Verdict

✅ Approve — no new inline findings or remaining code changes requested by this review. Current integration CI results remain pending.

@clickhouse-gh clickhouse-gh Bot added the pr-not-for-changelog This PR should not be mentioned in the changelog label Oct 8, 2026
filimonov and others added 4 commits October 8, 2026 10:32
Three rules: a test that arms a fail point must be tagged no-fasttest; a
stateless test must not modify the server data on disk, so the torn first
store case is dropped and belongs in an integration test; and a test name
must not contain "fail".

Co-Authored-By: Claude Opus 5 <[email protected]>
Lets a test stop the server between the sync of txn_version.txt.tmp and
its rename to txn_version.txt.

Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
Rows inserted outside a transaction are lost if the server stops after
txn_version.txt.tmp is synced and before it is renamed.

Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
Two ways this module could report nothing instead of a failed reproduction:

- `requests` with `timeout=None` waits forever and `clickhouse-client` waits
  `DEFAULT_QUERY_TIMEOUT` (600 s). A request still running in a
  `ThreadPoolExecutor` worker keeps pytest alive at exit whatever
  `pool.shutdown(wait=False)` says, because `concurrent.futures` joins its
  non-daemon workers through an atexit hook. Every request now carries
  `QUERY_TIMEOUT`, and each future waits a little longer than that so the
  request's own error reaches the test instead of a `TimeoutError`.
- `xfail(strict=True)` is satisfied by any failure. The hook in
  `_pytest/skipping.py` absorbs any exception in any phase, so a leaked
  session, a transport error or a broken module fixture all report as expected
  failures -- a module that executed no test body reported `12 xfailed` in 18 s.
  `raises=AssertionError` narrows it to the assertion each test is about;
  preconditions and infrastructure raise something else on purpose.

Measured on the four shapes: a broken module fixture is an ERROR instead of
twelve xfails, a wrong exception type is a FAILURE, the test's own assertion is
the expected failure, and a passing test still fails on `strict`.

Signed-off-by: Mikhail Filimonov <[email protected]>
@filimonov

filimonov commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor Author

Fixed in 2c007f4.

Both timeout blockers were real, and wider than reported: 84 of the 95 requests here ran on Instance.query's 600 s default, so the module's own polling budgets were decorative. The dismissed major was right too — everything that is not a defect now raises Precondition instead of asserting, so only the defect can report as the expected failure.

"Slow" no longer holds. The 88 s this comment first reported is now 27 s. Two tests accounted for 21 s and 43 s of it, only because they sat out a timeout to observe a hang. They now wait for system.mutations.parts_postpone_reasons to say Not visible by transaction version — the defect itself rather than a stopwatch: 1.7 s and 2.0 s.

filimonov and others added 4 commits October 10, 2026 23:32
`raises=AssertionError` narrows the exception type, not the reason. Setup checks, the state a
failpoint was supposed to create, and positive controls were `assert` too, so a reproduction that
never reached its defect reported a clean expected failure. 20 of the 38 assertions were not about
a defect. They now raise `Precondition`, which is not an `AssertionError`.

`Instance.query` defaults to `DEFAULT_QUERY_TIMEOUT` (600 s), so 84 of the 95 requests here had no
bound that any budget in this module could hold, and a polling loop whose own requests are
unbounded has no bound either. Every request goes through `q`/`q_error` with an explicit timeout,
and `poll` hands each predicate the time left, floored at `MIN_REQUEST_TIMEOUT`.

`restart_clickhouse` enforces no overall deadline: `wait_start` runs ten 30 s readiness attempts
before it looks at its budget, and `stop_clickhouse` waits on `llvm-symbolizer` with no deadline at
all. `restart_server` starts the process with `wait_start=False` and polls readiness itself.

`session_id` built the name from the epoch current when it was called, so a worker outliving its
test would send its next request into the following test's session. `in_session` resolves the name
at submit time, `workers` waits for what it submitted, and teardown kills a statement still running
before rolling back -- a statement holds its session exclusively, so the rollback would answer
`SESSION_IS_LOCKED` and leave a transaction open, pinning part cleanup for every later test.

The unloaded-commit test assumed the updating thread parks after the commit reaches Keeper. It wakes
on its own, so it can park before: `latest + 1` is then not the held commit's CSN and the test
reproduces the raised-snapshot defect instead. It now requires, over `system.zookeeper`, that the
entry is in the log and the loaded snapshot has not moved.

12 xfailed in 117 s, each on its own assertion in its own call phase.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Signed-off-by: Mikhail Filimonov <[email protected]>
A Keeper entry does not say a commit is in unknown state: `TransactionManager::commitTransaction`
injects the fault after `current_zookeeper->multi`, so the CSN node exists either way. A normally
finalized but unloaded commit passed, and the mutation then hung on the raised-snapshot defect
(ClickHouse#124488) instead. The test now waits for `TransactionManager` to log that it postponed
finalization, counting lines from a baseline because one log serves the whole module.

A failed `SELECT 1` is not evidence that the server aborted. The uncommitted-creation test now
requires the process to be gone and a new `creation_csn is not set` line in the log or
`stderr.log`.

`settled` hands back whether the statement was ever running. A request that never reached the
server used to read as a hang; it is now a `Precondition`. What remains is that elapsed time
cannot separate "stuck" from "slower than 30 s", which is stated where the number is defined.

`start_clickhouse` honours `wait_start=False` only on the branch where no process is left, and
`stop_clickhouse` logs a failed kill instead of reporting it. So a stop that did not take put the
ten-attempt readiness batch back in the path, and a surviving old server would have been accepted
as the restarted one -- with the durability test then reading rows nothing had killed.
`restart_server` kills the process itself and proves it is gone before launching.

Teardown replaces a server it cannot clean instead of only reporting it, because pytest runs the
tests after a teardown error anyway.

12 xfailed in 117 s, each on its own assertion. The unknown-state probe is verified in the run's
log: one line, carrying `Fault injected: forced unknown state after commit`.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Signed-off-by: Mikhail Filimonov <[email protected]>
Part selection records `PostponeReasons::VERSION_NOT_VISIBLE` when a part is not visible at the
mutation's start CSN, and `system.mutations.parts_postpone_reasons` carries it out as
`Not visible by transaction version`. That is the mutation defect itself, where elapsed time
equally described a slow server. A comment here claimed no such state exists; it was wrong.

Waiting for that reason instead of the budget also ends the wait as soon as it appears. The module
drops from 88 s to 27 s: the two hang reproductions were 21 s and 43 s and are now 1.7 s and 2.0 s.

Also:

- A repaired `SET TRANSACTION SNAPSHOT` that waits for the log no longer falls through into the
  raised-snapshot defect, where the fix would have kept reporting this test as xfailed.
- The abort path waits for the creation-CSN line in the log rather than for the process. The
  exception is logged before `abort`, and fatal reporting may run for minutes
  (`SignalHandlers.cpp`), so waiting on the process first called a real abort an unrelated failure.
- `server_process_count` replaces `get_process_pid`, which answers `None` both for no match and
  for a probe that did not run -- the second reading as a dead server.
- A killed statement must fail because it was killed; other errors from it propagate.
- Cleanup that cannot restore the server marks the module, and the next test refuses to run rather
  than reproduce anything against it. A request that outlived its test counts as contamination: a
  restart cannot cancel the client thread, whose next call would recreate its session.
- The log pause is released before the pool is drained, so the join cannot wait on a commit the
  test is itself holding.

12 xfailed in 27.21s, each on its own assertion.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Signed-off-by: Mikhail Filimonov <[email protected]>
A statement that finished between the observation that it was stuck and the kill was not stuck, so
the caller's conclusion about it does not hold. `require_cancelled` accepted that silently and the
test went on to report its defect.

12 xfailed in 27.12s.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Signed-off-by: Mikhail Filimonov <[email protected]>
filimonov and others added 7 commits October 11, 2026 11:36
The three `DETACH`/`ATTACH` reproductions passed on the CI asan+ubsan runner and so failed as
`XPASS(strict)`, while this same tree reproduces the defect on Release and on an asan+ubsan build
locally, both on a standalone server and under the integration harness. The run's server logs are
no longer reachable, so the tests now print the state the reproduction turns on: `system.parts`,
`system.detached_parts`, the part directories and every `txn_version.txt` under them, before and
after the reload, plus the injected error in one line. pytest prints a captured log for
`XPASS(strict)`, so the next CI run says which link broke.

What that state is: the rollback of a failed non-transactional removal marks
`creation_csn = RolledBackCSN` in memory only, because `VersionMetadataOnDisk::storeInfoUnlocked`
defers the store for a part that `VersionInfo::wasInvolvedInTransaction` says was never in a
transaction. The empty covering parts keep the final directory names `transaction.renameParts`
gave them and carry no `txn_version.txt`, so the loader reads them as prehistoric and they cover
the live parts.

`test_failed_drop_partition_survives_reload_when_rollback_mark_fails` also gets the positive
control it lacked: both injections raise `CANNOT_WRITE_TO_FILE` and the statement reports only the
first, so its precondition held for the single-fault path next door as well. The second injection
fires inside `~MergeTreeData::Transaction`, which logs the exception and swallows it, so that log
line is the only observable, and it lands after the client already has the error.

Related: ClickHouse#124485 (comment)

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Signed-off-by: Mikhail Filimonov <[email protected]>
Three reproductions reported `XPASS(strict)` on `amd_asan_ubsan` while reproducing on every local
build. The sanitizer build is not the reason: the same CI configuration
(`-DSANITIZE=address,undefined`, `CMAKE_BUILD_TYPE=None`) reproduces all twelve locally, on a
standalone server and in the integration harness.

The reproductions depend on the empty covering parts of the failed removal staying on disk until
the reload, and nothing kept them there. The rollback hands them to `removePartsFromWorkingSet`
with `clear_without_timeout`, which sets `remove_time = 0`, so `grabOldParts` is free to take them
whatever `old_parts_lifetime` says. `SYSTEM STOP MERGES` does not cover it either: cleanup runs on
its own thread under `ActionLocks::Cleanup`. Once the directories are gone the reload finds only
the original parts, keeps the rows, and the test reports a fix that did not happen.

So `merges_stopped` becomes `merges_and_cleanup_stopped` and adds `SYSTEM STOP CLEANUP`. That also
closes a second hole: a background part removal reaches
`NonTransactionalRemovalLocks::store` with `LockKind::REMOVAL` like the statement under test, and
can take the single-shot failpoint first.

`two_parts` now polls cleanup every second instead of every 30, so a reproduction that loses this
guard fails at once rather than depending on how long the test took, and each reload test first
requires the rolled-back parts to still be on disk. Both directions were run on an ASan+UBSan
build, with five seconds between the failed statement and the `DETACH`:

- cleanup left running: `2 failed`, both on that new precondition -- the CI result, reproduced.
- cleanup stopped: `12 xfailed`.

`test_failed_drop_partition_survives_reload_when_rollback_mark_fails` is not one of the two: when
the rollback's own mark fails, the covering parts stay `PreActive`, which `grabOldParts` does not
touch. Its `XPASS` in CI, and the server death in the same run, are still unexplained.

`require_injected_failure` now matches the injected message and not every `CANNOT_WRITE_TO_FILE`,
and `reload_state` selects `_state` -- without it `system.parts` returns no `PreActive` part
(`StoragesInfo::getParts`) -- and prints the contents of each `txn_version*` file rather than its
name.

Related: ClickHouse#124485

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Signed-off-by: Mikhail Filimonov <[email protected]>
Seven places where a run could report something other than what the test claims to measure.

A mutation verdict no longer trusts a postponement reason it may have outlived.
`selectPartsToMutate` clears `current_parts_postpone_reasons` at the start of each pass, so the
reason read right after releasing what the mutation waited for describes the pass before that: a
repaired server that is about to proceed would be killed and reported as stuck. The verdict waits
its budget out and reads the reason at the end.

The lowered-snapshot reproduction requires the cleanup thread to have looked at the part while the
snapshot was held. `grabOldParts` stamps `last_removal_attempt_time` on every part it examines,
before testing whether a transaction can still see it, so that is the chance the defect needs. A
run that never gave it one passed both assertions on a server that still removes the part.

Merges stop before the inserts that make the two parts, not after: the module-wide stop locks the
tables that exist when it runs, so a merge of the two rows could leave the removal batch holding a
single part, with no second part for the failpoint to fail after.

The double-fault control names its own table. Both the failpoint and its log line are global, so
the bare message counted a mark that failed anywhere, including a mark of another test's part.

A logical error is now expected of one test by name instead of the whole module. `cluster.shutdown`
can only exempt the entire run, which also hides a logical error from an unrelated code path. The
`<Fatal>` check stays exempt, and says why: the abort of a logical error writes a stack of which
one line carries the message, so counting cannot tell it from an unrelated crash.

`table_path` requires the table to have one data path rather than reading the first of several.

A repaired ClickHouse#124488 reports what to do about it. That test cannot turn the repair into a passing
expected failure, because everything after that point measures a different defect.

Verified on an ASan+UBSan build: `12 xfailed`.

Related: ClickHouse#124485

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Signed-off-by: Mikhail Filimonov <[email protected]>
Four reproductions accepted state that predates the window they measure.

- The mutation verdict read `parts_postpone_reasons` without knowing which
  selection pass wrote it. `selectPartsToMutate` rebuilds the map per pass, so
  the reason the paused transaction log justified outlived its release.
  `require_fresh_mutation_pass` arms `mt_select_parts_to_mutate_no_free_threads`
  and waits for `No free threads in pool`, which only a pass after that call can
  write.
- `SYSTEM STOP CLEANUP` cancels an `ActionBlocker` that
  `IMergeTreeCleanupThread::run` tests once, before `iterate`, so a round
  already past it still removed the empty covering parts.
  `wait_for_no_cleanup` waits for the table's task to stop executing in
  `system.background_schedule_pool`.
- The lowered-snapshot test accepted any non-zero `last_removal_attempt_time`.
  `StorageMergeTree::truncate` cleans up synchronously, so the stamp could be
  from a round that ran while the truncating transaction still protected the
  part. It now takes a baseline and requires a newer attempt. Its setup also
  ran with cleanup live, and the transactional `TRUNCATE` sets
  `remove_time = 0`, so nothing held the part between that commit and the
  lowered snapshot: cleanup is stopped until the snapshot is set.
- Only the whole run could be exempted from the `<Fatal>` check, which hid an
  unrelated fatal report behind an intentional restart. The exemption is now
  per test, as the `LOGICAL_ERROR` one already was.

12 xfailed on an ASan+UBSan build of `538719e18bb`.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Signed-off-by: Mikhail Filimonov <[email protected]>
A fresh `last_removal_attempt_time` only said a cleanup round examined the
part. `grabOldParts` stamps that time before any test, so a round that found
the part removable and then skipped it under `NON_UNIQUE_OWNERSHIP` -- the
reference the poll's own read of `system.parts` holds -- satisfied the
precondition, and the assertions then passed on a server that does remove a
part a lowered snapshot sees. Require `removal_state` to name the visibility
test instead, with the attempt time only to date it.

12 xfailed on an ASan+UBSan build of `538719e18bb`.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Signed-off-by: Mikhail Filimonov <[email protected]>
`last_removal_attempt_time` is written at the top of `grabOldParts` and
`removal_state` only after the test that stopped the round, and `system.parts`
reads the two columns separately. A read taken while a round is in flight could
pair this round's attempt time with the previous round's reason, so a server
that goes on to remove the part satisfied the precondition. Give cleanup one
round at a time and read both columns with cleanup stopped and the round
drained; a round that ended in `NON_UNIQUE_OWNERSHIP` now has to be beaten by
the next one.

12 xfailed on an ASan+UBSan build of `538719e18bb`.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Signed-off-by: Mikhail Filimonov <[email protected]>
`default_session_timeout` is 60 s, inside the waits these reproductions take.
An expired session is dropped with its transaction rolled back, and the next
request opens a new one silently: the test then reads the table outside the
transaction it believes it is in, and the result it asserts on is the defect's.
Every session request now carries `session_timeout = 3600`, and every request
after the first in a session carries `session_check`, so a session that is gone
fails the request instead of being replaced. A restart destroys the sessions,
so `restart_server` forgets them.

12 xfailed on an ASan+UBSan build of `538719e18bb`.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Signed-off-by: Mikhail Filimonov <[email protected]>
filimonov and others added 2 commits October 12, 2026 12:53
ClickHouse#122375 removes the rolled-back empty covering parts
inside the failing statement, so a failed `DROP PARTITION` or `TRUNCATE` no longer empties the
table after a reload. The two reproductions assert that instead of expecting it to fail: the parts
must leave the disk (`leftover_part_dirs`), and the rows must survive `DETACH`/`ATTACH`.

`test_failed_drop_partition_survives_reload_when_rollback_mark_fails` is skipped. When the
rollback itself throws, the handler added by ClickHouse#122375 hands a part in state `Temporary` to
`tryRemovePartImmediately`, which raises `Cannot remove part ..., because it has state:
Temporary`; a debug or sanitizer build aborts on it and the node is gone for the rest of the
module. The reload it checks still loses the rows, so the test stays as written.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Signed-off-by: Mikhail Filimonov <[email protected]>
filimonov and others added 2 commits October 13, 2026 19:46
`MergeTreeTransaction::afterCommit` is `noexcept` and stores the committed CSN through
`setAndStoreCreationCSN` as well, so `version_metadata_store_creation_csn_fail` could terminate the
server from an unrelated commit, and consume the one-shot injection before the rollback under test
reached it. Inject only for `Tx::RolledBackCSN`.

Three reads ran after their helper's budget was already spent and fell back to `QUERY_TIMEOUT`,
which turned a 30 s or 60 s bound into up to three minutes: the final postpone-reason read of a
`stop_early=False` verdict, and the `system.merges` and `system.background_schedule_pool`
diagnostics of the two `Precondition` paths. They take `MIN_REQUEST_TIMEOUT`.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Signed-off-by: Mikhail Filimonov <[email protected]>
@filimonov

Copy link
Copy Markdown
Contributor Author

tests look ok-ish now.

@tuanpach or @murphy-4o do you want guys to pick the challenge to make those green? :)

Some require quite straight-forward fixes and probably groneai can do those, and some need some design decisions.

yariks5s pushed a commit to ylw510/ClickHouse that referenced this pull request Oct 22, 2026
Two pauseable failpoints make the race deterministic:
`version_metadata_store_pause_before_rename` stops
`VersionMetadataOnDisk::storeInfoToDataPartStorage` after `txn_version.txt.tmp`
is written and before it replaces `txn_version.txt` (the same name and spot as
in open PR ClickHouse#124485), and `mt_mutate_task_pause_before_rename_part` stops a
plain MergeTree mutation after its disk transaction is committed and before
the new part is renamed into the table.

The test stamps a part's creation CSN with COMMIT paused at the first point,
runs a non-transactional mutation over the part while `txn_version.txt.tmp`
exists, then reloads the table and checks that the mutated part is kept.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

Dear @murphy-4o, you haven't been active on this PR for 30 days. You will be unassigned. Will you continue working on it? If so, please feel free to reassign yourself.

@clickhouse-gh clickhouse-gh Bot added comp-transactions MergeTree transactions (MVCC): BEGIN / COMMIT / ROLLBACK, the transaction log and manager, part v... and removed comp-testing Test content only (no production code). labels Nov 19, 2026

This branch has not been deployed

No deployments
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 comp-transactions MergeTree transactions (MVCC): BEGIN / COMMIT / ROLLBACK, the transaction log and manager, part v... external Author is not a member of the ClickHouse organization pr-not-for-changelog This PR should not be mentioned in the changelog

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants