Repository navigation
Sync BackupImpl lock-file handling and the Cloud-only resume state - #115387
Conversation
… needs `createLockFile` creates the lock with `writeFileIfNotExists`, so two backups racing for the same destination cannot both believe they own it. When the create fails it compares what is there against what it would have written: its own contents mean a concurrent backup, a completed `.backup` means the backup already exists, and a lock that has since disappeared rethrows the original failure rather than guessing. `removeLockFile` now reports whether the destination still holds the lock. `checkLockFile(false)` is false both for a foreign lock and for one it could not read, so a caller could not tell "not ours" from "unknown" while the lock was still there; `tryRemoveAllFiles` reports that as a failure rather than claiming the destination is clean. `open` also removes a lock it created when the verification that follows throws. Otherwise the lock outlives the failed attempt and fences the destination against every later one, which cannot match it either: a retry picks a fresh backup UUID, so the orphaned lock belongs to nobody. ClickHouse Cloud can continue an interrupted backup, and `BackupImpl` is where that is implemented, so the state it keeps for one belongs here: whether this attempt is a continuation, the timestamp text the earlier attempt wrote into `.backup`, the ownership check to run before publishing anything, and whether `.backup` is already published. All of it, the two helpers that reconcile an already-published manifest, and every place the shared implementation reads or reports it, are behind `CLICKHOUSE_CLOUD`, so this build behaves as it did: it writes its own timestamp and always publishes metadata. The parameters that fill the state in stay out, along with the code that reads them. Co-Authored-By: Claude Opus 5 <[email protected]>
|
Workflow [PR], commit [5473e8b] Summary: ✅
AI ReviewSummaryThis PR syncs the public Missing context / blind spots
Findings
Final VerdictChanges requested. The live head fixes two earlier cleanup holes, but it still leaves archive destinations dirty on LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 95/123 (77.24%) · Uncovered code |
BackupImpl lock-file handling and the Cloud-only resume state
| bool lock_created = false; | ||
| try | ||
| { | ||
| auto out = writer->writeFileIfNotExists(lock_file_name); |
There was a problem hiding this comment.
createLockFile() now assumes writeFileIfNotExists() is an atomic create, but that is only true for the dedicated object-storage writers. IBackupWriter::writeFileIfNotExists() still falls back to plain writeFile(), and BackupWriterFile / BackupWriterDisk only implement rewrite-mode opens, so concurrent BACKUP ... TO File(...) / Disk(...) calls can still overwrite each other's .lock and both continue.
That breaks the new contract and changelog claim that lock creation is now atomic across backup destinations. Please either add real exclusive-create implementations for those writers or scope this path so the stronger behavior is only used on backends that can actually enforce it.
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
Only the stripped binary is compared: the official master build keeps debug symbols while PR builds strip them, so the other binaries differ by construction. Compile time of recompiled translation units12 translation units recompiled, 30 s compile time in total, 12 of them have a recent master baseline. |
The resumer is ClickHouse Cloud only, and so is this call site; what changes here is that it compares against a named state instead of taking a bare bool whose meaning was only in the field it was assigned to. Co-Authored-By: Claude Opus 5 <[email protected]>
Only the ClickHouse Cloud resumer called it, and it needs nothing of `BackupImpl` beyond the writer, the UUID and the name for logging, so it belongs in the resumer -- which this build does not have. Its two includes were the only users of `IO/StdStreamFromReadBuffer.h` and `Poco/SAX/InputSource.h` here, and go with it. Co-Authored-By: Claude Opus 5 <[email protected]>
…kupImpl` `resuming`, `timestamp_text` and `resume_check_owner` were copies of fields of `params.resume`, which the ClickHouse Cloud resumer filled in while it reopened a destination that build already owns. The guarded code reads those parameters directly now, so this build carries three members fewer -- it had them declared but never set. Co-Authored-By: Claude Opus 5 <[email protected]>
| catch (...) | ||
| { | ||
| if (!params.is_internal_backup) | ||
| tryRemoveOwnLockFile(); |
There was a problem hiding this comment.
openArchive() can still leave the destination dirty even if the lock-cleanup catch is widened. createArchiveWriter() is called with writer->writeFile(archive_name) already materialized, and BackupWriterFile::writeFile() / BackupWriterDisk::writeFile() open rewrite-mode buffers immediately. A concrete repro is BACKUP ... TO File('backup.badext'): archive_name is created or truncated before createArchiveWriter() throws CANNOT_PACK_ARCHIVE, so the constructor unwinds with an empty archive file already present.
The next retry then fails in checkBackupDoesntExist() with BACKUP_ALREADY_EXISTS even if the .lock were removed. Please validate the archive type before opening archive_name, or remove the partially created archive object on this failure path as well.
`BackupImpl` kept a `metadata_already_published` member and a getter for it, both describing something only the ClickHouse Cloud resumer can find out: that the attempt being continued had already published `.backup`. That now lives with the progress record of the attempt, which this build does not have either, and the guarded code reads it back through the resume parameters. `BackupImpl` keeps no resume state at all. The write in `writeBackupMetadata` went with it: nothing could observe it. Its only caller had already branched on the flag, and set `writing_finalized` right after, which is what every later reader checks first. Co-Authored-By: Claude Opus 5 <[email protected]>
It promised the write-open state this class no longer keeps. What the ClickHouse Cloud resumer needs is the writer, the lock file and the helpers that claim and release it. Co-Authored-By: Claude Opus 5 <[email protected]>
`resumable_backup_batch_size` and `resumable_backup_batch_size_bytes` bound the work a continued `BACKUP FROM SNAPSHOT` has to redo. Nothing outside ClickHouse Cloud resumes one, so both are behind `CLICKHOUSE_CLOUD` and this build has neither -- what it gains is that `BackupSettings` no longer differs from the private copy here. A macro list cannot hold a preprocessor conditional, so the conditional selects the list: `LIST_OF_CLOUD_BACKUP_SETTINGS` is the two settings or nothing. Co-Authored-By: Claude Opus 5 <[email protected]>
|
Taking a look at the bot's comments. I promise I did not add anything on top of what is already merged in private. |
`open` runs from the constructor, so a throw leaves no backup for anything else to clean up: the cleanup in `open` is all there is. It covered the verification that follows creating the lock, and nothing else, so two paths still left the lock behind -- `createLockFile` throwing after the write committed, and `openArchive` failing afterwards. A lock that outlives its attempt fences the destination for good, because a retry picks a fresh backup UUID and can never match it. The guard now spans claiming the destination and opening the archive, which is everything a write does before the backup exists. Reading and unlocking keep their own `openArchive` call, where there is no lock to lose. Co-Authored-By: Claude Opus 5 <[email protected]>
Is beyond the scope of this PR which is supposed to be private-to-public sync. |
Related: https://github.com/ClickHouse/clickhouse-private/pull/69709
This is the public side of the private pull request above, and most of it is that sync. The shared files both touch --
BackupImpl.h,BackupImpl.cpp,BackupSettings.h,BackupSettings.cpp,BackupFactory.h-- are identical here and there, down to the blank lines, soCheck public buildcan overlay the private ones unchanged and later syncs have nothing to reconcile in them. What stays private is where continuing an interrupted backup is implemented, because nothing outside ClickHouse Cloud resumes one.The part that changes this build is the lock-file handling.
openruns from the constructor, so a failure there leaves no backup behind for anything else to clean up: whateveropendoes not undo, nothing will. It now removes the lock it created when anything that follows throws -- the verification, the rest of claiming the destination, and opening the archive. Otherwise the lock outlives the failed attempt and fences the destination against every later one, which cannot match it either: a retry picks a fresh backup UUID, so the orphaned lock belongs to nobody, and every subsequentBACKUPto that destination fails until someone deletes the file by hand.removeLockFilenow reports whether the destination still holds the lock.checkLockFile(false)is false both for a foreign lock and for one it could not read, so a caller could not tell "not ours" from "unknown" while the lock was still there;tryRemoveAllFilesreports that as a failure rather than claiming the destination is clean.createLockFileasks for the lock withwriteFileIfNotExistsand, when that fails, compares what is there against what it would have written: its own contents mean a concurrent backup, a completed.backupmeans the backup already exists, and a lock that has since disappeared rethrows the original failure rather than guessing.writeFileIfNotExistsis only exclusive where the storage can be --S3andAzureimplement it, every other writer falls back to an ordinary write.Known gaps
Two of them, both predating this change and both worth naming rather than implying they are fixed.
File,DiskandMemorydestinations still have no exclusive create, so two backups started against one of them can each write.lock, each verify their own contents, and both proceed. The comparison above detects a lock that is already there; it cannot order two writers racing to create one. Closing this needs an exclusive create in those writers.An archive whose type
createArchiveWriterrefuses -- an unsupported extension, a compiled-out library -- still leaves the archive object behind, because the buffer it is given is created before the type is checked. The lock is removed, but the next attempt finds the archive and reports the destination as an existing backup.The rest
Behind
CLICKHOUSE_CLOUD, and compiling to nothing here:CreateParamscarries the resume parameters,openhands them to aBackupResumerthis build does not have, and the places that read them are the ownership check before anything becomes visible, the timestamp a continuation republishes, the lock a continuation is allowed to find, and the manifest it does not write again.BackupSettingscarries the two batch-size settings that bound the work a continuation redoes; a macro list cannot hold a preprocessor conditional, so the conditional selects the list.BackupImplkeeps one member,metadata_already_published. So this build behaves as it did: it writes its own timestamp and always publishes metadata.Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
BACKUPno longer leaves a lock file behind in its destination when the attempt that created it fails before writing anything -- whether it fails while claiming the destination or while opening an archive. No later backup could match such a lock, so every retry to the same destination failed until the file was deleted by hand. Backups toS3andAzuredestinations also create the lock exclusively, and a lock that belongs to another backup is reported as a concurrent backup rather than as whatever error the storage returned.Workflow [PR]
Sync PR [sync-upstream/pr/115387]
Version info
26.8.1.1800(included in26.8and later)