Skip to content
Merged
Show file tree
Hide file tree
Changes from 45 commits
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
609f1d9
initial commit for backup_only
ajeetj Jan 10, 2020
a36ac69
changes in package structure
ajeetj Jan 10, 2020
b64271b
updating package name and fixing a test
ajeetj Jan 10, 2020
a8273a8
removed unrequired teardown code
ajeetj Jan 13, 2020
975645f
Removed debug code
ajeetj Jan 13, 2020
1563e63
inital commit for xtrabackup
ajeetj Jan 20, 2020
de23c53
fix sequencing of cleanup
ajeetj Jan 21, 2020
769d6f7
fix terminate restore for xtrabackup
ajeetj Jan 21, 2020
621c848
updated config for xtrabackup
ajeetj Jan 21, 2020
cad5498
backup-mysqlctld: mysqlctld setup module created.
princeparmar Jan 21, 2020
d556aa3
added xtrabackup stream mode
ajeetj Jan 21, 2020
7cd55aa
updated config for xtrabackup stream
ajeetj Jan 21, 2020
502cacb
minor changes to config
ajeetj Jan 21, 2020
bdbc989
initial commit for backup_only
ajeetj Jan 10, 2020
ed44822
changes in package structure
ajeetj Jan 10, 2020
366fe54
updating package name and fixing a test
ajeetj Jan 10, 2020
f887be3
removed unrequired teardown code
ajeetj Jan 13, 2020
29569e8
Removed debug code
ajeetj Jan 13, 2020
833cd08
inital commit for xtrabackup
ajeetj Jan 20, 2020
7e9f837
fix sequencing of cleanup
ajeetj Jan 21, 2020
815b693
fix terminate restore for xtrabackup
ajeetj Jan 21, 2020
61fe132
updated config for xtrabackup
ajeetj Jan 21, 2020
a334d24
added xtrabackup stream mode
ajeetj Jan 21, 2020
d68b6c4
updated config for xtrabackup stream
ajeetj Jan 21, 2020
e10dbdb
minor changes to config
ajeetj Jan 21, 2020
c1e8706
rebased to resolve conflict
arindamnayak Jan 22, 2020
4acd21e
backup-mysqlctld: mysqlctld health check changes.
princeparmar Jan 22, 2020
480d111
Merge branch 'xtrabackup' into backup-mysqlctld
princeparmar Jan 22, 2020
640bc64
backup_mysqlctld: mysqlctld teardown fixes. vttablet restart method c…
princeparmar Jan 23, 2020
1a99489
backup-mysqlctld: mysqlctld restart fixed, backup utils refactor.
princeparmar Jan 24, 2020
650f834
Merge branch 'xtrabackup' into backup-mysqlctld
princeparmar Jan 24, 2020
5287826
backup_transform_mysqlctld: backup_transform testing using mysqlctld.
princeparmar Jan 24, 2020
8df329b
merged with upstream master
ajeetj Jan 29, 2020
6266aa3
Added percona 56 new dependency
ajeetj Jan 29, 2020
c57774e
Putting the dependency at right place
ajeetj Jan 29, 2020
65ea31a
updated apt tp apt-get
ajeetj Jan 29, 2020
dee9222
corrected the typo
ajeetj Jan 29, 2020
af3c7f4
fixed a comma in config.json
ajeetj Jan 29, 2020
43c9b16
Merge remote-tracking branch 'origin/xtrabackup' into backup-mysqlctld
princeparmar Jan 30, 2020
8a4b2a8
review changes.
princeparmar Jan 30, 2020
21b5923
Merge branch 'backup-mysqlctld' into backup-transform-mysqlctld
princeparmar Jan 30, 2020
005b88f
Merge branch 'master' of https://github.com/vitessio/vitess into back…
princeparmar Jan 30, 2020
bf19133
test added in config.
princeparmar Jan 30, 2020
e5f0a19
package name changed.
princeparmar Jan 30, 2020
ae6970b
mysql_ctld: file name change.
princeparmar Jan 30, 2020
baca2f8
mysqlctld: review changes,
princeparmar Jan 30, 2020
dbed929
backup_transform: refator.
princeparmar Jan 31, 2020
ac01391
backup_mysqlctld: config changes.
princeparmar Jan 31, 2020
49189be
restore vtBackup test
ajeetj Jan 31, 2020
a16bdeb
Merge branch 'backup-transform-mysqlctld' of github.com:planetscale/v…
ajeetj Jan 31, 2020
05ea4d4
redistribute travis tests
ajeetj Jan 31, 2020
4ef2a1f
updated shard matrix for transform test
ajeetj Jan 31, 2020
f8c103d
mysqlctld: mysqlctld teardown issue resolved.
princeparmar Jan 31, 2020
4fa21f5
mysqlctld: mysqlctld teardown issue resolved.
princeparmar Jan 31, 2020
0601bf8
Merge branch 'backup-transform-mysqlctld' of https://github.com/plane…
princeparmar Jan 31, 2020
db14fc2
Merge branch 'backup-transform-mysqlctld' of https://github.com/plane…
princeparmar Jan 31, 2020
346d66e
Merge branch 'backup-transform-mysqlctld' of https://github.com/plane…
princeparmar Feb 4, 2020
12a4a73
Merge branch 'backup-transform-mysqlctld' of https://github.com/plane…
princeparmar Feb 4, 2020
c2d3538
Merge branch 'backup-transform-mysqlctld' of https://github.com/plane…
princeparmar Feb 5, 2020
3b1e455
mysql-ctld: process teardown changes.
princeparmar Feb 6, 2020
6700a4f
review changes and newConnection method modified.
princeparmar Feb 6, 2020
e17988d
mysqlctld: process hang issue resolved.
princeparmar Feb 6, 2020
202d66e
Merge branch 'master' into backup-transform-mysqlctld
deepthi Feb 7, 2020
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
28 changes: 28 additions & 0 deletions go/test/endtoend/backup/backupmysqlctld/backup_mysqlctld_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
Copyright 2019 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 backupmysqlctld

