From ff0f5c8bab4db3d587e37cce6df7188c3e6400ab Mon Sep 17 00:00:00 2001 From: Florent Poinsard Date: Wed, 18 Sep 2024 17:28:33 -0600 Subject: [PATCH] Use a context in S3's AddFiles Signed-off-by: Florent Poinsard --- go/vt/mysqlctl/s3backupstorage/s3.go | 3 +-- go/vt/mysqlctl/xtrabackupengine.go | 9 ++++++++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/go/vt/mysqlctl/s3backupstorage/s3.go b/go/vt/mysqlctl/s3backupstorage/s3.go index 1af1362ae30..9bec0ed5bbb 100644 --- a/go/vt/mysqlctl/s3backupstorage/s3.go +++ b/go/vt/mysqlctl/s3backupstorage/s3.go @@ -182,8 +182,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, diff --git a/go/vt/mysqlctl/xtrabackupengine.go b/go/vt/mysqlctl/xtrabackupengine.go index 784d718af26..daba8bb1ec3 100644 --- a/go/vt/mysqlctl/xtrabackupengine.go +++ b/go/vt/mysqlctl/xtrabackupengine.go @@ -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)