Skip to content

Commit

Permalink
issue-686: support MySQL 8.4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
shunki-fujita committed Jun 13, 2024
1 parent 8d9903b commit 230da45
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
MYSQL_VERSION = 8.0.37
MYSQL_VERSION = 8.4.0

# For Go
GOOS := $(shell go env GOOS)
Expand Down
3 changes: 2 additions & 1 deletion server/clone_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package server
import (
"context"
"path/filepath"
"strings"
"time"

mocoagent "github.com/cybozu-go/moco-agent"
Expand Down Expand Up @@ -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())
Expand Down
13 changes: 7 additions & 6 deletions server/initialize.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion server/mysql_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}()
Expand Down
7 changes: 4 additions & 3 deletions server/mysqld_health_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"net/http"
"net/http/httptest"
"path/filepath"
"strings"
"time"

mocoagent "github.com/cybozu-go/moco-agent"
Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -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())
Expand Down

0 comments on commit 230da45

Please sign in to comment.