Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix xtrabackup/builtin context when doing AddFiles #16806

Merged
merged 3 commits into from
Sep 27, 2024

Conversation

frouioui
Copy link
Member

@frouioui frouioui commented Sep 18, 2024

Description

This PR fixes a long standing issue in the xtrabackup engine: the context used to AddFiles by the backup storage was canceled before AddFiles had the chance to complete. This problem can be experienced with the S3 backup storage, as it uploads the file through a goroutine, Ceph also does that and have been impacted in the past too. That goroutine wouldn't have time to complete before the XtrabackupEngine.backupFiles function returned and canceled the context through a defer statement. Leading to AddFiles failing since the context we pass got canceled.

To avoid this issue, we never really passed the context down to AddFiles. We attempted to pass the context in #12500 but reverted it in #14311 since #14188 was raised.

This PR fixes that by not canceling the context automatically, but only when the backupFiles return an error. If we have an error anywhere while executing backupFiles we should attempt to cancel the addition of the files, otherwise we can assume there is nothing to cancel. A different goroutine already make sure to cancel the context if we reach a certain timeout when closing the files.

cc @L3o-pold @vczyh as the original authors of the two issues. I have tested this on my end with manual tests (only on S3), but do you mind making sure it fixes your issues?

Related Issue(s)

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

Signed-off-by: Florent Poinsard <florent.poinsard@outlook.fr>
Copy link
Contributor

vitess-bot bot commented Sep 18, 2024

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.

@vitess-bot vitess-bot bot added 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 labels Sep 18, 2024
@frouioui frouioui removed NeedsDescriptionUpdate The description is not clear or comprehensive enough, and needs work NeedsWebsiteDocsUpdate What it says 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 Sep 18, 2024
@frouioui frouioui requested a review from L3o-pold September 18, 2024 23:42
@github-actions github-actions bot added this to the v21.0.0 milestone Sep 18, 2024
@frouioui frouioui changed the title Use a context in S3's AddFiles Fix xtrabackup context when doing AddFiles Sep 18, 2024
Copy link

codecov bot commented Sep 19, 2024

Codecov Report

Attention: Patch coverage is 31.25000% with 11 lines in your changes missing coverage. Please review.

Project coverage is 69.49%. Comparing base (56c39b2) to head (1102c59).
Report is 28 commits behind head on main.

Files with missing lines Patch % Lines
go/vt/mysqlctl/s3backupstorage/s3.go 12.50% 7 Missing ⚠️
go/vt/mysqlctl/xtrabackupengine.go 0.00% 3 Missing ⚠️
go/vt/mysqlctl/builtinbackupengine.go 80.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #16806      +/-   ##
==========================================
- Coverage   69.53%   69.49%   -0.04%     
==========================================
  Files        1567     1569       +2     
  Lines      202388   202644     +256     
==========================================
+ Hits       140723   140826     +103     
- Misses      61665    61818     +153     

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

@L3o-pold
Copy link
Collaborator

@frouioui with your PR I can no longer listing backup for example:

/vt/bin/vtctldclient --server=vtctld:15999 --logtostderr=true GetBackups unsharded/-
E0919 12:12:39.588828      27 main.go:56] rpc error: code = Unknown desc = operation error S3: HeadBucket, https response error StatusCode: 301, RequestID: 2ACET95HY572K3PX, HostID: X2nVlauIKbd8pM8PqINAZCTtrmJ7LmHkCHVrCZq9tTbR3cLb8s4AnS/SnrELiZzroPbO69weCZ4=, api error MovedPermanently: Moved Permanently

@frouioui
Copy link
Member Author

@frouioui with your PR I can no longer listing backup for example:

/vt/bin/vtctldclient --server=vtctld:15999 --logtostderr=true GetBackups unsharded/-

E0919 12:12:39.588828      27 main.go:56] rpc error: code = Unknown desc = operation error S3: HeadBucket, https response error StatusCode: 301, RequestID: 2ACET95HY572K3PX, HostID: X2nVlauIKbd8pM8PqINAZCTtrmJ7LmHkCHVrCZq9tTbR3cLb8s4AnS/SnrELiZzroPbO69weCZ4=, api error MovedPermanently: Moved Permanently

Interesting, may I know what flags (redacted) you are using? We recently changed the SDK version, that might be the cause.

@L3o-pold
Copy link
Collaborator

@frouioui --backup_engine_implementation=builtin --s3_backup_aws_region=us-east-1 --s3_backup_storage_bucket=vitess --s3_backup_force_path_style=true --s3_backup_aws_endpoint=http://minio:9000

@deepthi
Copy link
Member

deepthi commented Sep 19, 2024

@L3o-pold could you test GetBackups with #16664? That way we know whether the SDK upgrade is already breaking you without the changes in this PR.

@frouioui
Copy link
Member Author

@L3o-pold could you test GetBackups with #16664? That way we know whether the SDK upgrade is already breaking you without the changes in this PR.

I tested and it is a problem introduced by #16664, it seems to be an issue with Minio and the new connector. I am still investigating

Signed-off-by: Florent Poinsard <florent.poinsard@outlook.fr>
@frouioui
Copy link
Member Author

@L3o-pold this should be fixed now, at least on my end with Minio I am able to do all kind of backup operations.

@frouioui frouioui changed the title Fix xtrabackup context when doing AddFiles Fix xtrabackup/builtin context when doing AddFiles Sep 20, 2024
@L3o-pold
Copy link
Collaborator

L3o-pold commented Sep 23, 2024

@frouioui it works great congrats and thanks <3

Copy link
Member

@deepthi deepthi left a comment

Choose a reason for hiding this comment

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

💯

@@ -47,6 +47,8 @@ import (
"github.com/aws/smithy-go/middleware"
"github.com/spf13/pflag"

smithyendpoints "github.com/aws/smithy-go/endpoints"
Copy link
Member

Choose a reason for hiding this comment

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

nit: I don't see why this needs an override.

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed via 1102c59, we still need an override though using simply "endpoints", the IDE and compiler was not happy. Not exactly sure why, but in the migration docs, they also use override, and the package is named "transport" (even if the path is endpoint), so i ended up overriding it by "transport".

Signed-off-by: Florent Poinsard <florent.poinsard@outlook.fr>
func newEndpointResolver() *endpointResolver {
return &endpointResolver{
r: s3.NewDefaultEndpointResolverV2(),
endpoint: &endpoint,
Copy link
Contributor

Choose a reason for hiding this comment

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

Would be nice IMO to have a comment about what this is here:

Suggested change
endpoint: &endpoint,
endpoint: &endpoint, // Use default endpoint of amazonaws.com

Copy link
Member Author

Choose a reason for hiding this comment

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

this is already the case in the variable definition:

// AWS endpoint, defaults to amazonaws.com but appliances may use a different location
	endpoint string

@frouioui frouioui merged commit 766bc64 into vitessio:main Sep 27, 2024
97 checks passed
@frouioui frouioui deleted the fix-backup-ctx branch September 27, 2024 21:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bug Report: v18.0.0-rc1 S3 backup failed to upload Failed to backup to ceph(s3) using xtrabackup
4 participants