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

Migrate the S3 SDK from v1 to v2 #16664

Merged
merged 3 commits into from
Sep 17, 2024
Merged

Migrate the S3 SDK from v1 to v2 #16664

merged 3 commits into from
Sep 17, 2024

Conversation

frouioui
Copy link
Member

@frouioui frouioui commented Aug 27, 2024

Description

This PR updates the version of the AWS SDK from v1 to v2. The version 1 has been deprecated for some time now.

I have ran the following manual test:

  1. Create a Vitess cluster (1 unsharded keyspace) from the main branch
  2. Insert some data
  3. Backup the cluster into AWS S3
  4. Teardown the cluster
  5. Create a Vitess cluster (same config) from the migrate-to-s3-v2 branch (with --restore_from_backup)
  6. Restore from the previous backup
  7. Observe that the inserted data shows up after restoring
  8. Take another backup on AWS S3
  9. List all available backup on AWS S3
  10. Restore the cluster from the latest backup (using RestoreFromBackup)
  11. Remove the first backup we did (the one from main) from AWS S3
  12. Teardown the cluster
  13. Create another Vitess cluster (same config) from the main branch (with --restore_from_backup)
  14. Observe that the inserted data shows up after restoring

This test ensures that we can upgrade: old backups will still work with the new code, and that we can downgrade: new backups will work with the old code. While making sure that no config/flag change is needed between the two code version. It also checks that the GetBackups and RestoreFromBackup vtctldclient commands work.

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

Copy link
Contributor

vitess-bot bot commented Aug 27, 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 Aug 27, 2024
@github-actions github-actions bot added this to the v21.0.0 milestone Aug 27, 2024
@frouioui frouioui force-pushed the migrate-to-s3-v2 branch 2 times, most recently from bd75773 to 9edbe34 Compare September 5, 2024 16:04
Signed-off-by: Florent Poinsard <florent.poinsard@outlook.fr>
Signed-off-by: Florent Poinsard <florent.poinsard@outlook.fr>
@frouioui frouioui added Type: Internal Cleanup Component: Backup and Restore and 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 12, 2024
Copy link

codecov bot commented Sep 12, 2024

Codecov Report

Attention: Patch coverage is 40.50633% with 47 lines in your changes missing coverage. Please review.

Project coverage is 68.96%. Comparing base (538dd4c) to head (02598ab).
Report is 81 commits behind head on main.

Files with missing lines Patch % Lines
go/vt/mysqlctl/s3backupstorage/s3.go 37.50% 40 Missing ⚠️
go/vt/mysqlctl/s3backupstorage/retryer.go 57.14% 6 Missing ⚠️
go/vt/mysqlctl/xtrabackupengine.go 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #16664      +/-   ##
==========================================
- Coverage   68.98%   68.96%   -0.03%     
==========================================
  Files        1562     1565       +3     
  Lines      200690   201770    +1080     
==========================================
+ Hits       138449   139142     +693     
- Misses      62241    62628     +387     

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

