Skip to content

Commit

Permalink
Do not drain tablet in incremental backup (#13773)
Browse files Browse the repository at this point in the history
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
  • Loading branch information
shlomi-noach authored Aug 15, 2023
1 parent 1659386 commit 16024c2
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 10 deletions.
6 changes: 3 additions & 3 deletions go/vt/mysqlctl/backupengine.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ import (

"github.com/spf13/pflag"

"vitess.io/vitess/go/mysql/replication"

"vitess.io/vitess/go/mysql"
"vitess.io/vitess/go/mysql/replication"
"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 @@ -48,7 +48,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
10 changes: 7 additions & 3 deletions go/vt/mysqlctl/builtinbackupengine.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,17 @@ import (
"github.com/spf13/pflag"
"golang.org/x/sync/semaphore"

"vitess.io/vitess/go/mysql/replication"

"vitess.io/vitess/go/ioutil"
"vitess.io/vitess/go/mysql"
"vitess.io/vitess/go/mysql/replication"
"vitess.io/vitess/go/vt/concurrency"
"vitess.io/vitess/go/vt/log"
"vitess.io/vitess/go/vt/logutil"
stats "vitess.io/vitess/go/vt/mysqlctl/backupstats"
"vitess.io/vitess/go/vt/mysqlctl/backupstorage"
"vitess.io/vitess/go/vt/proto/mysqlctl"
mysqlctlpb "vitess.io/vitess/go/vt/proto/mysqlctl"
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 @@ -1149,7 +1149,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
11 changes: 11 additions & 0 deletions go/vt/mysqlctl/builtinbackupengine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import (
"testing"

"github.com/stretchr/testify/assert"

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

func TestGetIncrementalFromPosGTIDSet(t *testing.T) {
Expand Down Expand Up @@ -67,3 +69,12 @@ func TestGetIncrementalFromPosGTIDSet(t *testing.T) {
})
}
}

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 @@ -36,6 +36,7 @@ import (
"vitess.io/vitess/go/mysql/replication"
"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 @@ -950,7 +951,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

0 comments on commit 16024c2

Please sign in to comment.