Repository navigation
download: don't leave half-extracted parts when a download is interrupted, fix #1633 - #1675
Merged
Merged
Conversation
…1633 Signed-off-by: Ryo Kusnadi <ryokusnadi@gmail.com>
…1633 moveExtractedIntoPlace replaced every top-level entry with RemoveAll+Rename. With upload_by_part=false splitFilesBySize can split one part across several archives, and all archives of a table are extracted concurrently into the same table dir, so the second archive wiped the files of the first one (or failed with ENOTEMPTY when racing). Publish now renames a whole directory only when the target is missing and otherwise merges it file by file, RemoveAll only on a file/dir type conflict. A cancelled context is checked before publishing. A killed download (SIGKILL, OOM) skips the deferred cleanup and leaves .tmp_extract_* dirs, which restore copies into access/configs. They are removed once in downloadTablesMetadata (download and restore_remote --streaming), under the backup pid lock and before any download goroutine starts, depth-limited and scoped to the backup being downloaded. The prefix is the shared storage.ExtractTempDirPrefix constant. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Integration coverage for the merge-into-place fix: upload_by_part=false with a small max_file_size splits wide parts over several archives (asserted via more archives than parts on MinIO), an incremental --diff-from-remote backup is downloaded with download_by_part=true and download_concurrency=4 so the diff flow extracts all required-backup archives into one table dir, then restore must reproduce count() and sum(cityHash64(*)) and no .tmp_extract_* dirs may remain under /var/lib/clickhouse/backup. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ix/download-extract-parts-atomically
…ix/download-extract-parts-atomically # Conflicts: # ChangeLog.md
…nd verify split parts via tar listings Calibrate rows per part so each part is ~70% of max_file_size (above the CalculateMaxSize floor), read archive tar headers to assert at least one part spans several archives, use upload_by_part=true for the --diff-from-remote increment, hash explicit columns. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ouse before 19.15 upload_by_part=false grouped system.parts by disk_name, which doesn't exist before multiple disks support, create_remote/upload failed with code: 47, Unknown identifier: disk_name on 1.1.54394. Fall back to max over all active parts when the column is absent, there is only one disk there. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Coverage Report for CI Build 45810596740Coverage increased (+0.3%) to 70.831%Details
Uncovered Changes
Coverage RegressionsNo coverage regressions found. Coverage Stats
💛 - Coveralls |
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.
Reopened from #1665 by @RyoKusnadi (original fork was deleted); commit cherry-picked onto current master with authorship preserved.
Problem
After an interrupted
downloadof an incremental backup, runningdownloadagain can finish without an error, butrestore --datathen fails withcode: 226 ... Marks file ... doesn't existon some parts. Those parts were required parts of the full backup, and they were only half downloaded.How it happens:
downloadstopped (killed container, cancelled run) whileDownloadCompressedStreamwas still extracting a required part intobackup/<required>/shadow/<db>/<table>/<disk>/<part>. The half-extracted directory stays. On the next run,downloadDiffParts(pkg/backup/download.go, theelsebranch afteros.Stat(existsPath)) sees the directory, takes it as complete, and hard-links it into the incremental backup. This also happens without--resume, for example afterdelete local <incremental>and a newdownload.Cause
DownloadCompressedStreaminpkg/storage/general.goextracted straight into the final directory and did not remove the files it had already written when it failed or was cancelled.Fix
DownloadCompressedStreamnow extracts into a temporary directory insidelocalPath(.tmp_extract_*) and moves the top-level entries into place only after the whole archive was read. On any error the temporary directory is removed. So an existing part directory is complete. An entry already inlocalPath(a leftover from an older version or an earlier attempt) is replaced. This is step 1 of the proposal in the issue; it fixes all callers (required parts, own parts, backup-related dirs) at one place.Scope
downloadDiffParts, remove an existingexistsPaththat is not in the resumable state). Without--resumethat state is empty, so it would re-download every part of an already complete required backup. Leftovers written by older versions are still trusted. Happy to do it as a follow-up if you prefer..tmp_extract_*directory can stay inside the table directory. It is not a part directory, so it is not linked or restored.Testing
New tests in
pkg/storage/download_atomic_test.go(temp dirs, in-memory tar, no ClickHouse):TestDownloadCompressedStreamInterruptedLeavesNoPartDir: stream cut insidedata.bin. Before the fix:Should be empty, but was [20261001_1_1_0]. After: passes.TestDownloadCompressedStreamMovesCompletePartIntoPlace: complete archive replaces an old stale part directory. Before the fix:elements differ(stale.binstayed). After: passes.go test ./pkg/storage/passes,go vet ./pkg/storage/andgofmt -lare clean.Risk
One extra
renameper top-level entry after each archive, on the same filesystem. No config or format change. Revert the commit to roll back.Fixes #1633
🤖 Generated with Claude Code