Skip to content

Commit

Permalink
WALG-1683. Save CPU arch / OS to mysql sentinel. (#1693)
Browse files Browse the repository at this point in the history
* WALG-1683 Save CPU arch / OS to mysql sentinel.
* Use local GOOS and GOARCH because during restore we cannot connect to MySQL and compare values
  • Loading branch information
ostinru committed May 14, 2024
1 parent 89c5174 commit 99376a9
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 11 deletions.
21 changes: 16 additions & 5 deletions internal/databases/mysql/backup_push_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@ package mysql

import (
"context"
"github.com/wal-g/wal-g/pkg/storages/storage"
"os"
"os/exec"
"runtime"
"strings"

"github.com/wal-g/wal-g/pkg/storages/storage"

"github.com/wal-g/tracelog"

"github.com/wal-g/wal-g/internal"
"github.com/wal-g/wal-g/internal/limiters"
"github.com/wal-g/wal-g/utility"
Expand Down Expand Up @@ -52,7 +55,7 @@ func HandleBackupPush(
var backupName string
var prevBackupInfo PrevBackupInfo
var incrementCount int
var xtrabackupInfo XtrabackupInfo
var xtrabackupInfo XtrabackupExtInfo
if isXtrabackup(backupCmd) {
prevBackupInfo, incrementCount, err = deltaBackupConfigurator.Configure(isFullBackup, hostname, serverUUID, version)
tracelog.ErrorLogger.FatalfOnError("failed to get previous backup for delta backup: %v", err)
Expand Down Expand Up @@ -101,6 +104,8 @@ func HandleBackupPush(
Hostname: hostname,
ServerUUID: serverUUID,
ServerVersion: version,
ServerArch: xtrabackupInfo.ServerArch,
ServerOS: xtrabackupInfo.ServerOS,
IsPermanent: isPermanent,
IsIncremental: incrementCount != 0,
UserData: userData,
Expand Down Expand Up @@ -135,7 +140,7 @@ func handleXtrabackupBackup(
backupCmd *exec.Cmd,
isFullBackup bool,
prevBackupInfo *PrevBackupInfo,
) (backupName string, backupInfo XtrabackupInfo, err error) {
) (backupName string, backupExtInfo XtrabackupExtInfo, err error) {
if prevBackupInfo == nil {
tracelog.ErrorLogger.Fatalf("PrevBackupInfo is null")
}
Expand All @@ -158,16 +163,22 @@ func handleXtrabackupBackup(
tracelog.ErrorLogger.Printf("Backup command output:\n%s", stderr.String())
}

backupInfo, err = readXtrabackupInfo(xtrabackupExtraDirectory)
backupInfo, err := readXtrabackupInfo(xtrabackupExtraDirectory)
if err != nil {
tracelog.WarningLogger.Printf("failed to read and parse `xtrabackup_checkpoints`: %v", err)
}
backupExtInfo = XtrabackupExtInfo{
XtrabackupInfo: backupInfo,
// it is hard to run `wal-g xtrabackup-push` on remote host. So, expect that local OS/Arch is ok.
ServerOS: runtime.GOOS,
ServerArch: runtime.GOARCH,
}

err = removeTemporaryDirectory(xtrabackupExtraDirectory)
if err != nil {
tracelog.ErrorLogger.Printf("failed to remove tmp directory from diff-backup: %v", err)
err = nil // don't crash an app
}

return backupName, backupInfo, err
return backupName, backupExtInfo, err
}
31 changes: 25 additions & 6 deletions internal/databases/mysql/mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,31 @@ const (
WalgXtrabackupTool BackupTool = "WALG_XTRABACKUP_TOOL"
)

func getMySQLVersion(db *sql.DB) (string, error) {
row := db.QueryRow("SELECT @@version")
var version string
err := row.Scan(&version)
func fetchMySQLVariable(db *sql.DB, variable string) (string, error) {
row := db.QueryRow("SELECT @@" + variable)
var value string
err := row.Scan(&value)
if err != nil {
return "", err
}
return version, nil
return value, nil
}

func getMySQLVersion(db *sql.DB) (string, error) {
// e.g. '8.0.35-27'
return fetchMySQLVariable(db, "version")
}

// nolint:unused
func getMySQLArchitecture(db *sql.DB) (string, error) {
// e.g 'x86_64' / 'aarch64' / 'arm64'
return fetchMySQLVariable(db, "version_compile_machine")
}

// nolint:unused
func getMySQLOS(db *sql.DB) (string, error) {
// e.g. 'Linux' / 'macos14.2'
return fetchMySQLVariable(db, "version_compile_os")
}

func getMySQLFlavor(db *sql.DB) (string, error) {
Expand Down Expand Up @@ -230,7 +247,9 @@ type StreamSentinelDto struct {
CompressedSize int64 `json:"CompressedSize,omitempty"`
Hostname string `json:"Hostname,omitempty"`
ServerUUID string `json:"ServerUUID,omitempty"`
ServerVersion string `json:"ServerVersion,omitempty"`
ServerVersion string `json:"ServerVersion,omitempty"` // e.g. '8.0.35-27'
ServerArch string `json:"ServerArch,omitempty"` // e.g '386' / 'amd64' / 'arm64' / 'arm'
ServerOS string `json:"ServerOS,omitempty"` // e.g. 'linux' / 'darwin' / 'windows'

IsPermanent bool `json:"IsPermanent"`
IsIncremental bool `json:"IsIncremental"`
Expand Down
6 changes: 6 additions & 0 deletions internal/databases/mysql/xtrabackup.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ type XtrabackupInfo struct {
LastLSN *LSN
}

type XtrabackupExtInfo struct {
XtrabackupInfo
ServerOS string
ServerArch string
}

func NewXtrabackupInfo(content string) XtrabackupInfo {
result := XtrabackupInfo{}
for _, line := range strings.Split(content, "\n") {
Expand Down

0 comments on commit 99376a9

Please sign in to comment.