import (
"testing"

backup "vitess.io/vitess/go/test/endtoend/backup/vtctlbackup"
)

// TestBackupMysqlctld - tests the backup using mysqlctld.
func TestBackupMysqlctld(t *testing.T) {
backup.TestBackup(t, backup.Mysqlctld, "", 0)
}
29 changes: 2 additions & 27 deletions go/test/endtoend/backup/vtbackup/backup_only_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ func restore(t *testing.T, tablet *cluster.Vttablet, tabletType string, waitForS
// Erase mysql/tablet dir, then start tablet with restore enabled.

log.Info("restoring tablet %s", time.Now())
resetTabletDirectory(t, *tablet, true)
tablet.ValidateTabletRestart(t)

err := tablet.VttabletProcess.CreateDB(keyspaceName)
assert.Nil(t, err)
Expand All @@ -251,31 +251,6 @@ func restore(t *testing.T, tablet *cluster.Vttablet, tabletType string, waitForS
assert.Nil(t, err)
}

func resetTabletDirectory(t *testing.T, tablet cluster.Vttablet, initMysql bool) {

extraArgs := []string{"-db-credentials-file", dbCredentialFile}
tablet.MysqlctlProcess.ExtraArgs = extraArgs

// Shutdown Mysql
err := tablet.MysqlctlProcess.Stop()
assert.Nil(t, err)
// Teardown Tablet
err = tablet.VttabletProcess.TearDown()
assert.Nil(t, err)

// Empty the dir
err = os.RemoveAll(tablet.VttabletProcess.Directory)
assert.Nil(t, err)

if initMysql {
// Init the Mysql
tablet.MysqlctlProcess.InitDBFile = newInitDBFile
err = tablet.MysqlctlProcess.Start()
assert.Nil(t, err)
}

}

Comment thread
princeparmar marked this conversation as resolved.
func tearDown(t *testing.T, initMysql bool) {
// reset replication
promoteSlaveCommands := "STOP SLAVE; RESET SLAVE ALL; RESET MASTER;"
Expand All @@ -300,6 +275,6 @@ func tearDown(t *testing.T, initMysql bool) {
err := localCluster.VtctlclientProcess.ExecuteCommand("DeleteTablet", "-allow_master", tablet.Alias)
assert.Nil(t, err)

resetTabletDirectory(t, tablet, initMysql)
tablet.ValidateTabletRestart(t)
}
}
15 changes: 4 additions & 11 deletions go/test/endtoend/backup/vtctlbackup/backup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,11 @@ limitations under the License.

package vtctlbackup

import "testing"
import (
"testing"
)

// TestBackupMain - main tests backup using vtctl commands
func TestBackupMain(t *testing.T) {
code, err := LaunchCluster(false, "", 0)
if err != nil {
t.Errorf("setup failed with status code %d", code)
}

// Run all the backup tests
TestBackup(t)

// Teardown the cluster
TearDownCluster()
TestBackup(t, Backup, "", 0)
}
166 changes: 99 additions & 67 deletions go/test/endtoend/backup/vtctlbackup/backup_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,23 @@ import (
"vitess.io/vitess/go/vt/proto/topodata"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"vitess.io/vitess/go/test/endtoend/cluster"
)

const (
ExtraBackup = iota
Backup
Mysqlctld
)

var (
master *cluster.Vttablet
replica1 *cluster.Vttablet
replica2 *cluster.Vttablet
localCluster *cluster.LocalProcessCluster
newInitDBFile string
useXtrabackup bool
xbStreamMode string
xbStripes int
cell = cluster.DefaultCell
hostname = "localhost"
keyspaceName = "ks"
Expand All @@ -72,7 +77,8 @@ var (
) Engine=InnoDB`
)

func LaunchCluster(xtrabackup bool, streamMode string, stripes int) (int, error) {
// LaunchCluster :

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

need to add some comment

func LaunchCluster(setupType int, streamMode string, stripes int) (int, error) {
localCluster = cluster.NewCluster(cell, hostname)

// Start topo server
Expand Down Expand Up @@ -101,16 +107,14 @@ func LaunchCluster(xtrabackup bool, streamMode string, stripes int) (int, error)
commonTabletArg = append(commonTabletArg, "-db-credentials-file", dbCredentialFile)

// Update arguments for xtrabackup
if xtrabackup {
useXtrabackup = xtrabackup
xbStreamMode = streamMode
xbStripes = stripes
if setupType == ExtraBackup {
useXtrabackup = true

xtrabackupArgs := []string{
"-backup_engine_implementation", "xtrabackup",
fmt.Sprintf("-xtrabackup_stream_mode=%s", xbStreamMode),
fmt.Sprintf("-xtrabackup_stream_mode=%s", streamMode),
"-xtrabackup_user=vt_dba",
fmt.Sprintf("-xtrabackup_stripes=%d", xbStripes),
fmt.Sprintf("-xtrabackup_stripes=%d", stripes),
"-xtrabackup_backup_flags", fmt.Sprintf("--password=%s", dbPassword),
}

Expand All @@ -134,14 +138,27 @@ func LaunchCluster(xtrabackup bool, streamMode string, stripes int) (int, error)
tablet.VttabletProcess.SupportsBackup = true
tablet.VttabletProcess.EnableSemiSync = true

if setupType == Mysqlctld {
tablet.MysqlctldProcess = *cluster.MysqlCtldProcessInstance(tablet.TabletUID, tablet.MySQLPort, localCluster.TmpDirectory)
tablet.MysqlctldProcess.InitDBFile = newInitDBFile
tablet.MysqlctldProcess.ExtraArgs = extraArgs
tablet.MysqlctldProcess.Password = tablet.VttabletProcess.DbPassword
if err := tablet.MysqlctldProcess.Start(); err != nil {
return 1, err
}
shard.Vttablets = append(shard.Vttablets, tablet)
continue
}

Comment thread
princeparmar marked this conversation as resolved.
tablet.MysqlctlProcess = *cluster.MysqlCtlProcessInstance(tablet.TabletUID, tablet.MySQLPort, localCluster.TmpDirectory)
tablet.MysqlctlProcess.InitDBFile = newInitDBFile
tablet.MysqlctlProcess.ExtraArgs = extraArgs
if proc, err := tablet.MysqlctlProcess.StartProcess(); err != nil {
proc, err := tablet.MysqlctlProcess.StartProcess()
if err != nil {
return 1, err
} else {
mysqlProcs = append(mysqlProcs, proc)
}
mysqlProcs = append(mysqlProcs, proc)

shard.Vttablets = append(shard.Vttablets, tablet)
}
for _, proc := range mysqlProcs {
Expand Down Expand Up @@ -179,35 +196,60 @@ func TearDownCluster() {
localCluster.Teardown()
}

func TestBackup(t *testing.T) {
// Run all the backup tests
t.Run("TestReplicaBackup", func(t *testing.T) {
vtctlBackup(t, "replica")
})

t.Run("TestRdonlyBackup", func(t *testing.T) {
vtctlBackup(t, "rdonly")
})

t.Run("TestMasterBackup", func(t *testing.T) {
masterBackup(t)
})
func TestBackup(t *testing.T, setupType int, streamMode string, stripes int) {

testMethods := []struct {
name string
method func(t *testing.T)
}{
{
name: "TestReplicaBackup",
method: func(t *testing.T) {
vtctlBackup(t, "replica")
},
}, //
{
name: "TestRdonlyBackup",
method: func(t *testing.T) {
vtctlBackup(t, "rdonly")
},
}, //
{
name: "TestMasterBackup",
method: masterBackup,
}, //
{
name: "TestMasterReplicaSameBackup",
method: masterReplicaSameBackup,
}, //
{
name: "TestRestoreOldMasterByRestart",
method: restoreOldMasterByRestart,
}, //
{
name: "TestRestoreOldMasterInPlace",
method: restoreOldMasterInPlace,
}, //
{
name: "TestTerminatedRestore",
method: terminatedRestore,
}, //
}

t.Run("TestMasterReplicaSameBackup", func(t *testing.T) {
masterReplicaSameBackup(t)
})
// setup cluster for the testing
code, err := LaunchCluster(setupType, streamMode, stripes)
require.Nilf(t, err, "setup failed with status code %d", code)

t.Run("TestRestoreOldMasterByRestart", func(t *testing.T) {
restoreOldMasterByRestart(t)
})
// Teardown the cluster
defer TearDownCluster()

t.Run("TestRestoreOldMasterInPlace", func(t *testing.T) {
restoreOldMasterInPlace(t)
})
// Run all the backup tests

t.Run("TestTerminatedRestore", func(t *testing.T) {
terminatedRestore(t)
})
for _, test := range testMethods {
fmt.Printf("test %v started \n", test.name)
pass := t.Run(test.name, test.method)
fmt.Printf("test %v completed, isPass %v\n", test.name, pass)
Comment thread
princeparmar marked this conversation as resolved.
Outdated
}

}

Expand All @@ -228,14 +270,12 @@ func masterBackup(t *testing.T) {
assert.NotNil(t, err)
assert.Contains(t, output, "type MASTER cannot take backup. if you really need to do this, rerun the backup command with -allow_master")

backups := listBackups(t)
assert.Equal(t, len(backups), 0)
localCluster.VerifyBackupCount(t, shardKsName, 0)

err = localCluster.VtctlclientProcess.ExecuteCommand("Backup", "-allow_master=true", master.Alias)
assert.Nil(t, err)

backups = listBackups(t)
assert.Equal(t, len(backups), 1)
backups := localCluster.VerifyBackupCount(t, shardKsName, 1)
assert.Contains(t, backups[0], master.Alias)

_, err = master.VttabletProcess.QueryTablet("insert into vt_insert_test (msg) values ('test2')", keyspaceName, true)
Expand Down Expand Up @@ -383,14 +423,15 @@ func restartMasterReplica(t *testing.T) {
stopAllTablets()

// remove all backups
backups := listBackups(t)
for _, backup := range backups {
err := localCluster.VtctlclientProcess.ExecuteCommand("RemoveBackup", shardKsName, backup)
assert.Nil(t, err)
}
localCluster.RemoveAllBackups(t, shardKsName)
// start all tablet and mysql instances
var mysqlProcs []*exec.Cmd
for _, tablet := range []*cluster.Vttablet{master, replica1} {
for _, tablet := range []*cluster.Vttablet{master, replica1, replica2} {
if tablet.MysqlctldProcess.TabletUID > 0 {
err := tablet.MysqlctldProcess.Start()
require.Nilf(t, err, "error while starting mysqlctld, tabletUID %v", tablet.TabletUID)
continue
}
proc, _ := tablet.MysqlctlProcess.StartProcess()
mysqlProcs = append(mysqlProcs, proc)
}
Expand All @@ -413,6 +454,11 @@ func stopAllTablets() {
var mysqlProcs []*exec.Cmd
for _, tablet := range []*cluster.Vttablet{master, replica1, replica2} {
tablet.VttabletProcess.TearDown()
if tablet.MysqlctldProcess.TabletUID > 0 {
tablet.MysqlctldProcess.Stop()
localCluster.VtctlclientProcess.ExecuteCommand("DeleteTablet", "-allow_master", tablet.Alias)
continue
}
Comment thread
princeparmar marked this conversation as resolved.
proc, _ := tablet.MysqlctlProcess.StopProcess()
mysqlProcs = append(mysqlProcs, proc)
localCluster.VtctlclientProcess.ExecuteCommand("DeleteTablet", "-allow_master", tablet.Alias)
Expand Down Expand Up @@ -489,8 +535,7 @@ func vtctlBackup(t *testing.T, tabletType string) {
err := localCluster.VtctlclientProcess.ExecuteCommand("Backup", replica1.Alias)
assert.Nil(t, err)

backups := listBackups(t)
assert.Equal(t, len(backups), 1)
backups := localCluster.VerifyBackupCount(t, shardKsName, 1)

_, err = master.VttabletProcess.QueryTablet("insert into vt_insert_test (msg) values ('test2')", keyspaceName, true)
assert.Nil(t, err)
Expand Down Expand Up @@ -529,7 +574,7 @@ func verifyInitialReplication(t *testing.T) {
// to restore a previous backup successfully regardless of this setting.
func restoreWaitForBackup(t *testing.T, tabletType string) {
replica2.Type = tabletType
resetTabletDir(t, replica2)
replica2.ValidateTabletRestart(t)
replicaTabletArgs := commonTabletArg
replicaTabletArgs = append(replicaTabletArgs, "-backup_engine_implementation", "fake_implementation")
replicaTabletArgs = append(replicaTabletArgs, "-wait_for_backup_interval", "1s")
Expand All @@ -540,17 +585,6 @@ func restoreWaitForBackup(t *testing.T, tabletType string) {
assert.Nil(t, err)
}

func resetTabletDir(t *testing.T, tablet *cluster.Vttablet) {
err := cluster.ResetTabletDirectory(*tablet)
assert.Nil(t, err)
}

func listBackups(t *testing.T) []string {
output, err := localCluster.ListBackups(shardKsName)
assert.Nil(t, err)
return output
}

func verifyAfterRemovingBackupNoBackupShouldBePresent(t *testing.T, backups []string) {
// Remove the backup
for _, backup := range backups {
Expand All @@ -559,17 +593,14 @@ func verifyAfterRemovingBackupNoBackupShouldBePresent(t *testing.T, backups []st
}

// Now, there should not be no backup
backups = listBackups(t)
assert.Equal(t, len(backups), 0)
localCluster.VerifyBackupCount(t, shardKsName, 0)
}

func verifyRestoreTablet(t *testing.T, tablet *cluster.Vttablet, status string) {
err := tablet.VttabletProcess.TearDown()
assert.Nil(t, err)

resetTabletDir(t, tablet)
tablet.ValidateTabletRestart(t)
tablet.VttabletProcess.ServingStatus = ""
err = tablet.VttabletProcess.Setup()
err := tablet.VttabletProcess.Setup()
assert.Nil(t, err)
if status != "" {
err = tablet.VttabletProcess.WaitForTabletTypesForTimeout([]string{status}, 25*time.Second)
Expand All @@ -596,6 +627,7 @@ func terminateRestore(t *testing.T) {
stopRestoreMsg := "Copying file 10"
if useXtrabackup {
stopRestoreMsg = "Restore: Preparing"
useXtrabackup = false
}

args := append([]string{"-server", localCluster.VtctlclientProcess.Server, "-alsologtostderr"}, "RestoreFromBackup", master.Alias)
Expand Down
Loading