Repository navigation
download: don't leave half-extracted parts when a download is interrupted, fix #1633 - #1665
Open
RyoKusnadi wants to merge 1 commit into
Open
RyoKusnadi wants to merge 1 commit into
RyoKusnadi wants to merge 1 commit into
Conversation
…ltinity#1633 Signed-off-by: Ryo Kusnadi <ryokusnadi@gmail.com>
Author
|
A note on the red |
Author
|
@Slach friendly ping on this one when you have a moment. Happy to change anything. |
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.
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