-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
select backup engine in Backup() and ignore engines in RestoreFromBackup() #16428
Merged
Merged
Changes from 19 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
675922a
allow backup engine to be specified on Backup() API
rvrangel b4fb33d
add test for the --ignored-backup-engines flag
rvrangel b2b83f5
Merge branch 'master' into select-backup-engine
rvrangel 1369c4a
fixing tests
rvrangel 5f12132
Merge branch 'master' into select-backup-engine
rvrangel 2738f7f
installed xtrabackup for additional tests
rvrangel a73bf44
fix xtrabackup install
rvrangel a08b8e1
add vtctlbackup_sharded_clustertest_heavy to list that requires xtrab…
rvrangel f4f6451
fix unit test
rvrangel 4c70b4e
reset common args for each test
rvrangel 4613bf5
Merge branch 'master' into select-backup-engine
rvrangel 2f174cc
use allow list
rvrangel d4a53a9
improve tests
rvrangel 631bb65
moving tests to endtoend/backup/xtrabackup
rvrangel f3b9e83
Merge branch 'master' into select-backup-engine
rvrangel 41cd68e
fix tests
rvrangel c187e36
Merge branch 'master' into select-backup-engine
rvrangel b2a540e
fix mysqlshell engine
rvrangel ff3dc51
update test and flags
rvrangel a6dff4b
empty commit to kick CI
shlomi-noach File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -75,14 +75,7 @@ var ( | |
shardKsName = fmt.Sprintf("%s/%s", keyspaceName, shardName) | ||
dbCredentialFile string | ||
shardName = "0" | ||
commonTabletArg = []string{ | ||
"--vreplication_retry_delay", "1s", | ||
"--degraded_threshold", "5s", | ||
"--lock_tables_timeout", "5s", | ||
"--watch_replication_stream", | ||
"--enable_replication_reporter", | ||
"--serving_state_grace_period", "1s", | ||
} | ||
commonTabletArg = getDefaultCommonArgs() | ||
|
||
vtInsertTest = ` | ||
create table vt_insert_test ( | ||
|
@@ -1482,3 +1475,149 @@ func verifyTabletRestoreStats(t *testing.T, vars map[string]any) { | |
|
||
require.Contains(t, bd, "BackupStorage.File.File:Read") | ||
} | ||
|
||
func getDefaultCommonArgs() []string { | ||
return []string{ | ||
"--vreplication_retry_delay", "1s", | ||
"--degraded_threshold", "5s", | ||
"--lock_tables_timeout", "5s", | ||
"--watch_replication_stream", | ||
"--enable_replication_reporter", | ||
"--serving_state_grace_period", "1s", | ||
} | ||
} | ||
|
||
func setDefaultCommonArgs() { commonTabletArg = getDefaultCommonArgs() } | ||
|
||
// fetch the backup engine used on the last backup triggered by the end-to-end tests. | ||
func getBackupEngineOfLastBackup(t *testing.T) string { | ||
lastBackup := getLastBackup(t) | ||
|
||
manifest := readManifestFile(t, path.Join(localCluster.CurrentVTDATAROOT, "backups", keyspaceName, shardName, lastBackup)) | ||
|
||
return manifest.BackupMethod | ||
} | ||
|
||
func getLastBackup(t *testing.T) string { | ||
backups, err := localCluster.ListBackups(shardKsName) | ||
require.NoError(t, err) | ||
|
||
return backups[len(backups)-1] | ||
} | ||
|
||
func TestBackupEngineSelector(t *testing.T) { | ||
defer setDefaultCommonArgs() | ||
defer cluster.PanicHandler(t) | ||
|
||
// launch the custer with xtrabackup as the default engine | ||
code, err := LaunchCluster(XtraBackup, "xbstream", 0, &CompressionDetails{CompressorEngineName: "pgzip"}) | ||
require.Nilf(t, err, "setup failed with status code %d", code) | ||
|
||
defer TearDownCluster() | ||
|
||
localCluster.DisableVTOrcRecoveries(t) | ||
defer func() { | ||
localCluster.EnableVTOrcRecoveries(t) | ||
}() | ||
verifyInitialReplication(t) | ||
|
||
t.Run("backup with backup-engine=builtin", func(t *testing.T) { | ||
// first try to backup with an alternative engine (builtin) | ||
err = localCluster.VtctldClientProcess.ExecuteCommand("Backup", "--allow-primary", "--backup-engine=builtin", primary.Alias) | ||
require.NoError(t, err) | ||
engineUsed := getBackupEngineOfLastBackup(t) | ||
require.Equal(t, "builtin", engineUsed) | ||
}) | ||
|
||
t.Run("backup with backup-engine=xtrabackup", func(t *testing.T) { | ||
// then try to backup specifying the xtrabackup engine | ||
err = localCluster.VtctldClientProcess.ExecuteCommand("Backup", "--allow-primary", "--backup-engine=xtrabackup", primary.Alias) | ||
require.NoError(t, err) | ||
engineUsed := getBackupEngineOfLastBackup(t) | ||
require.Equal(t, "xtrabackup", engineUsed) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
}) | ||
|
||
t.Run("backup without specifying backup-engine", func(t *testing.T) { | ||
// check that by default we still use the xtrabackup engine if not specified | ||
err = localCluster.VtctldClientProcess.ExecuteCommand("Backup", "--allow-primary", primary.Alias) | ||
require.NoError(t, err) | ||
engineUsed := getBackupEngineOfLastBackup(t) | ||
require.Equal(t, "xtrabackup", engineUsed) | ||
}) | ||
} | ||
|
||
func TestRestoreAllowedBackupEngines(t *testing.T) { | ||
defer setDefaultCommonArgs() | ||
defer cluster.PanicHandler(t) | ||
|
||
backupMsg := "right after xtrabackup backup" | ||
|
||
cDetails := &CompressionDetails{CompressorEngineName: "pgzip"} | ||
|
||
// launch the custer with xtrabackup as the default engine | ||
code, err := LaunchCluster(XtraBackup, "xbstream", 0, cDetails) | ||
require.Nilf(t, err, "setup failed with status code %d", code) | ||
|
||
defer TearDownCluster() | ||
|
||
localCluster.DisableVTOrcRecoveries(t) | ||
defer func() { | ||
localCluster.EnableVTOrcRecoveries(t) | ||
}() | ||
verifyInitialReplication(t) | ||
|
||
t.Run("generate backups", func(t *testing.T) { | ||
// lets take two backups, each using a different backup engine | ||
err = localCluster.VtctldClientProcess.ExecuteCommand("Backup", "--allow-primary", "--backup-engine=builtin", primary.Alias) | ||
require.NoError(t, err) | ||
|
||
err = localCluster.VtctldClientProcess.ExecuteCommand("Backup", "--allow-primary", "--backup-engine=xtrabackup", primary.Alias) | ||
require.NoError(t, err) | ||
}) | ||
|
||
// insert more data on the primary | ||
_, err = primary.VttabletProcess.QueryTablet(fmt.Sprintf("insert into vt_insert_test (msg) values ('%s')", backupMsg), keyspaceName, true) | ||
require.NoError(t, err) | ||
|
||
t.Run("restore replica and verify data", func(t *testing.T) { | ||
// now bring up another replica, letting it restore from backup. | ||
restoreWaitForBackup(t, "replica", cDetails, true) | ||
err = replica2.VttabletProcess.WaitForTabletStatusesForTimeout([]string{"SERVING"}, timeout) | ||
require.NoError(t, err) | ||
|
||
// check the new replica has the data | ||
cluster.VerifyRowsInTablet(t, replica2, keyspaceName, 2) | ||
result, err := replica2.VttabletProcess.QueryTablet( | ||
fmt.Sprintf("select msg from vt_insert_test where msg='%s'", backupMsg), replica2.VttabletProcess.Keyspace, true) | ||
require.NoError(t, err) | ||
require.Equal(t, backupMsg, result.Named().Row().AsString("msg", "")) | ||
}) | ||
|
||
t.Run("test broken restore", func(t *testing.T) { | ||
// now lets break the last backup in the shard | ||
err = os.Remove(path.Join(localCluster.CurrentVTDATAROOT, | ||
"backups", keyspaceName, shardName, | ||
getLastBackup(t), "backup.xbstream.gz")) | ||
require.NoError(t, err) | ||
|
||
// and try to restore from it | ||
err = localCluster.VtctldClientProcess.ExecuteCommand("RestoreFromBackup", replica2.Alias) | ||
require.Error(t, err) // this should fail | ||
}) | ||
|
||
t.Run("test older working backup", func(t *testing.T) { | ||
// now we retry but with the first backup | ||
err = localCluster.VtctldClientProcess.ExecuteCommand("RestoreFromBackup", "--allowed-backup-engines=builtin", replica2.Alias) | ||
require.NoError(t, err) // this should succeed | ||
|
||
// make sure we are replicating after the restore is done | ||
err = replica2.VttabletProcess.WaitForTabletStatusesForTimeout([]string{"SERVING"}, timeout) | ||
require.NoError(t, err) | ||
cluster.VerifyRowsInTablet(t, replica2, keyspaceName, 2) | ||
|
||
result, err := replica2.VttabletProcess.QueryTablet( | ||
fmt.Sprintf("select msg from vt_insert_test where msg='%s'", backupMsg), replica2.VttabletProcess.Keyspace, true) | ||
require.NoError(t, err) | ||
require.Equal(t, backupMsg, result.Named().Row().AsString("msg", "")) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package vtctlbackup | ||
|
||
import ( | ||
"testing" | ||
|
||
backup "vitess.io/vitess/go/test/endtoend/backup/vtctlbackup" | ||
) | ||
|
||
func TestBackupEngineSelector(t *testing.T) { | ||
defer setDefaultCompressionFlag() | ||
backup.TestBackupEngineSelector(t) | ||
} | ||
|
||
func TestRestoreAllowedBackupEngines(t *testing.T) { | ||
defer setDefaultCompressionFlag() | ||
backup.TestRestoreAllowedBackupEngines(t) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