Signed-off-by: Florent Poinsard <florent.poinsard@outlook.fr>
u.PartSize = partSizeBytes
})
object := objName(bh.dir, bh.name, filename)
sendStats := bh.bs.params.Stats.Scope(stats.Operation("AWS:Request:Send"))
// Using UploadWithContext breaks uploading to Minio and Ceph https://github.com/vitessio/vitess/issues/14188
_, err := uploader.Upload(&s3manager.UploadInput{
_, err := uploader.Upload(context.Background(), &s3.PutObjectInput{
Copy link
Member Author

Choose a reason for hiding this comment

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

Using context.Background() is a side-effect of the issue described in #14188. Upgrading to the SDK V2 does not fix it, the issue is rooted in how we handle the context and the goroutines. I started investigating the issue a bit deeper and will continue in a subsequent PR.

@deepthi deepthi removed the request for review from rohit-nayak-ps September 12, 2024 23:27
r: &request.Request{
Retryable: aws.Bool(false),
},
name: "no error",
Copy link
Member

Choose a reason for hiding this comment

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

Nice refactor.

@@ -277,7 +277,7 @@ func (be *XtrabackupEngine) executeFullBackup(ctx context.Context, params Backup
if err != nil {
return BackupUnusable, vterrors.Wrapf(err, "cannot JSON encode %v", backupManifestFileName)
}
if _, err := mwc.Write([]byte(data)); err != nil {
if _, err := mwc.Write(data); err != nil {
Copy link
Member

Choose a reason for hiding this comment

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

This code is going to be called regardless of s3 or other storage backend. Why this change?

Copy link
Member Author

@frouioui frouioui Sep 12, 2024

Choose a reason for hiding this comment

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

data is a already a slice of bytes, I saw it while debugging something and thought I'd remove the useless conversion, I can revert if you want

@frouioui frouioui merged commit 3182049 into main Sep 17, 2024
189 checks passed
@frouioui frouioui deleted the migrate-to-s3-v2 branch September 17, 2024 23:28
@marf
Copy link

marf commented Nov 30, 2024

Hi, I have recently upgraded to Vitess v21 from v20. Now the backup fails with the following error:

+ /vt/bin/vtctldclient --action_timeout=2h0m0s --server esound-vtctld-d7707a8c.default.svc.cluster.local:15999 BackupShard esound/-
E1130 13:16:50.577523       7 main.go:56] rpc error: code = Unknown desc = TabletManager.Backup on uk-0828527281: StartBackup failed: operation error S3: HeadBucket, resolve auth scheme: resolve endpoint: endpoint rule error, Custom endpoint `` was not a valid URI

I haven't changed how the backup configuration works and the s3 credentials and configuration are correct, I copy it here:

spec:
  backup:
    locations:
      - s3:
          authSecret:
            key: credentials
            name: vitess-s3-credentials
          bucket: esound-vitess-backup
          region: eu-west-2

Any idea what this could be? Seems more an issue with this PR.

Thank you!

@marf
Copy link

marf commented Nov 30, 2024

I think I have found the issue.

Seems a bug with the fact that it does not check if the endpoint config is not specified and if not specified it uses an empty value instead of completely ignoring it and constructing the URL from the other parameters.

I managed to get it working by specifying this in the spec:

spec:
  backup:
    locations:
      - s3:
          authSecret:
            key: credentials
            name: vitess-s3-credentials
          bucket: esound-vitess-backup
          region: eu-west-2
          endpoint: https://s3.eu-west-2.amazonaws.com/ # fix for Vitess v21.0.0

@frouioui
Copy link
Member Author

frouioui commented Dec 2, 2024

Hi @marf, thanks for raising this. I opened a direct Pull Request to release-21.0 to fix the issue, we should be releasing a new v21 patch tonight. #17307

@marf
Copy link

marf commented Dec 2, 2024

Thank you @frouioui.

As soon as released I will test it.

I want to raise also the fact that even in the case I specified a custom endpoint to make the backup working after a certain point during the finalization of the backup for a large table that we have called usertrack we get this error:

esound/- (uk-0828527281): time:{seconds:1733007057 nanoseconds:802234680} file:"builtinbackupengine.go" line:803 value:"backing up  \"vt_esound/userstracks.ibd\": 98.91% (417421408.00/422031360.00kb)"
esound/- (uk-0828527281): time:{seconds:1733007062 nanoseconds:802172059} file:"builtinbackupengine.go" line:803 value:"backing up  \"vt_esound/userstracks.ibd\": 99.38% (419396064.00/422031360.00kb)"
esound/- (uk-0828527281): time:{seconds:1733007067 nanoseconds:802024811} file:"builtinbackupengine.go" line:803 value:"backing up  \"vt_esound/userstracks.ibd\": 99.96% (421879616.00/422031360.00kb)"
esound/- (uk-0828527281): time:{seconds:1733007068 nanoseconds:95660900} file:"builtinbackupengine.go" line:902 value:"closing compressor"
esound/- (uk-0828527281): time:{seconds:1733007068 nanoseconds:97128328} file:"builtinbackupengine.go" line:795 value:"Completed backing up  \"vt_esound/userstracks.ibd\""
esound/- (uk-0828527281): time:{seconds:1733007081 nanoseconds:110832416} file:"builtinbackupengine.go" line:509 value:"resetting mysqld super_read_only to true"
esound/- (uk-0828527281): time:{seconds:1733007081 nanoseconds:111730683} file:"builtinbackupengine.go" line:526 value:"restarting mysql replication"
E1130 22:51:23.243289       7 main.go:56] rpc error: code = Unknown desc = TabletManager.Backup on uk-0828527281: upload multipart failed, upload id: PbdDGKgIlKtHUj0OYGkB.gI.g.TINRpUZtUZwHqOHkhthC9Uu04ScDsqiPDN5XMnvxkQW8T4d0Z01gpM2P26ebuHN73TVLYfa4pUI7I7Pg7bILDB2g13j0371Ga9KFKi, cause: operation error S3: UploadPart, https response error StatusCode: 0, RequestID: , HostID: , canceled, context canceled

I then downgraded to vitess v20.0.3 and this issue seems not to happen with this version. Not sure if it is something related with the upgrade of the S3 SDK.

@frouioui
Copy link
Member Author

frouioui commented Dec 2, 2024

This is fixed by #17285 and is already included in the upcoming 21.0.1 release.

@marf
Copy link

marf commented Dec 2, 2024

Awesome, thank you @frouioui.

@frouioui
Copy link
Member Author

frouioui commented Dec 2, 2024

As soon as released I will test it.

Thanks for that! If you see any issue, let me know :)

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.

4 participants