Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
3 changes: 2 additions & 1 deletion go/vt/mysqlctl/backupengine.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (
"vitess.io/vitess/go/vt/logutil"
"vitess.io/vitess/go/vt/mysqlctl/backupstats"
"vitess.io/vitess/go/vt/mysqlctl/backupstorage"
tabletmanagerdatapb "vitess.io/vitess/go/vt/proto/tabletmanagerdata"
"vitess.io/vitess/go/vt/proto/vtrpc"
"vitess.io/vitess/go/vt/servenv"
"vitess.io/vitess/go/vt/topo"
Expand All @@ -46,7 +47,7 @@ var (
// BackupEngine is the interface to take a backup with a given engine.
type BackupEngine interface {
ExecuteBackup(ctx context.Context, params BackupParams, bh backupstorage.BackupHandle) (bool, error)
ShouldDrainForBackup() bool
ShouldDrainForBackup(req *tabletmanagerdatapb.BackupRequest) bool
}

// BackupParams is the struct that holds all params passed to ExecuteBackup
Expand Down
7 changes: 6 additions & 1 deletion go/vt/mysqlctl/builtinbackupengine.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import (
"vitess.io/vitess/go/vt/logutil"
stats "vitess.io/vitess/go/vt/mysqlctl/backupstats"
"vitess.io/vitess/go/vt/mysqlctl/backupstorage"
tabletmanagerdatapb "vitess.io/vitess/go/vt/proto/tabletmanagerdata"
"vitess.io/vitess/go/vt/proto/vtrpc"
"vitess.io/vitess/go/vt/servenv"
"vitess.io/vitess/go/vt/topo"
Expand Down Expand Up @@ -1080,7 +1081,11 @@ func (be *BuiltinBackupEngine) restoreFile(ctx context.Context, params RestorePa

// ShouldDrainForBackup satisfies the BackupEngine interface
// backup requires query service to be stopped, hence true
func (be *BuiltinBackupEngine) ShouldDrainForBackup() bool {
func (be *BuiltinBackupEngine) ShouldDrainForBackup(req *tabletmanagerdatapb.BackupRequest) bool {
if req != nil && req.IncrementalFromPos != "" {
// Incremental backup: we do not drain the tablet.
return false
}
return true
}

Expand Down
35 changes: 35 additions & 0 deletions go/vt/mysqlctl/builtinbackupengine2_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
Copyright 2023 The Vitess Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

// Package mysqlctl_test is the blackbox tests for package mysqlctl.
package mysqlctl

import (
"testing"

"github.com/stretchr/testify/assert"

tabletmanagerdatapb "vitess.io/vitess/go/vt/proto/tabletmanagerdata"
)

func TestShouldDrainForBackupBuiltIn(t *testing.T) {
be := &BuiltinBackupEngine{}

assert.True(t, be.ShouldDrainForBackup(&tabletmanagerdatapb.BackupRequest{}))
assert.False(t, be.ShouldDrainForBackup(&tabletmanagerdatapb.BackupRequest{IncrementalFromPos: "auto"}))
assert.False(t, be.ShouldDrainForBackup(&tabletmanagerdatapb.BackupRequest{IncrementalFromPos: "99ca8ed4-399c-11ee-861b-0a43f95f28a3:1-197"}))
assert.False(t, be.ShouldDrainForBackup(&tabletmanagerdatapb.BackupRequest{IncrementalFromPos: "MySQL56/99ca8ed4-399c-11ee-861b-0a43f95f28a3:1-197"}))
}
3 changes: 2 additions & 1 deletion go/vt/mysqlctl/fakebackupengine.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"time"

"vitess.io/vitess/go/vt/mysqlctl/backupstorage"
tabletmanagerdatapb "vitess.io/vitess/go/vt/proto/tabletmanagerdata"
)

type FakeBackupEngine struct {
Expand Down Expand Up @@ -86,7 +87,7 @@ func (be *FakeBackupEngine) ExecuteRestore(
return be.ExecuteRestoreReturn.Manifest, be.ExecuteRestoreReturn.Err
}

func (be *FakeBackupEngine) ShouldDrainForBackup() bool {
func (be *FakeBackupEngine) ShouldDrainForBackup(req *tabletmanagerdatapb.BackupRequest) bool {
be.ShouldDrainForBackupCalls = be.ShouldDrainForBackupCalls + 1
return be.ShouldDrainForBackupReturn
}
3 changes: 2 additions & 1 deletion go/vt/mysqlctl/xtrabackupengine.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import (
"vitess.io/vitess/go/mysql"
"vitess.io/vitess/go/vt/logutil"
"vitess.io/vitess/go/vt/mysqlctl/backupstorage"
tabletmanagerdatapb "vitess.io/vitess/go/vt/proto/tabletmanagerdata"
"vitess.io/vitess/go/vt/proto/vtrpc"
"vitess.io/vitess/go/vt/servenv"
"vitess.io/vitess/go/vt/vterrors"
Expand Down Expand Up @@ -944,7 +945,7 @@ func stripeReader(readers []io.Reader, blockSize int64) io.Reader {

// ShouldDrainForBackup satisfies the BackupEngine interface
// xtrabackup can run while tablet is serving, hence false
func (be *XtrabackupEngine) ShouldDrainForBackup() bool {
func (be *XtrabackupEngine) ShouldDrainForBackup(req *tabletmanagerdatapb.BackupRequest) bool {
return false
}

Expand Down
10 changes: 10 additions & 0 deletions go/vt/mysqlctl/xtrabackupengine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ import (
"math/rand"
"testing"

"github.com/stretchr/testify/assert"

"vitess.io/vitess/go/vt/logutil"
tabletmanagerdatapb "vitess.io/vitess/go/vt/proto/tabletmanagerdata"
)

func TestFindReplicationPosition(t *testing.T) {
Expand Down Expand Up @@ -115,3 +118,10 @@ func TestStripeRoundTrip(t *testing.T) {
// Test block size and stripe count that don't evenly divide data size.
test(6000, 7)
}

func TestShouldDrainForBackupXtrabackup(t *testing.T) {
be := &XtrabackupEngine{}

assert.False(t, be.ShouldDrainForBackup(nil))
assert.False(t, be.ShouldDrainForBackup(&tabletmanagerdatapb.BackupRequest{}))
}
4 changes: 2 additions & 2 deletions go/vt/vttablet/tabletmanager/rpc_backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func (tm *TabletManager) Backup(ctx context.Context, logger logutil.Logger, req

// Prevent concurrent backups, and record stats
backupMode := backupModeOnline
if engine.ShouldDrainForBackup() {
if engine.ShouldDrainForBackup(req) {
backupMode = backupModeOffline
}
if err := tm.beginBackup(backupMode); err != nil {
Expand All @@ -80,7 +80,7 @@ func (tm *TabletManager) Backup(ctx context.Context, logger logutil.Logger, req
l := logutil.NewTeeLogger(logutil.NewConsoleLogger(), logger)

var originalType topodatapb.TabletType
if engine.ShouldDrainForBackup() {
if engine.ShouldDrainForBackup(req) {
if err := tm.lock(ctx); err != nil {
return err
}
Expand Down