From 230da459955916bde60d5e0d471841e711db9885 Mon Sep 17 00:00:00 2001 From: shunki-fujita Date: Wed, 12 Jun 2024 06:51:48 +0000 Subject: [PATCH] issue-686: support MySQL 8.4.0 --- .github/workflows/ci.yaml | 2 +- Makefile | 2 +- server/clone_test.go | 3 ++- server/initialize.go | 13 +++++++------ server/mysql_test.go | 2 +- server/mysqld_health_test.go | 7 ++++--- 6 files changed, 16 insertions(+), 13 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 7ce1800..fcca8f5 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -43,7 +43,7 @@ jobs: name: Small Tests strategy: matrix: - mysql-version: ["8.0.18", "8.0.25", "8.0.26", "8.0.27", "8.0.28", "8.0.30", "8.0.31", "8.0.32", "8.0.33", "8.0.34", "8.0.35", "8.0.36", "8.0.37"] + mysql-version: ["8.0.28", "8.0.36", "8.0.37", "8.4.0"] runs-on: ubuntu-22.04 steps: - uses: actions/checkout@v4 diff --git a/Makefile b/Makefile index b358778..877869a 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -MYSQL_VERSION = 8.0.37 +MYSQL_VERSION = 8.4.0 # For Go GOOS := $(shell go env GOOS) diff --git a/server/clone_test.go b/server/clone_test.go index b3a43b5..e305f3a 100644 --- a/server/clone_test.go +++ b/server/clone_test.go @@ -3,6 +3,7 @@ package server import ( "context" "path/filepath" + "strings" "time" mocoagent "github.com/cybozu-go/moco-agent" @@ -104,7 +105,7 @@ var _ = Describe("clone", func() { By("starting replication") _, err = donorDB.Exec(`INSERT INTO foo.bar (i) VALUES (9), (999)`) Expect(err).NotTo(HaveOccurred()) - if strings.hasPrefix(MySQLVersion, "8.4") { + if strings.HasPrefix(MySQLVersion, "8.4") { _, err = replicaDB.Exec(`CHANGE REPLICATION SOURCE TO SOURCE_HOST=?, SOURCE_PORT=3306, SOURCE_USER=?, SOURCE_PASSWORD=?, GET_SOURCE_PUBLIC_KEY=1`, donorHost, mocoagent.ReplicationUser, replicationUserPassword) Expect(err).NotTo(HaveOccurred()) diff --git a/server/initialize.go b/server/initialize.go index 44065ba..21f85e2 100644 --- a/server/initialize.go +++ b/server/initialize.go @@ -321,16 +321,17 @@ func Init(ctx context.Context, db *sqlx.DB, socket string) error { var version string err := db.GetContext(ctx, &version, `SELECT SUBSTRING_INDEX(VERSION(), '.', 2)`) if err != nil { - return false, fmt.Errorf("failed to get version: %w", err) + return fmt.Errorf("failed to get version: %w", err) } - if version == "8.0" { - if _, err := db.ExecContext(ctx, "RESET MASTER"); err != nil { - return fmt.Errorf("failed to reset master: %w", err) - } - } else { + if version == "8.4" { if _, err := db.ExecContext(ctx, "RESET BINARY LOGS AND GTIDS"); err != nil { return fmt.Errorf("failed to reset binary logs and gtids: %w", err) } + + } else { + if _, err := db.ExecContext(ctx, "RESET MASTER"); err != nil { + return fmt.Errorf("failed to reset master: %w", err) + } } if _, err := db.ExecContext(ctx, "SET GLOBAL super_read_only=ON"); err != nil { return fmt.Errorf("failed to enable super_read_only: %w", err) diff --git a/server/mysql_test.go b/server/mysql_test.go index 363e4fd..18f5956 100644 --- a/server/mysql_test.go +++ b/server/mysql_test.go @@ -35,7 +35,7 @@ var tmpBaseDir = path.Join(os.TempDir(), "moco-agent-test-server") var MySQLVersion = func() string { if ver := os.Getenv("MYSQL_VERSION"); ver == "" { - os.Setenv("MYSQL_VERSION", "8.0.28") + os.Setenv("MYSQL_VERSION", "8.4.0") } return os.Getenv("MYSQL_VERSION") }() diff --git a/server/mysqld_health_test.go b/server/mysqld_health_test.go index b4ab221..b592fb8 100644 --- a/server/mysqld_health_test.go +++ b/server/mysqld_health_test.go @@ -4,6 +4,7 @@ import ( "net/http" "net/http/httptest" "path/filepath" + "strings" "time" mocoagent "github.com/cybozu-go/moco-agent" @@ -104,8 +105,8 @@ var _ = Describe("health", func() { items := []interface{}{100, 299, 993, 9292} _, err = donorDB.Exec("INSERT INTO foo.bar (i) VALUES (?), (?), (?), (?)", items...) Expect(err).NotTo(HaveOccurred()) - - if strings.hasPrefix(MYSQL_VERSION, "8.4") { + + if strings.HasPrefix(MySQLVersion, "8.4") { _, err = replicaDB.Exec(`CHANGE REPLICATION SOURCE TO SOURCE_HOST=?, SOURCE_PORT=3306, SOURCE_USER=?, SOURCE_PASSWORD=?, GET_SOURCE_PUBLIC_KEY=1`, donorHost, mocoagent.ReplicationUser, replicationUserPassword) Expect(err).NotTo(HaveOccurred()) @@ -179,7 +180,7 @@ var _ = Describe("health", func() { _, err = donorDB.Exec("SET GLOBAL read_only=0") Expect(err).NotTo(HaveOccurred()) - if strings.hasPrefix(MYSQL_VERSION, "8.4") { + if strings.HasPrefix(MySQLVersion, "8.4") { _, err = replicaDB.Exec(`CHANGE REPLICATION SOURCE TO SOURCE_HOST=?, SOURCE_PORT=3306, SOURCE_USER=?, SOURCE_PASSWORD=?, GET_SOURCE_PUBLIC_KEY=1`, donorHost, mocoagent.ReplicationUser, replicationUserPassword) Expect(err).NotTo(HaveOccurred())