Skip to content

Complete an interrupted part removal when loading outdated parts - #117793

Open
groeneai wants to merge 14 commits into
ClickHouse:masterfrom
groeneai:complete-interrupted-part-removal-on-load
Open

groeneai wants to merge 14 commits into
ClickHouse:masterfrom
groeneai:complete-interrupted-part-removal-on-load

Conversation

@groeneai

@groeneai groeneai commented Sep 2, 2026 •

Copy link
Copy Markdown
Collaborator

Related: #71136

Changelog category (leave one):

  • Bug Fix (user-visible misbehavior in an official stable release)

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

Fixed the server failing to start after a non-transactional DROP PARTITION, DROP PART, TRUNCATE or MOVE PARTITION TO TABLE was interrupted by an abrupt process stop: a covered part could be left with no removal TID, and loading it raised Data part ... is Outdated ... but does not have removal tid, which terminates startup and recurred on every later start. Such a removal is now completed while the part is loaded.

Description

Requested by @ alexey-milovidov: #106231 (comment) (private Stress test (amd_tsan, meta in keeper), STID 2429-2239).
Public sighting: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=115916&sha=86f83f64ecd36a085371e943194ab3f64d098fdb&name_0=PR&name_1=Upgrade%20check%20%28amd_release%29

Root cause. renameAndCommitEmptyParts makes the empty covering part durable, and only then addNewPartAndRemoveCovered stores the covered parts' removal TID: two durable writes with no atomicity between them. A stop in between leaves the covered part with a committed creation CSN and no removal TID. On restart it is Outdated by block range alone, preparePartForRemoval rejects that pair as impossible, and the exception reaches a handler that terminates the server. Being on disk, it recurs every start.

The change. In loadDataPart, before the part is published, complete the removal for exactly that shape: the removal was never recorded, the creation was committed by a real transaction, and the covering ancestor that loaded Active was created without one. That ancestor's classification is snapshotted by value as it loads. Anything else falls through to today's behaviour, and preparePartForRemoval is untouched. The metadata is written by the same call a finished commit makes.

Until the outdated parts are loaded, a transactional merge, mutation or OPTIMIZE waits: its commit also removes the covered outdated parts, and replacing the covering part first left nothing to show the removal after another restart.

Not the struck-out option in #71136: the assertion is not relaxed, and the producer-side store added there is present on every path (details below).

Validation. Three integration tests beside #81734's regression test, using a new pauseable failpoint plus SIGKILL: one restart, and two restarts with a background merge or a transactional mutation of the covering parts in between. Without the fix the server does not start and logs the reported message; with it every restart succeeds and the recovered parts carry removal_tid = (1,1,...), removal_csn = 1.

Disclosed coverage limitation and adjacent findings

Why the load side: storing the TID first would instead lose data (a stop between the store and the rename leaves the covered part marked removed with no cover on disk, so its rows vanish), the two writes cannot be made atomic because they target different parts' storages, and no producer code runs after an abrupt stop.

On #71136 @ tuanpach struck through "remove the assertion" and fixed the producer in #81734, adding the then-missing store. That store exists today on every path, so there is no write left to add; what remains is process death between two writes that are not atomic with respect to each other, which no producer-side change can close.

The cover conditions have no reddening mutation arm by construction: every part reaching the helper is covered, so a case where deleting the cover predicate changes an assertion would need a second victim covered by a transactional cover, whose correct behaviour on the fixed build is that the server still terminates. They are justified fail-closed instead: they can only narrow what is touched, and anything rejected lands on the unchanged preparePartForRemoval throw.

The producer set is structural, not a closed list: any MergeTreeData::Transaction committed with no transaction while its covered parts were created by committed transactions. Background merges are not in it, since MergeTreeDataMergerMutator rejects a non-transactional merge once transactions are enabled.

Two adjacent issues found en route and deliberately left alone: locked_parts_to_cleanup in Transaction::commit is written and never read, which is the subject of open #115442; and loadMetadata discards a coexisting txn_version.txt.tmp instead of using it, so an interrupted metadata rewrite is silently rolled back (latent, and excluded as the cause here).


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

A non-transactional DROP PARTITION / DROP PART / TRUNCATE / MOVE PARTITION TO
TABLE covers the parts it removes with an empty part. It makes the covering
part durable first (StorageMergeTree::renameAndCommitEmptyParts ->
MergeTreeData::Transaction::renameParts) and only afterwards stores the covered
parts' removal TID (MergeTreeData::Transaction::commit ->
MergeTreeTransaction::addNewPartAndRemoveCovered ->
setAndStoreNonTransactionalRemovalTID). Those are two separate durable writes
with no atomicity between them, and the store is deliberately placed before
NOEXCEPT_SCOPE, so an abrupt process stop in that window is enough to leave the
covering part complete on disk and the covered part unstamped.

