Skip to content
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

add mysql-shell engine as a supported engine #586

Merged
merged 7 commits into from
Sep 24, 2024
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
1 change: 1 addition & 0 deletions deploy/crds/planetscale.com_vitessclusters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,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
23 changes: 18 additions & 5 deletions pkg/operator/vttablet/backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ package vttablet
import (
"fmt"

corev1 "k8s.io/api/core/v1"
planetscalev2 "planetscale.dev/vitess-operator/pkg/apis/planetscale/v2"
"planetscale.dev/vitess-operator/pkg/operator/lazy"
"planetscale.dev/vitess-operator/pkg/operator/vitess"
"planetscale.dev/vitess-operator/pkg/operator/vitessbackup"
corev1 "k8s.io/api/core/v1"
)

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 @@ -1523,6 +1523,7 @@ spec:
enum:
- builtin
- xtrabackup
- mysqlshell
type: string
locations:
items:
Expand Down
Loading