Repository navigation
Cherry pick #111196 to 26.6: Fix data loss when replicated INSERT commit recovery is interrupted - #119610
Merged
robot-clickhouse-ci-2 merged 11 commits intoSep 12, 2026
Conversation
…ncelled while the Keeper commit status is unknown When the Keeper multi request committing an INSERT ends with a hardware error (e.g. connection loss), the request may or may not have been applied, so `ReplicatedMergeTreeSinkImpl::commitPart` verifies the status with an `exists` check under `ZooKeeperRetriesControl`. The preservation logic previously lived in the `actionAfterLastFailedRetry` callback, which only runs when the retries are exhausted by Keeper errors: a `max_execution_time` timeout, `KILL QUERY` or any non-retryable exception thrown during the recovery bypassed it, the exception left `commitPart` and `MergeTreeData::Transaction` rolled back the local part. Keeper, however, could already contain the part metadata, the replication log entry and the deduplication block id, so the part became lost forever (replaced by an empty part by the part check), and retrying the same INSERT was silently deduplicated - permanent data loss. The regression exists since 23.12: the verify-first recovery introduced by #56917 interacts with the time limit checks between retries introduced by Now the recovery result is explicit: unless the recovery loop completes the Keeper checks and produces a result, the commit status is treated as unknown on any exit path, and the local part is preserved - committed locally and enqueued for a part check, which keeps it if it is present in Keeper or drops it otherwise. `actionAfterLastFailedRetry` is deliberately not used: its contract does not cover cancellation or non-retryable failures. On these paths the INSERT now fails with `UNKNOWN_STATUS_OF_INSERT` instead of `TIMEOUT_EXCEEDED` / `QUERY_WAS_CANCELLED`, consistently with the exhausted-retries path, so that clients do not interpret the failure as "the data was not inserted". Co-Authored-By: Claude Fable 5 <[email protected]>
…unknown `writeExistingPart` (used by `ATTACH PART` and `RESTORE`) rolls back the on-disk rename of the part on any exception from `commitPart` unless `new_part_was_committed_to_zookeeper_after_rename_on_disk` is set. The preserve path commits the part into the working set and throws `UNKNOWN_STATUS_OF_INSERT`, but did not set the flag, so `try_rollback_part_rename` renamed the already-committed part back to `detached/` or `tmp_restore_*`, leaving an active part whose directory is outside the table data path. Set the flag before committing, in the same way as the successful recovery path does. Co-Authored-By: Claude Fable 5 <[email protected]>
When the recovery of an ambiguous Keeper commit is aborted by a query timeout or `KILL QUERY`, the pipeline executor cancels the query before the exception-carrying chunk of the sink reaches the end of the pipeline, so the sink's `UNKNOWN_STATUS_OF_INSERT` is dropped and the client receives the original `TIMEOUT_EXCEEDED` / `QUERY_WAS_CANCELLED` error. Assert these codes instead of `UNKNOWN_STATUS_OF_INSERT`. The invariants that actually guard the fix - the part stays readable, the retried `INSERT` is deduplicated, `lost_part_count` stays 0 - are asserted separately. CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=111196&sha=5b6739251333d0d68bc3be36ff66860f9ee19ac9&name_0=PR PR: #111196 Co-Authored-By: Claude Fable 5 <[email protected]>
The test used an unstable , for which ClickHouse disables deduplication. As a result, retrying the insert correctly created another part and made the row-count assertion fail. Add to the original and retried inserts so they generate the same deduplication block ID and exercise the intended ambiguous Keeper commit path.
Set `new_part_was_committed_to_zookeeper_after_rename_on_disk` only after the local `MergeTreeData::Transaction::commit` succeeds in the ambiguous Keeper recovery path. This keeps the existing `writeExistingPart` rename rollback when the local commit itself fails while still protecting a successfully preserved part from the terminal unknown-status exception.
Apply the same ordering as in the ambiguous-commit preserve path to the two success paths of `commitPart`: set `new_part_was_committed_to_zookeeper_after_rename_on_disk` only after `transaction.commit` succeeds. If the local commit throws before the part becomes visible in the working set, `writeExistingPart` can still rename the part back to `detached/` or `tmp_restore_*`, where the data is preserved instead of being deleted by the cleanup thread. Co-Authored-By: Claude Fable 5 <[email protected]>
…lback Refresh the branch on top of current `master` to re-run CI. The branch was 25707 commits behind. The merge is clean; the change to `ReplicatedMergeTreeSink.cpp` and the integration tests are unchanged.
…-ambiguous-commit-rollback Fix data loss when replicated INSERT commit recovery is interrupted
…ypick/26.6/111196 # Conflicts: # src/Storages/MergeTree/ReplicatedMergeTreeSink.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Original pull-request #111196
Do not merge this PR manually
This pull-request is a first step of an automated backporting.
It contains changes similar to calling
git cherry-picklocally.If you intend to continue backporting the changes, then resolve all conflicts if any.
Otherwise, if you do not want to backport them, then just close this pull-request.
The check results does not matter at this step - you can safely ignore them.
Before you resolve anything
Conflicts are often caused by a prerequisite change that has not been backported yet, rather than by a real divergence. The bot re-tries this cherry-pick against the release branch on every run, so if that is the case here it will merge itself as soon as the prerequisite lands, and you will see a comment saying so. Manual resolution is only needed while the conflict persists.
Troubleshooting
If the conflicts were resolved in a wrong way
If this cherry-pick PR is completely screwed by a wrong conflicts resolution, and you want to recreate it:
pr-cherrypicklabel from the PRYou also need to check the Original pull-request for
pr-backports-createdlabel, and delete if it's presented thereThe PR source
The PR is created in the CI job