On the next start the covered part is classified Outdated purely from block
range containment - PartLoadingTree::add descends the containment branch with no
transaction check - and, because the cover loads Active, the child is never
promoted and is collected into outdated_unloaded_data_parts.
loadOutdatedDataParts then calls preparePartForRemoval unconditionally, whose
check rejects "committed creation CSN with an empty removal TID" as impossible.
The exception reaches a handler that terminates the server, and since the state
is on disk every subsequent start repeats it: the server cannot start again.

Complete the removal in loadDataPart, before the part is published into
data_parts_indexes, and only for that exact shape: the removal was never
recorded, the creation was committed by a real transaction (its local TID is
above the reserved band, so an empty or sentinel TID cannot qualify), and the
ancestor that loaded Active and therefore covers this part was itself created
without a transaction. That ancestor's classification is snapshotted by value
when it loads, because the loading tree does not outlive active parts loading
and a background merge started by startup can replace the cover before the
outdated parts are read. Anything else - a transactional cover, unreadable or
absent evidence - fails closed and reaches the existing check exactly as today.

The covering part accounts for the covered part's rows, so its removal is a
fact even though the TID never reached disk, and a non-transactional marker is
the truthful record of it: the metadata written is byte-identical to what a
finished commit writes, because it is the same call.

The recovery must precede publication rather than sit next to
preparePartForRemoval. Background merges start before outdated parts are loaded
and explicitly collect visible Outdated descendants, so after publication such
a merge can install an in-flight transactional removal TID; isRemoved() stays
false until that CSN is known, so the completion would still fire and then
collide with the merge's removal lock, terminating startup nondeterministically.

The producer side cannot fix this. Storing the removal TID before the rename
loses data: a stop in between leaves the covered part removable with no
covering part on disk, so it loads top-level, is demoted and deleted, and its
rows vanish. There is no cross-part durable transaction - the stamp writes into
the covered part's storage and the rename into the cover's - and the storage
transaction that does exist is committed before the stamp as well, so deferring
the rename moves the window instead of closing it. Above all, no producer code
runs at all after an abrupt stop.

This is not the option struck out in ClickHouse#71136. There the producer never persisted
the mark, and ClickHouse#81734 added the missing write; that write is present today and is
issued on every path, so there is nothing left to add and the assertion is not
relaxed here.

The regression test lives beside ClickHouse#81734's own test in
tests/integration/test_transactions. It cannot be a functional test: it needs a
kill and restart, and functional tests must not fabricate or manually intervene
with data parts. A new pauseable failpoint stops the commit after the covering
part is durable and before the covered parts are stamped, so the window is
deterministic rather than timing-dependent; the test synchronizes on the pause
state via SYSTEM WAIT FAILPOINT, not on the filesystem, because the final
covering directory exists whether the commit is paused or already finished.

Related: ClickHouse#71136
`pauseFailPoint` sat before the covered-parts loop, so a commit with no
covered parts reached it. Every plain INSERT commits that way, and every
system-log flush is such an INSERT, so while the failpoint was enabled
every flush in the server parked at it. The entry is `PAUSEABLE`, not
`PAUSEABLE_ONCE`, and `waitForPause` only observes that some thread
paused, so `SYSTEM WAIT FAILPOINT ... PAUSE` did not prove that the
test's `DROP PARTITION` had reached the window: the SIGKILL could
capture an unrelated operation, and the test would then fail on its
result assertions.

Injecting inside `if (!covering_part)`, guarded on a non-empty covered
set and immediately before `addNewPartAndRemoveCovered`, is the same
window. The covering part's storage transaction is already committed
before the loop, and `commit` throws if any part still needs renaming,
so the cover is durable; `addNewPartAndRemoveCovered` on the next line
is the only writer of the removal TID, and by then `covered_parts`
already includes the transaction branch's covered outdated parts. It is
strictly narrower: no commit without covered parts can reach it.

