Repository navigation
Conversation
Reversing a directory move rewrites one prefix.path marker per directory, and each of those is a separate object storage write. MetadataOperationsHolder::rollback stops at the first undo that throws, so the operations it never reached keep the writes they already made. The in-memory filesystem is unaffected, because a failed commit never publishes its snapshot, and the result is that object storage describes a filesystem this process does not have. Nothing reconciled the two. PARTIALLY_ROLLED_BACK was recorded and then never read, so the only trace was a sentence appended to the exception, and the disagreement survived until the filesystem was next rebuilt from object storage. For a MergeTree part rename that means the merge reports failure while the directory is left under its committed name, and a later restart loads a part the server never committed. Reload the filesystem from object storage when the rollback did not complete. It runs only after a transaction has already failed, and serving a filesystem that is known to disagree with object storage is worse than listing the disk again. The test needs a fault that fires only while undoing, because the existing plain_object_storage_write_fail_on_directory_move sits in rewriteSingleDirectory, which the forward pass calls first - so it can never leave a move half reversed.
|
Workflow [PR], commit [f36216b] Summary: ❌
AI ReviewSummaryThe PR teaches Findings
Final VerdictChanges requested. LLVM Coverage ReportMeasured on commit f36216b.
Changed lines: Changed C/C++ lines covered: 58/62 (93.55%) · Uncovered code |
|
|
||
| try | ||
| { | ||
| metadata_storage.dropCache(); |
There was a problem hiding this comment.
dropCache() runs after the metadata_mutex guard from line 409 has already been unwound, so another plain_rewritable commit can slip in before the reload and validate itself against the stale fs snapshot. In the normal DiskObjectStorageTransaction::writeFile() path the blob key was already chosen via generateObjectKeyForPath(), so a write to A/x in that window can succeed against the remote directory whose prefix.path already says MOVED/, and only later reappear as MOVED/x after this relist. The recovery path needs to keep later commits out until the reload finishes (or fence the disk), otherwise partial rollback still corrupts subsequent transactions.
|
That approach not better. We still has difference between memory and s3 state which we do not know. |
|
Closing this in favour of a different fix. Reloading the filesystem after a failed rollback does make the in-memory state agree with object storage, but it adopts a half-moved state that no transaction ever committed. At the point where the rollback stopped we do not know what object storage holds, so every decision taken from that state can be wrong, and adopting it is one such decision. The fence hole the review found has the same root. The replacement retries every stage of I will link the replacement pull request here. |
|
Replaced by #119235 |
A reversal that a shutdown abandons releases the metadata lock, and the transactions that were waiting for it resume at once. They decide what to write from a filesystem that object storage no longer matches, which is the state this branch exists to prevent - so the disk now takes no further transaction after that happens. The mark is set while the commit still holds the lock, and it is checked right after the lock is taken, because a transaction that was already waiting is past the point where it was created. Reads are still served: the filesystem in memory is the state that was committed, and a file resolves to the blob it did before. `refresh` and `dropCache` stop reloading, since reloading would adopt a state no transaction ever committed. Nothing here can make the two agree again, so this lasts until the next start, which loads the filesystem from object storage. `MetadataOperationsHolder::isPartiallyRolledBack` reports the state that decides this. It is the one piece worth keeping from #118623, which detected the same thing and then reloaded the filesystem to match object storage. Also fixes what CI reported on the tests: an override must not repeat the default arguments of the method it overrides, and a `catch (...)` needs to say that swallowing is intended. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Reversing a failed `plain_rewritable` metadata transaction is not atomic. Each object storage write is separate, and `MetadataOperationsHolder::rollback` stops at the first `undo` that throws. The writes the reversal never reached stay in object storage, while the in-memory filesystem still describes the state before the transaction, because a failed commit never publishes its snapshot. Nothing reconciles the two until the filesystem is rebuilt from object storage, so a `MergeTree` part directory can turn up under a name the server never committed. The state of object storage is unknown at that point, so no decision taken from it can be trusted, including the decision to accept it. Every stage of an `undo` now repeats until object storage accepts it, and a stage that succeeded never repeats. `MetadataStorageFromPlainObjectStorageMoveFileOperation` needs the second half of that: it drops a temporary copy once the blob the copy holds is back under its own key, so a retry that started the reversal over would copy from an object an earlier stage has already removed. A commit holds `metadata_mutex`, and so do `refresh` and `dropCache`, so no other transaction and no reload can read the filesystem of this disk while a reversal is still in progress. A shutdown is the only exit. The retries stop, the transaction reports its failure, and the next start loads the filesystem from object storage. The retries live in the plain-rewritable operations, so `MetadataOperationsHolder` and the other metadata storages keep their current behaviour. Related: ClickHouse#118623 Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Related: #118615
Reversing a directory move rewrites one
prefix.pathmarker per directory, and each of those is a separate object storage write.MetadataOperationsHolder::rollbackstops at the firstundo()that throws, so the operations it never reached keep the writes they already made. The in-memory filesystem is unaffected, because a failed commit never publishes its snapshot — and the result is that object storage describes a filesystem this process does not have.Nothing reconciled the two.
PARTIALLY_ROLLED_BACKwas recorded and then never read, so the only trace was a sentence appended to the exception, and the disagreement survived until the filesystem was next rebuilt from object storage. For a MergeTree part rename that means the merge reports failure while the directory is left under its committed name, and a later restart loads a part the server never committed.This reloads the filesystem from object storage when the rollback did not complete. Note it does not undo the move: once the rollback has failed, the pre-move state is gone from object storage, so the guarantee is that the in-memory filesystem matches what is actually there. The reload runs only after a transaction has already failed, and serving a filesystem known to disagree with object storage is worse than listing the disk again.
The test needs a fault that fires only while undoing, hence the new failpoint: the existing
plain_object_storage_write_fail_on_directory_movesits inrewriteSingleDirectory, which the forward pass calls first, so it can never leave a move half reversed.Open question for reviewers. The recovery is a full disk relist (
dropCache). It only fires after a rollback has already failed, so it should be rare, but on a largeplain_rewritabledisk it is a LIST storm at an already-bad moment. The cheaper alternative is a "needs reload" flag consumed by the nextrefresh(), butrefresh()is not guaranteed to run, so the stale window would be unbounded. I chose correctness; happy to switch if you prefer bounded cost.Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed
plain_rewritabledisks continuing to serve a filesystem that disagrees with object storage after a metadata transaction failed to roll back completely. The disagreement previously surfaced only after a restart, when a directory could appear under a name the server never committed.Documentation entry for user-facing changes
Workflow [PR]
Sync PR [sync-upstream/pr/118623]