Repository navigation
Conversation
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.
Internal pre-publication review (click to expand)Three rounds before publication: my own cold pass over the resulting code each round plus an Fixed before publication, all in the test harness: the new failpoint paused commits that remove Declined with recorded evidence: two asks for negative cases that no reachable state produces (a Noted and not fixed: the merge drain sits outside the test's The one real coverage limitation has no reddening arm by construction and is stated in the |
|
Workflow [PR], commit [279717e] Summary: ❌
AI ReviewSummaryThe PR repairs interrupted non-transactional part removals when loading covered transactional parts, and delays transactional merges, mutations, and Missing context / blind spots
Final VerdictStatus: ✅ Approve — no remaining code-review findings. Current CI still needs to complete. |
|
cc @CheSema @tiandiwonder, could you review this? A non-transactional |
Build profile diff (arm_release)Commit See the job log for details. |
CI finish ledger - 88ac8b8Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task whose
Session id: cron:our-pr-ci-monitor:20260903-053000 |
| current_version_info.toString(/*one_line=*/true)); | ||
|
|
||
| TransactionInfoContext transaction_context{part->storage.getStorageID(), part->name}; | ||
| part->version->setAndStoreNonTransactionalRemovalTID(transaction_context); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
| bool covering_part_is_non_transactional = false, | ||
| const String & covering_part_name = {}); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
| /// 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. |
There was a problem hiding this comment.
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.
| /// 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. |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
left a comment
There was a problem hiding this comment.
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 theloadDataPartdeclaration into the protected section (SMT loads mounted parts through it), and this PR adds it back at the old spot.MergeTreeData.cpp, theloadDataPartdefinition — private has trailingsnapshot_root_path/snapshot_part_dirand the body branches on them, while this PR puts thePartLoadingTree::NodePtrin the same position. both are needed.MergeTreeData.cpp,Transaction::commit— private passes a trailingLockKind::REMOVALtoaddNewPartAndRemoveCovered, exactly where the newpauseFailPointgoes. keep both sides.completeRemovalOfCoveredPartauto-merges cleanly but still calls the one-argumentsetAndStoreNonTransactionalRemovalTID, 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.
|
Thanks for the list. I cannot see private master, so I took the simulation as given and rebuilt its One of the four is removable from my side, and is, in The other three I do not think I can take off your plate:
Since this is a signature change and not a behaviour one, I verified it rather than assuming: debug |
…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.
CI finish ledger - 34e1a5bEvery failure below has an owner: a fixing PR (mine or external), or a full-effort fix task CI is fully finished on this head: 176 checks, 151 pass, 22 skipped, 2 failed,
Session id: cron:our-pr-ci-monitor:20260915-190256 |
…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]>
|
📊 Cloud Performance Report ✅ AI verdict: 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
|
|
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. |
…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]>
CI finish ledger - 3082b74Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
Session id: cron:our-pr-ci-monitor:20261010-180005 |
…d-part-removal-on-load
…d-part-removal-on-load
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]>
CI finish ledger - 279717eEvery failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
The other CIDB Session id: cron:our-pr-ci-monitor:20261024-083006 |
| 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(); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
Related: #71136
Changelog category (leave one):
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,TRUNCATEorMOVE PARTITION TO TABLEwas interrupted by an abrupt process stop: a covered part could be left with no removal TID, and loading it raisedData 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.
renameAndCommitEmptyPartsmakes the empty covering part durable, and only thenaddNewPartAndRemoveCoveredstores 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 isOutdatedby block range alone,preparePartForRemovalrejects 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 loadedActivewas created without one. That ancestor's classification is snapshotted by value as it loads. Anything else falls through to today's behaviour, andpreparePartForRemovalis untouched. The metadata is written by the same call a finished commit makes.Until the outdated parts are loaded, a transactional merge, mutation or
OPTIMIZEwaits: 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 carryremoval_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
preparePartForRemovalthrow.The producer set is structural, not a closed list: any
MergeTreeData::Transactioncommitted with no transaction while its covered parts were created by committed transactions. Background merges are not in it, sinceMergeTreeDataMergerMutatorrejects a non-transactional merge once transactions are enabled.Two adjacent issues found en route and deliberately left alone:
locked_parts_to_cleanupinTransaction::commitis written and never read, which is the subject of open #115442; andloadMetadatadiscards a coexistingtxn_version.txt.tmpinstead 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]