The test's `SYSTEM STOP MERGES` now takes no table argument. A merge of
any table does have covered parts, so a table-scoped stop still left a
system-log merge able to satisfy the wait.
`SYSTEM STOP MERGES` only installs the action locks; it does not wait.
`InterpreterSystemQuery` routes it to `ActionLocksManager::add`, which calls
`IStorage::getActionLock`, while the primitive that drains is
`StorageMergeTree::stopMergesAndWait`. So a merge already past its last
cancellation check reaches `NEED_FINISH` and commits inside `finish` after
the blocker is installed. Every merge does remove covered parts, so it
satisfies `SYSTEM WAIT FAILPOINT ... PAUSE` instead of the `DROP PARTITION`
the test means to capture, and `assert not drop_future.done` cannot tell the
two apart: the two futures race two container-exec startups. The kill then
lands with the empty covering parts not yet renamed into place and the test
fails after the restart on `SELECT n FROM mt4 ORDER BY n`. This instance runs
nine system logs at `flush_interval_milliseconds = 7500`, and a system-log
table carries no version metadata, so the `ABORTED` guard in
`MergeTreeDataMergerMutator` does not cover them.

A merge holds its `MergeList` entry across that commit: the entry is created
in `prepare` and destroyed with the task, i.e. after `finish` returns, and
`system.merges` reads the merge list directly. An empty `system.merges` is
therefore the state in which no merge is between `prepare` and `finish`, and
the installed blocker keeps new ones from starting, so the `DROP` is the only
possible consumer of the pause. `assert_eq_with_retry` on that count is the
wait the SQL command does not perform.

The second `system.merges` assertion, after the `drop_future.done` check, is
not a duplicate of that wait. The action lock is taken per table when the
command runs, so a `MergeTree` table created after it is not covered. Any
future consumer of the same failpoint then fails with a sentence rather than
as a data assertion three steps later, after the restart. A `DROP PARTITION`
has no `MergeList` entry, so zero is the correct expectation when the parked
commit is ours, and the query reads only the merge list, so it cannot block
behind the parked commit's parts lock.

The armed failpoint and the merge stop are in-memory server state that only
the kill clears, and between arming and the kill there are two failing exits
and three queries that can raise. `PAUSEABLE` is enabled with no `FIU_ONETIME`
flag, so it fires for every arriving thread, and `notifyPauseAndWaitForResume`
waits with no timeout. On any of those paths every later commit in the module
that removes covered parts parks forever, bounded only by the 900-second
per-test cap in `tests/integration/pytest.ini`. Measured on one binary with
one failure induced inside the window: without the `finally` the module loses
four tests and takes a `pytest-timeout` kill, with it one fails and three
pass with no kill.

Disabling in the `finally` costs nothing on the success path. Disabling a
registered failpoint that is not enabled is a deliberate no-op, so it is inert
once the restart has cleared it; `disableFailPoint` also resumes a thread
already parked, including a `SYSTEM WAIT FAILPOINT` that never got its pause,
which `ThreadPoolExecutor.shutdown` cannot do because it does not cancel a
running future. `query_and_get_answer_with_error` returns the error instead of
raising, so a cleanup that cannot reach a killed server cannot mask the
assertion that got us there.

No source change in this commit.
@groeneai groeneai added can be tested Allows running workflows for external contributors groeneai-origin-request PR origin: a maintainer pinged or directed groeneai labels Sep 2, 2026
@groeneai

groeneai commented Sep 2, 2026

Copy link
Copy Markdown
Collaborator Author
Internal pre-publication review (click to expand)

Three rounds before publication: my own cold pass over the resulting code each round plus an
independent model (codex). Eight findings.

Fixed before publication, all in the test harness: the new failpoint paused commits that remove
nothing, so an unrelated system-log flush could satisfy the test's wait; SYSTEM STOP MERGES
does not drain a merge already past its last cancellation check, so one could consume the pause
instead of the DROP PARTITION; and a failure inside the armed window left the failpoint armed
and merges stopped for the rest of the module, which measured as four lost tests and a
pytest-timeout kill without the finally against one failure and three passes with it.

Declined with recorded evidence: two asks for negative cases that no reachable state produces (a
transactional cover always has its covered parts stamped before its own creation is committed),
and one for a Keeper-backend proof this repository cannot produce - that class exists here only as
a friend declaration, and the change adds no backend-specific behaviour.

Noted and not fixed: the merge drain sits outside the test's try/finally, and the merge-list
discriminator can fail a correct window if an unrelated merge parks at the failpoint at the same
moment. Both are bounded to this one test.

The one real coverage limitation has no reddening arm by construction and is stated in the
description above rather than only here.

@clickhouse-gh clickhouse-gh Bot closed this Sep 2, 2026
@clickhouse-gh clickhouse-gh Bot reopened this Sep 2, 2026
@clickhouse-gh

