Skip to content

Commit

Permalink
Merge pull request #586 from rvrangel/mysql-shell-engine
Browse files Browse the repository at this point in the history
add mysql-shell engine as a supported engine
  • Loading branch information
frouioui authored Sep 24, 2024
2 parents f36568a + 134463b commit bff6251
Show file tree
Hide file tree
Showing 10 changed files with 30 additions and 5 deletions.
1 change: 1 addition & 0 deletions deploy/crds/planetscale.com_vitessclusters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ spec:
enum:
- builtin
- xtrabackup
- mysqlshell
type: string
locations:
items:
Expand Down
4 changes: 3 additions & 1 deletion pkg/apis/planetscale/v2/vitesscluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ type ClusterBackupSpec struct {
// from one tablet in each shard. Otherwise, new tablets trying to restore
// will find that the latest backup was created with the wrong engine.
// Default: builtin
// +kubebuilder:validation:Enum=builtin;xtrabackup
// +kubebuilder:validation:Enum=builtin;xtrabackup;mysqlshell
Engine VitessBackupEngine `json:"engine,omitempty"`
// Subcontroller specifies any parameters needed for launching the VitessBackupStorage subcontroller pod.
Subcontroller *VitessBackupSubcontrollerSpec `json:"subcontroller,omitempty"`
Expand All @@ -337,6 +337,8 @@ const (
VitessBackupEngineBuiltIn VitessBackupEngine = "builtin"
// VitessBackupEngineXtraBackup uses Percona XtraBackup for backups.
VitessBackupEngineXtraBackup VitessBackupEngine = "xtrabackup"
// VitessBackupEngineMySQLShell uses MySQL Shell for backups.
VitessBackupEngineMySQLShell VitessBackupEngine = "mysqlshell"
)

// LockserverSpec specifies either a deployed or external lockserver,
Expand Down
21 changes: 17 additions & 4 deletions pkg/operator/vttablet/backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
"planetscale.dev/vitess-operator/pkg/operator/vitessbackup"
)

func xtrabackupFlags(spec *Spec, backupThreads, restoreThreads int) vitess.Flags {
func xtrabackupFlags(backupThreads, restoreThreads int) vitess.Flags {
flags := vitess.Flags{
"xtrabackup_user": xtrabackupUser,
"xtrabackup_stream_mode": xtrabackupStreamMode,
Expand All @@ -39,6 +39,15 @@ func xtrabackupFlags(spec *Spec, backupThreads, restoreThreads int) vitess.Flags
return flags
}

func mysqlshellFlags(backupLocation string) vitess.Flags {
flags := vitess.Flags{
"mysql-shell-backup-location": backupLocation,
"mysql-shell-flags": mysqlshellExtraFlags,
}

return flags
}

func init() {
vttabletFlags.Add(func(s lazy.Spec) vitess.Flags {
spec := s.(*Spec)
Expand All @@ -51,7 +60,8 @@ func init() {
"wait_for_backup_interval": waitForBackupInterval,
"backup_engine_implementation": string(spec.BackupEngine),
}
if spec.BackupEngine == planetscalev2.VitessBackupEngineXtraBackup {
switch spec.BackupEngine {
case planetscalev2.VitessBackupEngineXtraBackup:
// When vttablets take backups, we let them keep serving, so we
// limit to single-threaded to reduce the impact.
backupThreads := 1
Expand All @@ -67,7 +77,10 @@ func init() {
if restoreThreads < 1 {
restoreThreads = 1
}
flags.Merge(xtrabackupFlags(spec, backupThreads, restoreThreads))
flags.Merge(xtrabackupFlags(backupThreads, restoreThreads))
case planetscalev2.VitessBackupEngineMySQLShell:
svm := vitessbackup.StorageVolumeMounts(spec.BackupLocation)
flags.Merge(mysqlshellFlags(svm[0].MountPath))
}
clusterName := spec.Labels[planetscalev2.ClusterLabel]
storageLocationFlags := vitessbackup.StorageFlags(spec.BackupLocation, clusterName)
Expand All @@ -93,7 +106,7 @@ func init() {
if threads < 1 {
threads = 1
}
flags.Merge(xtrabackupFlags(spec, threads, threads))
flags.Merge(xtrabackupFlags(threads, threads))
}
clusterName := spec.Labels[planetscalev2.ClusterLabel]
storageLocationFlags := vitessbackup.StorageFlags(spec.BackupLocation, clusterName)
Expand Down
3 changes: 3 additions & 0 deletions pkg/operator/vttablet/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@ const (
xtrabackupStripeCount = 8
xtrabackupUser = "vt_dba"

mysqlshellUser = "vt_dba"
mysqlshellExtraFlags = "--defaults-file=/dev/null --no-password --js -u " + mysqlshellUser + " -S " + mysqlSocketPath

// mysqlctlWaitTime is how long mysqlctld will wait for mysqld to start up
// before assuming it's stuck and trying to restart it. We set this fairly
// high because it can take a while to do crash recovery and it's rarely
Expand Down
1 change: 1 addition & 0 deletions test/endtoend/operator/101_initial_cluster.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ stringData:
CREATE USER 'vt_dba'@'localhost';
GRANT ALL ON *.* TO 'vt_dba'@'localhost';
GRANT GRANT OPTION ON *.* TO 'vt_dba'@'localhost';
GRANT PROXY ON ''@'' TO 'vt_dba'@'localhost' WITH GRANT OPTION;
# User for app traffic, with global read-write access.
CREATE USER 'vt_app'@'localhost';
Expand Down
1 change: 1 addition & 0 deletions test/endtoend/operator/101_initial_cluster_backup.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ stringData:
CREATE USER 'vt_dba'@'localhost';
GRANT ALL ON *.* TO 'vt_dba'@'localhost';
GRANT GRANT OPTION ON *.* TO 'vt_dba'@'localhost';
GRANT PROXY ON ''@'' TO 'vt_dba'@'localhost' WITH GRANT OPTION;
# User for app traffic, with global read-write access.
CREATE USER 'vt_app'@'localhost';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ stringData:
CREATE USER 'vt_dba'@'localhost';
GRANT ALL ON *.* TO 'vt_dba'@'localhost';
GRANT GRANT OPTION ON *.* TO 'vt_dba'@'localhost';
GRANT PROXY ON ''@'' TO 'vt_dba'@'localhost' WITH GRANT OPTION;
# User for app traffic, with global read-write access.
CREATE USER 'vt_app'@'localhost';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ stringData:
CREATE USER 'vt_dba'@'localhost';
GRANT ALL ON *.* TO 'vt_dba'@'localhost';
GRANT GRANT OPTION ON *.* TO 'vt_dba'@'localhost';
GRANT PROXY ON ''@'' TO 'vt_dba'@'localhost' WITH GRANT OPTION;
# User for app traffic, with global read-write access.
CREATE USER 'vt_app'@'localhost';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ stringData:
CREATE USER 'vt_dba'@'localhost';
GRANT ALL ON *.* TO 'vt_dba'@'localhost';
GRANT GRANT OPTION ON *.* TO 'vt_dba'@'localhost';
GRANT PROXY ON ''@'' TO 'vt_dba'@'localhost' WITH GRANT OPTION;
# User for app traffic, with global read-write access.
CREATE USER 'vt_app'@'localhost';
Expand Down
1 change: 1 addition & 0 deletions test/endtoend/operator/operator-latest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1546,6 +1546,7 @@ spec:
enum:
- builtin
- xtrabackup
- mysqlshell
type: string
locations:
items:
Expand Down

0 comments on commit bff6251

Please sign in to comment.