From b006f4b8d8ebcc3fab20946ee64650008b1947cb Mon Sep 17 00:00:00 2001 From: Florent Poinsard Date: Thu, 5 Dec 2024 15:03:18 -0600 Subject: [PATCH] BackupHandle and s3_mock suggestions Signed-off-by: Florent Poinsard --- go/vt/mysqlctl/azblobbackupstorage/azblob.go | 23 +----------------- go/vt/mysqlctl/cephbackupstorage/ceph.go | 21 +--------------- go/vt/mysqlctl/fakebackupstorage.go | 22 +---------------- go/vt/mysqlctl/filebackupstorage/file.go | 23 +----------------- go/vt/mysqlctl/gcsbackupstorage/gcs.go | 21 +--------------- go/vt/mysqlctl/s3backupstorage/s3.go | 25 +------------------- go/vt/mysqlctl/s3backupstorage/s3_mock.go | 3 ++- 7 files changed, 8 insertions(+), 130 deletions(-) diff --git a/go/vt/mysqlctl/azblobbackupstorage/azblob.go b/go/vt/mysqlctl/azblobbackupstorage/azblob.go index f1ddefd6f01..54705d496fc 100644 --- a/go/vt/mysqlctl/azblobbackupstorage/azblob.go +++ b/go/vt/mysqlctl/azblobbackupstorage/azblob.go @@ -203,9 +203,9 @@ type AZBlobBackupHandle struct { name string readOnly bool waitGroup sync.WaitGroup - errors errorsbackup.PerFileErrorRecorder ctx context.Context cancel context.CancelFunc + errorsbackup.PerFileErrorRecorder } // Directory implements BackupHandle. @@ -218,27 +218,6 @@ func (bh *AZBlobBackupHandle) Name() string { return bh.name } -// RecordError is part of the concurrency.ErrorRecorder interface. -func (bh *AZBlobBackupHandle) RecordError(filename string, err error) { - bh.errors.RecordError(filename, err) -} - -// HasErrors is part of the concurrency.ErrorRecorder interface. -func (bh *AZBlobBackupHandle) HasErrors() bool { - return bh.errors.HasErrors() -} - -// Error is part of the concurrency.ErrorRecorder interface. -func (bh *AZBlobBackupHandle) Error() error { - return bh.errors.Error() -} - -func (bh *AZBlobBackupHandle) GetFailedFiles() []string { return bh.errors.GetFailedFiles() } - -func (bh *AZBlobBackupHandle) ResetErrorForFile(filename string) { - bh.errors.ResetErrorForFile(filename) -} - // AddFile implements BackupHandle. func (bh *AZBlobBackupHandle) AddFile(ctx context.Context, filename string, filesize int64) (io.WriteCloser, error) { if bh.readOnly { diff --git a/go/vt/mysqlctl/cephbackupstorage/ceph.go b/go/vt/mysqlctl/cephbackupstorage/ceph.go index 8deb9aee63a..fea11b0262a 100644 --- a/go/vt/mysqlctl/cephbackupstorage/ceph.go +++ b/go/vt/mysqlctl/cephbackupstorage/ceph.go @@ -70,29 +70,10 @@ type CephBackupHandle struct { dir string name string readOnly bool - errors errorsbackup.PerFileErrorRecorder waitGroup sync.WaitGroup + errorsbackup.PerFileErrorRecorder } -// RecordError is part of the concurrency.ErrorRecorder interface. -func (bh *CephBackupHandle) RecordError(filename string, err error) { - bh.errors.RecordError(filename, err) -} - -// HasErrors is part of the concurrency.ErrorRecorder interface. -func (bh *CephBackupHandle) HasErrors() bool { - return bh.errors.HasErrors() -} - -// Error is part of the concurrency.ErrorRecorder interface. -func (bh *CephBackupHandle) Error() error { - return bh.errors.Error() -} - -func (bh *CephBackupHandle) GetFailedFiles() []string { return bh.errors.GetFailedFiles() } - -func (bh *CephBackupHandle) ResetErrorForFile(filename string) { bh.errors.ResetErrorForFile(filename) } - // Directory implements BackupHandle. func (bh *CephBackupHandle) Directory() string { return bh.dir diff --git a/go/vt/mysqlctl/fakebackupstorage.go b/go/vt/mysqlctl/fakebackupstorage.go index da5b1cd1609..0ffa9d291ab 100644 --- a/go/vt/mysqlctl/fakebackupstorage.go +++ b/go/vt/mysqlctl/fakebackupstorage.go @@ -29,7 +29,7 @@ type FakeBackupHandle struct { Dir string NameV string ReadOnly bool - Errors errorsbackup.PerFileErrorRecorder + errorsbackup.PerFileErrorRecorder AbortBackupCalls []context.Context AbortBackupReturn error @@ -58,26 +58,6 @@ type FakeBackupHandleReadFileCall struct { Filename string } -func (fbh *FakeBackupHandle) RecordError(filename string, err error) { - fbh.Errors.RecordError(filename, err) -} - -func (fbh *FakeBackupHandle) HasErrors() bool { - return fbh.Errors.HasErrors() -} - -func (fbh *FakeBackupHandle) Error() error { - return fbh.Errors.Error() -} - -func (fbh *FakeBackupHandle) GetFailedFiles() []string { - return fbh.Errors.GetFailedFiles() -} - -func (fbh *FakeBackupHandle) ResetErrorForFile(filename string) { - fbh.Errors.ResetErrorForFile(filename) -} - func (fbh *FakeBackupHandle) Directory() string { return fbh.Dir } diff --git a/go/vt/mysqlctl/filebackupstorage/file.go b/go/vt/mysqlctl/filebackupstorage/file.go index c088aa1477a..9cbde1cb3a2 100644 --- a/go/vt/mysqlctl/filebackupstorage/file.go +++ b/go/vt/mysqlctl/filebackupstorage/file.go @@ -60,7 +60,7 @@ type FileBackupHandle struct { dir string name string readOnly bool - errors errorsbackup.PerFileErrorRecorder + errorsbackup.PerFileErrorRecorder } func NewBackupHandle( @@ -80,27 +80,6 @@ func NewBackupHandle( } } -// RecordError is part of the concurrency.ErrorRecorder interface. -func (fbh *FileBackupHandle) RecordError(filename string, err error) { - fbh.errors.RecordError(filename, err) -} - -// HasErrors is part of the concurrency.ErrorRecorder interface. -func (fbh *FileBackupHandle) HasErrors() bool { - return fbh.errors.HasErrors() -} - -// Error is part of the concurrency.ErrorRecorder interface. -func (fbh *FileBackupHandle) Error() error { - return fbh.errors.Error() -} - -func (fbh *FileBackupHandle) GetFailedFiles() []string { return fbh.errors.GetFailedFiles() } - -func (fbh *FileBackupHandle) ResetErrorForFile(filename string) { - fbh.errors.ResetErrorForFile(filename) -} - // Directory is part of the BackupHandle interface func (fbh *FileBackupHandle) Directory() string { return fbh.dir diff --git a/go/vt/mysqlctl/gcsbackupstorage/gcs.go b/go/vt/mysqlctl/gcsbackupstorage/gcs.go index 9da39ac6ba7..c3a2e4bda19 100644 --- a/go/vt/mysqlctl/gcsbackupstorage/gcs.go +++ b/go/vt/mysqlctl/gcsbackupstorage/gcs.go @@ -66,28 +66,9 @@ type GCSBackupHandle struct { dir string name string readOnly bool - errors errorsbackup.PerFileErrorRecorder + errorsbackup.PerFileErrorRecorder } -// RecordError is part of the concurrency.ErrorRecorder interface. -func (bh *GCSBackupHandle) RecordError(filename string, err error) { - bh.errors.RecordError(filename, err) -} - -// HasErrors is part of the concurrency.ErrorRecorder interface. -func (bh *GCSBackupHandle) HasErrors() bool { - return bh.errors.HasErrors() -} - -// Error is part of the concurrency.ErrorRecorder interface. -func (bh *GCSBackupHandle) Error() error { - return bh.errors.Error() -} - -func (bh *GCSBackupHandle) GetFailedFiles() []string { return bh.errors.GetFailedFiles() } - -func (bh *GCSBackupHandle) ResetErrorForFile(filename string) { bh.errors.ResetErrorForFile(filename) } - // Directory implements BackupHandle. func (bh *GCSBackupHandle) Directory() string { return bh.dir diff --git a/go/vt/mysqlctl/s3backupstorage/s3.go b/go/vt/mysqlctl/s3backupstorage/s3.go index 1267518a472..0657cec44e8 100644 --- a/go/vt/mysqlctl/s3backupstorage/s3.go +++ b/go/vt/mysqlctl/s3backupstorage/s3.go @@ -146,8 +146,8 @@ type S3BackupHandle struct { dir string name string readOnly bool - errors errorsbackup.PerFileErrorRecorder waitGroup sync.WaitGroup + errorsbackup.PerFileErrorRecorder } // Directory is part of the backupstorage.BackupHandle interface. @@ -160,29 +160,6 @@ func (bh *S3BackupHandle) Name() string { return bh.name } -// RecordError is part of the concurrency.ErrorRecorder interface. -func (bh *S3BackupHandle) RecordError(filename string, err error) { - bh.errors.RecordError(filename, err) -} - -// HasErrors is part of the concurrency.ErrorRecorder interface. -func (bh *S3BackupHandle) HasErrors() bool { - return bh.errors.HasErrors() -} - -// Error is part of the concurrency.ErrorRecorder interface. -func (bh *S3BackupHandle) Error() error { - return bh.errors.Error() -} - -func (bh *S3BackupHandle) GetFailedFiles() []string { - return bh.errors.GetFailedFiles() -} - -func (bh *S3BackupHandle) ResetErrorForFile(filename string) { - bh.errors.ResetErrorForFile(filename) -} - // AddFile is part of the backupstorage.BackupHandle interface. func (bh *S3BackupHandle) AddFile(ctx context.Context, filename string, filesize int64) (io.WriteCloser, error) { if bh.readOnly { diff --git a/go/vt/mysqlctl/s3backupstorage/s3_mock.go b/go/vt/mysqlctl/s3backupstorage/s3_mock.go index f6fae975fa0..f244c4d63b1 100644 --- a/go/vt/mysqlctl/s3backupstorage/s3_mock.go +++ b/go/vt/mysqlctl/s3backupstorage/s3_mock.go @@ -215,7 +215,8 @@ func FailFirstRead(s3bh *S3BackupHandle, ctx context.Context, filename string, f // FailAllReadExpectManifest is used to fail every attempt at reading a file from S3. // Only the MANIFEST file is allowed to be read, because otherwise we wouldn't even try to read the normal files. func FailAllReadExpectManifest(s3bh *S3BackupHandle, ctx context.Context, filename string, _ bool) (io.ReadCloser, error) { - if filename == "MANIFEST" { + const manifestFileName = "MANIFEST" + if filename == manifestFileName { return s3bh.ReadFile(ctx, filename) } return &failRead{}, nil