Skip to content

mysqlctl: stop incremental restore when file extraction fails - #22179

Open
shashi1973 wants to merge 1 commit into
vitessio:mainfrom
shashi1973:fix/issue-21954-incremental-restore
Open

shashi1973 wants to merge 1 commit into
vitessio:mainfrom
shashi1973:fix/issue-21954-incremental-restore

Conversation

@shashi1973

Copy link
Copy Markdown
Contributor

Description

Return the original backup-file extraction error before attempting incremental binlog replay, and clean up the temporary staging directory when extraction fails.

Previously, restoreFiles discarded the staging path on failure, and executeRestoreIncrementalBackup checked the extraction error after the replay loop. This could mask the original error and allow binlog paths to resolve against the tablet’s live binlog directory.

The fix checks the error immediately and preserves the staging path for deferred cleanup. A regression test injects a backup-storage read failure and verifies the original error is reported and the staging directory is removed.

Motivation

How do you use Vitess?

  • In production
  • In staging or development
  • Evaluating it
  • I don't use Vitess

Did you run this change against a real Vitess deployment?

Validation used FakeBackupHandle with the actual incremental restore helper. No live MySQL point-in-time restore was performed.

On unpatched main, the regression returned expected: Mysqld instead of the storage error and left a staging directory. It passed with the fix.

Related Issue(s)

Fixes #21954

Backport request

Please consider backporting this fix to release-23.0 and release-24.0.

The faulty error-check ordering is present in v16.0.0, which introduced incremental restore through #11097, and remains in both release branches. The fix prevents replay after failed extraction, preserves the original error, and removes temporary staging files.

Separate local backport patches passed the regression and file-path test against these branch baselines:

  • release-23.0 at 9adccbcfca6644b2bef1686bfa1fb7c038327162
  • release-24.0 at 42d00a0cb2af97a3078be677fd0d7c6853c926a3

Testing

The following focused tests passed on the refreshed main baseline and on my Mac with Go 1.27.4:

go test -p 4 ./go/vt/mysqlctl \
  -run '^(TestIncrementalRestoreCleansUpAfterStorageReadFailure|TestFileEntryFullPath|TestRestoreChunkedRetryPreservesData|TestRestoreFileEntriesSetupErrIsFatal|TestRestoreFileChunkRejectsDecompressedSizeMismatch)$' \
  -count=1

Mac result:

ok  vitess.io/vitess/go/vt/mysqlctl  0.594s

The repository formatter and git diff --check also passed. The complete mysqlctl suite was attempted in the assistant workspace but encountered Unix-socket listener restrictions.

Checklist

  • "Backport to:" labels have been added if this change should be back-ported to release branches
  • If this change is to be back-ported to previous releases, a justification is included in the PR description
  • Tests were added or are not required
  • Did the new or modified tests pass consistently locally and on CI?
  • Documentation was added or is not required

Deployment Notes

No configuration changes are required.

AI Disclosure

An OpenAI coding assistant helped prepare the implementation, regression test, and validation notes. I applied the patch and ran the focused tests locally on my Mac.

Signed-off-by: Shashishekar Hullahally Anantharamu <39974616+shashi1973@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings November 27, 2026 17:46
@vitess-bot vitess-bot Bot added NeedsWebsiteDocsUpdate What it says NeedsDescriptionUpdate The description is not clear or comprehensive enough, and needs work NeedsIssue A linked issue is missing for this Pull Request NeedsBackportReason If backport labels have been applied to a PR, a justification is required labels Nov 27, 2026
@github-actions github-actions Bot added this to the v25.0.0 milestone Nov 27, 2026
@vitess-bot

vitess-bot Bot commented Nov 27, 2026

Copy link
Copy Markdown
Contributor

Review Checklist

Hello reviewers! 👋 Please follow this checklist when reviewing this Pull Request.

General

  • Ensure that the Pull Request has a descriptive title.
  • Ensure there is a link to an issue (except for internal cleanup and flaky test fixes), new features should have an RFC that documents use cases and test cases.

Tests

  • Bug fixes should have at least one unit or end-to-end test, enhancement and new features should have a sufficient number of tests.

