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
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions go/vt/mysqlctl/builtinbackupengine.go
Original file line number Diff line number Diff line change
Expand Up @@ -399,8 +399,8 @@ func (be *BuiltinBackupEngine) executeFullBackup(ctx context.Context, params Bac
// Save initial state so we can restore.
replicaStartRequired := false
sourceIsPrimary := false
superReadOnly := true //nolint
readOnly := true //nolint
superReadOnly := true // nolint
readOnly := true // nolint
var replicationPosition replication.Position
semiSyncSource, semiSyncReplica := params.Mysqld.SemiSyncEnabled(ctx)

Expand Down Expand Up @@ -793,7 +793,11 @@ func (bp *backupPipe) ReportProgress(period time.Duration, logger logutil.Logger
// backupFile backs up an individual file.
func (be *BuiltinBackupEngine) backupFile(ctx context.Context, params BackupParams, bh backupstorage.BackupHandle, fe *FileEntry, name string) (finalErr error) {
ctx, cancel := context.WithCancel(ctx)
defer cancel()
defer func() {
if finalErr != nil {
cancel()
}
}()
// Open the source file for reading.
openSourceAt := time.Now()
source, err := fe.open(params.Cnf, true)
Expand Down
24 changes: 21 additions & 3 deletions go/vt/mysqlctl/s3backupstorage/s3.go
Original file line number Diff line number Diff line change
Expand Up @@ -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".


"vitess.io/vitess/go/vt/concurrency"
"vitess.io/vitess/go/vt/log"
stats "vitess.io/vitess/go/vt/mysqlctl/backupstats"
Expand Down Expand Up @@ -110,6 +112,23 @@ var logNameMap logNameToLogLevel

const sseCustomerPrefix = "sse_c:"

type endpointResolver struct {
r s3.EndpointResolverV2
endpoint *string
}

func (er *endpointResolver) ResolveEndpoint(ctx context.Context, params s3.EndpointParameters) (smithyendpoints.Endpoint, error) {
params.Endpoint = er.endpoint
return er.r.ResolveEndpoint(ctx, params)
}

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

}
}

type iClient interface {
manager.UploadAPIClient
manager.DownloadAPIClient
Expand Down Expand Up @@ -182,8 +201,7 @@ func (bh *S3BackupHandle) AddFile(ctx context.Context, filename string, filesize
})
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(context.Background(), &s3.PutObjectInput{
_, err := uploader.Upload(ctx, &s3.PutObjectInput{
Bucket: &bucket,
Key: &object,
Body: reader,
Expand Down Expand Up @@ -494,7 +512,7 @@ func (bs *S3BackupStorage) client() (*s3.Client, error) {
o.RetryMaxAttempts = retryCount
o.Retryer = &ClosedConnectionRetryer{}
}
})
}, s3.WithEndpointResolverV2(newEndpointResolver()))

if len(bucket) == 0 {
return nil, fmt.Errorf("--s3_backup_storage_bucket required")
Expand Down
9 changes: 8 additions & 1 deletion go/vt/mysqlctl/xtrabackupengine.go
Original file line number Diff line number Diff line change
Expand Up @@ -316,8 +316,15 @@ func (be *XtrabackupEngine) backupFiles(
// would impose a timeout that starts counting right now, so it would
// include the time spent uploading the file content. We only want to impose
// a timeout on the final Close() step.
// This context also allows us to immediately abort AddFiles if we encountered
// an error in this function.
addFilesCtx, cancelAddFiles := context.WithCancel(ctx)
defer cancelAddFiles()
defer func() {
if finalErr != nil {
cancelAddFiles()
}
}()

destFiles, err := addStripeFiles(addFilesCtx, params, bh, backupFileName, numStripes)
if err != nil {
return replicationPosition, vterrors.Wrapf(err, "cannot create backup file %v", backupFileName)
Expand Down
Loading