From 3f591d98ab0b98cdb1d8cdff741b9d80246c5676 Mon Sep 17 00:00:00 2001 From: Florent Poinsard Date: Fri, 20 Sep 2024 15:50:10 -0600 Subject: [PATCH] Fix ctx in builtin and fix endpoint resolver Signed-off-by: Florent Poinsard --- go/vt/mysqlctl/builtinbackupengine.go | 10 +++++++--- go/vt/mysqlctl/s3backupstorage/s3.go | 21 ++++++++++++++++++++- 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/go/vt/mysqlctl/builtinbackupengine.go b/go/vt/mysqlctl/builtinbackupengine.go index 494d765f2a9..b8350a731d4 100644 --- a/go/vt/mysqlctl/builtinbackupengine.go +++ b/go/vt/mysqlctl/builtinbackupengine.go @@ -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) @@ -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) diff --git a/go/vt/mysqlctl/s3backupstorage/s3.go b/go/vt/mysqlctl/s3backupstorage/s3.go index 9bec0ed5bbb..eb696e09786 100644 --- a/go/vt/mysqlctl/s3backupstorage/s3.go +++ b/go/vt/mysqlctl/s3backupstorage/s3.go @@ -47,6 +47,8 @@ import ( "github.com/aws/smithy-go/middleware" "github.com/spf13/pflag" + smithyendpoints "github.com/aws/smithy-go/endpoints" + "vitess.io/vitess/go/vt/concurrency" "vitess.io/vitess/go/vt/log" stats "vitess.io/vitess/go/vt/mysqlctl/backupstats" @@ -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, + } +} + type iClient interface { manager.UploadAPIClient manager.DownloadAPIClient @@ -493,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")