clickhouse-gh Bot commented Sep 2, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [279717e]

Summary: ❌

job_name test_name status info comment
Upgrade check (amd_release) FAIL
Changed settings are not reflected in the settings changes history (see changed_settings.txt) FAIL cidb

AI Review

Summary

The PR repairs interrupted non-transactional part removals when loading covered transactional parts, and delays transactional merges, mutations, and OPTIMIZE until outdated parts have loaded. Reviewed head 279717e178e0ae75c604538e0ab2d2785b3e7929, the diff, current callers and metadata handling, and all prior discussion. No actionable findings remain; the earlier recovery-evidence finding is addressed and its bot-authored thread is resolved.

Missing context / blind spots
  • ⚠️ The current head's CI is still running, and results for the three recovery integration tests are not yet available. No local ClickHouse build was available to rerun them; completed integration results would close this validation gap.
Final Verdict

Status: ✅ Approve — no remaining code-review findings. Current CI still needs to complete.

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Sep 2, 2026
@groeneai

groeneai commented Sep 2, 2026

Copy link
Copy Markdown
Collaborator Author

cc @CheSema @tiandiwonder, could you review this? A non-transactional DROP PARTITION makes its empty covering part durable before addNewPartAndRemoveCovered stores the covered parts removal TID, so an abrupt stop between those two writes leaves an Outdated part with a committed creation CSN and no removal TID; preparePartForRemoval then rejects that pair as impossible and the server terminates on every later start. I complete that removal in loadDataPart, only for that shape and only when the covering ancestor that loaded Active was itself created without a transaction.

@clickhouse-gh

