Skip to content

Commit

Permalink
BackupHandle and s3_mock suggestions
Browse files Browse the repository at this point in the history
Signed-off-by: Florent Poinsard <[email protected]>
  • Loading branch information
frouioui committed Dec 5, 2024
1 parent 8a35def commit b006f4b
Show file tree
Hide file tree
Showing 7 changed files with 8 additions and 130 deletions.
23 changes: 1 addition & 22 deletions go/vt/mysqlctl/azblobbackupstorage/azblob.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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 {
Expand Down
21 changes: 1 addition & 20 deletions go/vt/mysqlctl/cephbackupstorage/ceph.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
22 changes: 1 addition & 21 deletions go/vt/mysqlctl/fakebackupstorage.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ type FakeBackupHandle struct {
Dir string
NameV string
ReadOnly bool
Errors errorsbackup.PerFileErrorRecorder
errorsbackup.PerFileErrorRecorder

AbortBackupCalls []context.Context
AbortBackupReturn error
Expand Down Expand Up @@ -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
}
Expand Down
23 changes: 1 addition & 22 deletions go/vt/mysqlctl/filebackupstorage/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ type FileBackupHandle struct {
dir string
name string
readOnly bool
errors errorsbackup.PerFileErrorRecorder
errorsbackup.PerFileErrorRecorder
}

func NewBackupHandle(
Expand All @@ -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
Expand Down
21 changes: 1 addition & 20 deletions go/vt/mysqlctl/gcsbackupstorage/gcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
25 changes: 1 addition & 24 deletions go/vt/mysqlctl/s3backupstorage/s3.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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 {
Expand Down
3 changes: 2 additions & 1 deletion go/vt/mysqlctl/s3backupstorage/s3_mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit b006f4b

Please sign in to comment.