Documentation

  • Apply the release notes (needs details) label if users need to know about this change.
  • New features should be documented.
  • There should be some code comments as to why things are implemented the way they are.
  • There should be a comment at the top of each new or modified test to explain what the test does.

New flags

  • Is this flag really necessary?
  • Flag names must be clear and intuitive, use dashes (-), and have a clear help text.

If a workflow is added or modified:

  • Each item in Jobs should be named in order to mark it as required.
  • If the workflow needs to be marked as required, the maintainer team must be notified.

Backward compatibility

  • Protobuf changes should be wire-compatible.
  • Changes to _vt tables and RPCs need to be backward compatible.
  • RPC changes should be compatible with vitess-operator
  • If a flag is removed, then it should also be removed from vitess-operator and arewefastyet, if used there.
  • vtctl command output order should be stable and awk-able.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues are identified for the change to prevent binlog replay after backup extraction fails.

No open issues 🎉

What changed in this PR

Fixes incremental restore error handling in mysqlctl for #21954, preventing binlog replay after backup-file extraction fails.

Changes:

  • Checks extraction errors before replay, preserving the original failure.
  • Retains the staging directory path on failure so deferred cleanup can remove it.
  • Adds a regression test verifying error reporting and staging-directory cleanup after a storage read failure.
File Description
go/​vt/​mysqlctl/​builtinbackupengine.go Returns extraction errors before replay and preserves staging paths for cleanup.
go/​vt/​mysqlctl/​builtinbackupengine_test.go Adds regression coverage for storage read failures and cleanup.

Review effort: Balanced

@shashi1973

Copy link
Copy Markdown
Contributor Author

Hi @mattlord, I’ve opened #22179 with the fix and regression test for this issue. The focused tests passed locally on my Mac, and the PR includes the earlier validation results for both release branches.

I’ve requested backports to release-23.0 and release-24.0, with the justification in the description. Could you take a look when you have a chance? Thanks!

@mattlord mattlord left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for picking this up!

Blocking: I think that we should test the staging-directory cleanup on each error path that now returns createdDir, or make that cleanup independent of the path. The new test exercises only one of the six changed returns in restoreFiles (go/vt/mysqlctl/builtinbackupengine.go:1565-1605): its read failure is retried once and then fails at the retry's return createdDir, err (line 1600). Changing any of the other five back to return "", ... leaves every test passing. Three of those paths can be reached in an incremental restore: createChunkedDestinations failing on bad chunk metadata (line 1565), a fatal FAILED_PRECONDITION error such as a chunk's decompressed size mismatch (line 1570), and a context that is canceled before any file is dispatched (line 1574). I wonder if the simplest fix is to have executeRestoreIncrementalBackup create the staging directory itself, defer os.RemoveAll(createdDir) right away, and pass the directory to restoreFiles, which would then return only an error (the full restore passes ""). Every error path would then clean up by construction. The six return changes and the createdDir != "" guard would go away, since os.RemoveAll("") already does nothing, and the new test would cover the cleanup unchanged. I tried that locally: the targeted tests pass on macOS, and the Linux-only TestRestoreIncrementalBackupBuffered only needs to pass its own t.TempDir() (it vets with GOOS=linux). Otherwise, turning the new test into a table over those failure modes would close the gap. What do you think?

Locally, the full go/vt/mysqlctl package passes on macOS.

@codecov

codecov Bot commented Nov 27, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 60.00000% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 66.95%. Comparing base (70c7a72) to head (c0f2472).
⚠️ Report is 845 commits behind head on main.

Files with missing lines Patch % Lines
go/vt/mysqlctl/builtinbackupengine.go 60.00% 4 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##             main   #22179       +/-   ##
===========================================
- Coverage   69.67%   66.95%    -2.72%     
===========================================
  Files        1614       50     -1564     
  Lines      216793     7934   -208859     
===========================================
- Hits       151044     5312   -145732     
+ Misses      65749     2622    -63127     
Flag Coverage Δ
partial 66.95% <60.00%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

NeedsBackportReason If backport labels have been applied to a PR, a justification is required NeedsDescriptionUpdate The description is not clear or comprehensive enough, and needs work NeedsIssue A linked issue is missing for this Pull Request NeedsWebsiteDocsUpdate What it says Type: Bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

mysqlctl: incremental restore applies binlogs before checking whether they were restored

3 participants