clickhouse-gh Bot commented Sep 3, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Commit 279717e178e0ae75c604538e0ab2d2785b3e7929 was not compared: the CI logs cluster did not answer (exception 241, code 500: { "meta": [ { "name": "file", "type": "String" }, { "name…).

See the job log for details.

@groeneai

groeneai commented Sep 3, 2026

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - 88ac8b8

Every failure below has an owner: a fixing PR (mine 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
Docs examples / Documentation examples trunk-side, and not reachable from this diff: 2104 of 2226 examples are ok and the one unexpected failure is Function/timeSeriesPrometheusValueToString#0, whose documented output box is one character wider than the box the server prints #117789 (external, open)
Integration tests (amd_asan_ubsan, db disk, old analyzer, 2/6) / test_azure_403_handling/test.py::test_transient_forbidden_on_write_succeeds flaky, and not reachable from this diff: the injected one-shot Azure 403 is consumed by a concurrent read, so the CH write retry loop is never exercised and contains_in_log('Write at attempt') is false. 8 other PRs hit it in 30 days, 0 on master #116729 (mine, open)
Sync - CH Inc sync (private, not actionable by me)

Bugfix validation (integration tests, amd64/aarch64) is green on both arches; the FAIL rows CIDB
records for the nine test_transactions/test.py cases are that check's inverted semantics, i.e. the
new regression tests correctly fail against the pre-fix binary.

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

@PedroTadim

Copy link
Copy Markdown
Member

cc @alexey-milovidov

@tiandiwonder tiandiwonder self-assigned this Sep 4, 2026
@clickhouse-gh clickhouse-gh Bot added the comp-mergetree MergeTree* family: parts, merges, primary index, column statistics, background data transformation. label Sep 4, 2026
current_version_info.toString(/*one_line=*/true));

TransactionInfoContext transaction_context{part->storage.getStorageID(), part->name};
part->version->setAndStoreNonTransactionalRemovalTID(transaction_context);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

this won't build in the private repo — there the virtual takes an extra LockKind (preparePartForRemoval just above passes LockKind::REMOVAL), and since VersionMetadata.h isn't touched here the private signature survives the merge, so CH Inc sync will fail to compile until a LockKind::REMOVAL commit lands on the sync branch.

two more mechanical conflicts come with it: private addNewPartAndRemoveCovered takes a trailing LockKind::REMOVAL right below where the new pauseFailPoint goes, and private loadDataPart already ends in two defaulted String params.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I cannot compile the private fork, so I am taking the extra LockKind on trust rather than
asserting anything about it. What is checkable from the public tree: the virtual is declared with
arity 1 at src/Interpreters/MergeTreeTransaction/VersionMetadata.h:107, grep -rn LockKind src/
returns nothing, and this diff adds exactly one new call site (the existing public ones are
MergeTreeTransaction.cpp:116, :141 and preparePartForRemoval at MergeTreeData.cpp:2523).
CH Inc sync has been pending / "awaiting" on this PR since 2026-09-02T23:23:01Z, so it has not
produced a signal in either direction.

Of the two follow-on conflicts: the loadDataPart one is gone, since the two trailing defaults are
now a single PartLoadingTree::NodePtr (787bf17). The pauseFailPoint adjacency to
addNewPartAndRemoveCovered stays, but that one is a textual conflict rather than a build break.

I left the setAndStoreNonTransactionalRemovalTID call as it is. The one lever I have without
private access is to route both sites in this file through a single wrapper, so the fork patches the
arity once instead of at a new site; that trades a compile error for a merge conflict inside a
function your fork already diverges in, so it is your call. Say the word and I will do it.

Comment thread src/Storages/MergeTree/MergeTreeData.h Outdated
Comment on lines +2284 to +2285
bool covering_part_is_non_transactional = false,
const String & covering_part_name = {});

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

optional: pass the PartLoadingTree::NodePtr (or a small struct) instead of two trailing defaulted params.

both values already live on the node and the only caller that supplies them has the node in hand; as trailing defaults they also collide with the two defaulted String params the private fork already appends to this same signature, which turns the sync resolution into an ordering decision.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Done in 787bf17: one const PartLoadingTree::NodePtr & part_loading_node = nullptr replaces both
parameters on loadDataPart and loadDataPartWithRetries. Only loadOutdatedDataParts
(MergeTreeData.cpp:3632) supplies it, and my_part there is the node itself; the other two
callers keep the default.

That removes the collision with the fork's defaulted String parameters, and if the merged order
does come out wrong, a node pointer cannot bind to a String silently.

Comment thread src/Storages/MergeTree/MergeTreeData.h Outdated
Comment on lines +2048 to +2049
/// Set from the ancestor that loaded `Active` and therefore covers this part. Copied by value
/// because the tree does not outlive active parts loading and the cover may be replaced by a merge.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

the "does not outlive active parts loading" half is backwards — these nodes are exactly what carries the value past that phase into outdated_unloaded_data_parts. the second clause is the load-bearing reason.

Suggested change
/// Set from the ancestor that loaded `Active` and therefore covers this part. Copied by value
/// because the tree does not outlive active parts loading and the cover may be replaced by a merge.
/// Set from the ancestor that loaded `Active` and therefore covers this part. Stored by
/// value rather than as a part pointer, because a merge may replace the cover during startup.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Applied verbatim in 787bf17. You are right about which clause carries the reason.

# restart has cleared it.
node.query_and_get_answer_with_error(f"SYSTEM DISABLE FAILPOINT {FAILPOINT}")
node.query_and_get_answer_with_error("SYSTEM START MERGES")
pool.shutdown(wait=False, cancel_futures=True)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

re the thread above: the bot's mechanism holds even though its premise doesn't. disableFailPoint does release the parked commit, but that makes the worker running, not finished, so shutdown(wait=False) can return with the resumed DROP PARTITION still in flight.

impact is small — mt4 is used by no other test in this module and the failpoint is already disarmed — but wait=True after the disable would close it, since the disable guarantees the workers can make progress.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Agreed, and the hang I claimed against wait=True does not exist: the disable itself is a blocking
query_and_get_answer_with_error, so a server that cannot process it already stalls the finally
before the join is reached. wait=True in 4a3c24a, along with deleting the comment above the executor
that argued the opposite.

Measured with praktika integration / test_transactions, same binary:

variant result
as pushed 10 passed in 101.94s
same, assert False injected immediately before the SIGKILL 1 failed, 9 passed in 97.23s, no timeout kill

For comparison, the wait=False run of that same injection was 1 failed / 7 passed, and with
SYSTEM DISABLE FAILPOINT deleted it was 4 failed plus one Timeout (>90.0s) kill.

Both values already live on the PartLoadingTree node, and the one caller that
supplies them has the node in hand. As two trailing defaults they also sit where
the private fork appends its own defaulted String parameters to this same
signature, so the two sets have to be ordered against each other; a node pointer
cannot bind to a String by accident.

Also correct the field comment: these nodes are what carry the value past active
parts loading into outdated_unloaded_data_parts, so "does not outlive active
parts loading" had it backwards. The load-bearing reason for storing the name by
value is that a merge may replace the cover during startup.
SYSTEM DISABLE FAILPOINT releases the parked commit, which makes the worker
runnable rather than finished, so shutdown(wait=False) could return while the
resumed DROP PARTITION was still in flight. start_cluster is module-scoped, so
the next test would inherit that work on mt4.

The join is bounded precisely because the disable runs first: it clears the
pause for both the commit and the SYSTEM WAIT FAILPOINT, so neither worker can
still be blocked on the failpoint when shutdown is called.

@tiandiwonder tiandiwonder left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

heads up before this can land: the sync branch doesn't merge into private master, so the LockKind point I left on completeRemovalOfCoveredPart is one of four spots, not the whole story.

simulating the merge (git merge-tree --merge-base=bb3c0a852e1 <private master> 4a3c24a5bed) gives three conflicts plus one that auto-merges into a compile error:

  • MergeTreeData.h — private moved the loadDataPart declaration into the protected section (SMT loads mounted parts through it), and this PR adds it back at the old spot.
  • MergeTreeData.cpp, the loadDataPart definition — private has trailing snapshot_root_path / snapshot_part_dir and the body branches on them, while this PR puts the PartLoadingTree::NodePtr in the same position. both are needed.
  • MergeTreeData.cpp, Transaction::commit — private passes a trailing LockKind::REMOVAL to addNewPartAndRemoveCovered, exactly where the new pauseFailPoint goes. keep both sides.
  • completeRemovalOfCoveredPart auto-merges cleanly but still calls the one-argument setAndStoreNonTransactionalRemovalTID, which is the compile error.

one knock-on outside the conflicts: StorageSharedMergeTree.cpp passes the two snapshot arguments positionally, so it needs /*part_loading_node=*/nullptr inserted once the parameter list changes.

CH Inc sync is still awaiting on this head, so none of this shows on the board yet.

`loadDataPart` / `loadDataPartWithRetries` took the `PartLoadingTree::NodePtr` as
a trailing defaulted parameter, so the two callers that have no node to give said
nothing at all, and the parameter landed on the tail of the parameter list, which
is where the private fork appends its own trailing parameters. That made the sync
resolution an ordering decision between the two additions.

Both functions now take the node right after `part_disk_ptr`, and every caller
states what it passes: `loadOutdatedDataParts` passes its node, while the `Active`
and `PreActive` load paths pass `/*part_loading_node=*/nullptr`, since neither
consumes the covering information the node carries.

The argument every call site passes is the one it passed before, so behavior is
unchanged.
@groeneai

groeneai commented Sep 7, 2026

Copy link
Copy Markdown
Collaborator Author

Thanks for the list. I cannot see private master, so I took the simulation as given and rebuilt its
shape locally instead of second-guessing it: a stand-in off bb3c0a852e1 carrying the two trailing
String parameters plus a body branch on them, the trailing LockKind::REMOVAL at the
addNewPartAndRemoveCovered call and inside preparePartForRemoval, and the loadDataPart
declaration moved into the protected section. 3-way merged against 4a3c24a5bed it reproduces your
three conflicts and the clean auto-merge on completeRemovalOfCoveredPart, so the stand-in is the
right shape even though it is not your tree.

One of the four is removable from my side, and is, in 280318c05c7: the loadDataPart definition.
That conflict came from the node being trailing, so both sides rewrote the same
DB::SharedMutex & part_loading_mutex) line. The node is now the parameter after part_disk_ptr and
no longer defaulted, so snapshot_root_path / snapshot_part_dir keep the tail and there is no order
to decide; that hunk merges clean in the simulation, 3 conflicts down to 2. One position was not
enough, incidentally: with the node immediately before the mutex the two regions are still adjacent
and still conflict. The knock-on you predicted for StorageSharedMergeTree.cpp remains, but it is now
a fixed spot, /*part_loading_node=*/nullptr right after disk, rather than one that depends on how
the tail was ordered. The two public callers with no node pass it that way already.

The other three I do not think I can take off your plate:

  • MergeTreeData.h: your side deletes the declaration where mine edits it, so it conflicts whatever
    the parameter list looks like. I can move it into the protected section as well if you give me the
    anchor, but guessing the spot only relocates the conflict.
  • Transaction::commit: the pause has to sit between the covering part becoming durable and
    addNewPartAndRemoveCovered stamping the covered parts, which is the line your fork extends.
    Anywhere else it stops pinning the window the test needs, so this is "keep both sides".
  • completeRemovalOfCoveredPart: still the one-argument call. The wrapper offer stands (both sites in
    this file through one helper, so the arity is patched once), but it trades the compile error for a
    conflict inside preparePartForRemoval, which your fork already modifies. Your call.

Since this is a signature change and not a behaviour one, I verified it rather than assuming: debug
build 1fa7b603e836996, test_transactions 10 passed in 148.79s, and with the node replaced by
nullptr at loadOutdatedDataParts the recovery test fails, so the argument is load-bearing where it
is consumed. check_cpp.sh clean.

…d-part-removal-on-load

ClickHouse#105116 replaced the per-part removal in Transaction::commit with a batch that
locks every covered part first and stores the removal TIDs afterwards, so the
commit failpoint moved out of the per-part loop to the point before that batch
runs. It still pauses after the covering parts are durable and before any
covered part is stamped, which is the window loadOutdatedDataParts has to
recover from.

setAndStoreNonTransactionalRemovalTID kept its single-argument form on master,
so completeRemovalOfCoveredPart is unchanged by the merge.
@groeneai

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - 34e1a5b

Every failure below has an owner: a fixing PR (mine 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.

CI is fully finished on this head: 176 checks, 151 pass, 22 skipped, 2 failed,
aggregator complete, and nothing left running except CH Inc sync. The last real check completed at
17:32:19Z, well past the 20 minute buffer the CI database needs.

Check / test Reason Owner / fixing PR
Build profile diff infra, nothing tested: has_pr_data raised RuntimeError: CI logs cluster query failed on the binary_sizes read and aborted the job before any comparison ran #120121 (mine, open), which turns a transient cluster read failure into a skipped comparison instead of a failed one
CH Inc sync still pending: the private mirror sync does not complete on a fork CH Inc sync (private, not actionable by me)

PR aggregate the rows above rather than adding a failure of their own.

Bugfix validation (integration tests, amd64) and (aarch64) both concluded SUCCESS, so neither is a ledger line. For the record, the CI database carries 9 FAIL rows per arch under them for test_transactions/test.py: bugfix validation publishes its own job verdict independently of the per-test rows it stores, which is why a green job can carry them.

Report: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=117793&sha=34e1a5b2354be83c0a29e386ca449b1fbd0d9402&name_0=PR

Session id: cron:our-pr-ci-monitor:20260915-190256

alexey-milovidov and others added 2 commits September 26, 2026 03:19
…d-part-removal-on-load

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
`TransactionID` gained `session_node_version`, so `system.parts.creation_tid`
and `removal_tid` are now `Tuple(UInt64, UInt64, UUID, Int64)`, and comparing
them with three-element literals failed with `Illegal types of arguments`
before any assertion ran. `Tx::EmptyTID` and `Tx::NonTransactionalTID` both
carry `session_node_version = 0`, which is the form the other tests in this
file already use.

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

clickhouse-gh Bot commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

📊 Cloud Performance Report

✅ AI verdict: no_change — no significant changes across 31 queries analysed

no significant changes detected. K_source=6 K_base=30 flagged=0/65

clickbench

🟢 No significant changes

tpch_adapted_1_official

🟢 No significant changes

Debug info
  • StressHouse run: 8d4b945f-2cd6-4341-8cf1-78743c2590b3
  • MIRAI run: 08b381f0-2bf8-4204-9ea8-bd302bf445a9
  • PR check IDs:
    • clickbench_939697_1791758200
    • clickbench_939704_1791758200
    • clickbench_939714_1791758199
    • tpch_adapted_1_official_939721_1791758199
    • tpch_adapted_1_official_939754_1791758199
    • tpch_adapted_1_official_939768_1791758200

@clickhouse-gh

clickhouse-gh Bot commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

Dear @tiandiwonder, 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.

groeneai and others added 2 commits October 10, 2026 11:56
…d-part-removal-on-load

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Keep each comment to the invariant a reader needs at that spot. The reasons
for where the completion runs and how the cover is recorded stay here:

- the completion runs before the part is inserted into data_parts_indexes,
  because a background merge started by startup can stamp removal TIDs on any
  part it sees there;
- the covering part's origin is stored by value on the loading-tree node, not
  as a part pointer, because a merge may replace the cover during startup.

Comment-only change.

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

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - 3082b74

Every failure below has an owner: a fixing PR (mine 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 (arm_asan_ubsan, azure, sequential) job timeout, not a test failure: the job was stopped at its 9000 s limit after 1164 of 1180 tests, with no failed test. This job ended with the same error status on 109 PRs and 5 master runs in the last 24 hours #123849 (mine, open), which splits this job into 2 batches
Stateless tests (arm_binary, AsyncInsert, s3 storage, parallel) / 05239_written_rows_quota_interval_rollover flaky, not from this PR: under asynchronous inserts the rollover checkpoint line 1 1 is missing; 6 of 6 reruns pass. About 30 other PRs and master show it since 2026-10-09 #124935 (mine, merged 17:57Z). The tested merge commit predates it, so I will merge master here to pick it up
Upgrade check (amd_release) / Logical error: Part A intersects previous part B (STID 2002-2037) not from this PR: in the stress phase the previous release 26.9.14.10 ran ALTER TABLE mt DETACH PARTITION ID 'all' (01164_detach_attach_partition_race), a fault-injected MEMORY_LIMIT_EXCEEDED in the metadata commit rolled it back and left the empty part all_18_18_2 on disk, so the upgraded server refused to load all_18_32_2. 8 other PRs show this STID in this job since 2026-10-04, 0 master #122375 (external, merged), which removes such rolled back empty parts; 26.9.14.10 does not have it yet
Mergeable Check, PR praktika rollups of the rows above #123849 (mine, open), #124935 (mine, merged), #122375 (external, merged)
Sync - CH Inc sync (private, not actionable by me)

Session id: cron:our-pr-ci-monitor:20261010-180005

An interrupted removal is completed when the covered outdated parts are
loaded, in the background after startup, and what shows it was a removal
is that their covering part is Active and was created without a
transaction. A transactional merge or mutation of that covering part in
the meantime replaced it with a part created by a transaction, so after
one more restart the covered parts still had no removal TID, nothing
showed the removal, and loading them terminated the server on every
start again.

A transactional commit also removes the outdated parts covered by its new
part, and it can find only the loaded ones. So until the outdated parts
of a table are loaded, background merges and mutations that would run in
a transaction are not scheduled and a transactional OPTIMIZE waits, like
partition commands and TRUNCATE already do. Background operations are
triggered when the loading finishes, so the postponed ones do not wait
for the exponential backoff.

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

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - 279717e

Every failure below has an owner: a fixing PR (mine 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
Upgrade check (amd_release) / Changed settings are not reflected in the settings changes history (see changed_settings.txt) not from this PR (it does not touch settings): v26.10.2.103-stable, published 2026-10-24 04:17Z, ships use_query_condition_cache_for_time_conditions = false after #127632, while master's settings history still says its default became true in 26.10. Every PR whose Upgrade check started after 04:17Z reports the same 1 / 0 row #127687 (mine, open)
Mergeable Check, PR praktika rollups of the row above #127687 (the owner of the row above)
Sync - CH Inc sync (private, not actionable by me)

The other CIDB FAIL rows on this head are the Bugfix validation (integration tests, *) runs of the new test_transactions tests, which fail on master as intended (both jobs are green).

Session id: cron:our-pr-ci-monitor:20261024-083006

@clickhouse-gh clickhouse-gh Bot added comp-transactions MergeTree transactions (MVCC): BEGIN / COMMIT / ROLLBACK, the transaction log and manager, part v... and removed comp-mergetree MergeTree* family: parts, merges, primary index, column statistics, background data transformation. labels Nov 19, 2026
outdated_data_parts_loading_finished = true;
outdated_data_parts_cv.notify_all();
/// Transactional merges and mutations wait for the outdated parts to be loaded.
triggerBackgroundOperations();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

optional: gate this on transactions_enabled (same for the early-return trigger above at ~4080). Only transactional merges/mutations are deferred, so a non-transactional table takes a scheduling wake it never needed; gating it also pairs the trigger with the deferral in scheduleDataProcessingJob.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I'd keep both triggers ungated. The mutation deferral keys on the entry's txn, not on transactions_enabled, and submitting a transactional mutation does not set transactions_enabled (only creating or removing parts in a transaction does). test_recover_removal_tid_before_covering_parts_are_mutated is that case: no transactional part survives the restart, so transactions_enabled stays false while the ALTER ... UPDATE waits for its mutation (a mutation in a transaction is always waited for). That is also why this test fails without the mutate_entry->txn guard, which it could not if transactions_enabled were true.

Gated, nothing would wake that mutation when loading finishes, so the ALTER would wait for the assignee's postpone backoff instead: up to about a minute after a 10-minute load. The cost on a non-transactional table is one scheduling pass when the loading finishes, and only for a table that had outdated parts, since the loading task is created only then.

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... groeneai-origin-request PR origin: a maintainer pinged or directed groeneai pr-bugfix Pull request with bugfix, not backported by default

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants