Skip to content

Commit

Permalink
Support config adapt to mysql 8.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
drivebyer committed Jul 27, 2024
1 parent 0727310 commit fc97d09
Showing 1 changed file with 42 additions and 13 deletions.
55 changes: 42 additions & 13 deletions pkg/controller/mysqlcluster/internal/syncer/config_map.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,15 @@ import (
"sort"
"strings"

"github.com/bitpoke/mysql-operator/pkg/internal/mysqlcluster"
"github.com/blang/semver"
"github.com/go-ini/ini"
"github.com/presslabs/controller-util/syncer"
core "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/util/intstr"
"sigs.k8s.io/controller-runtime/pkg/client"

"github.com/presslabs/controller-util/syncer"

"github.com/bitpoke/mysql-operator/pkg/internal/mysqlcluster"
)

// NewConfigMapSyncer returns config map syncer
Expand Down Expand Up @@ -96,15 +95,17 @@ fi
func buildMysqlConfData(cluster *mysqlcluster.MysqlCluster) (string, error) {
cfg := ini.Empty()
sec := cfg.Section("mysqld")

if cluster.GetMySQLSemVer().Major == 5 {
version := cluster.GetMySQLSemVer()
if version.Major == 5 {
addKVConfigsToSection(sec, convertMapToKVConfig(mysql5xConfigs))
} else if cluster.GetMySQLSemVer().Major == 8 {
} else if version.Major == 8 {
addKVConfigsToSection(sec, convertMapToKVConfig(mysql8xConfigs))
}

// boolean configs
addBConfigsToSection(sec, mysqlMasterSlaveBooleanConfigs)
addSkipHostCacheByVersion(sec, version)
addReplicationRepositoryByVersion(sec, version)
// add custom configs, would overwrite common configs
addKVConfigsToSection(sec, convertMapToKVConfig(mysqlCommonConfigs), cluster.Spec.MysqlConf)

Expand Down Expand Up @@ -170,6 +171,39 @@ func addBConfigsToSection(s *ini.Section, boolConfigs ...[]string) {
}
}

func addSkipHostCacheByVersion(s *ini.Section, version semver.Version) {
// cannot find which version exactly removes the --skip-host-cache option
// but in https://dev.mysql.com/doc/relnotes/mysql/8.0/en/news-8-0-30.html, it is deprecated.
if version.GTE(semver.MustParse("8.0.30")) {
// set host_cache_size to 0 for backward compatibility
_, err := s.NewKey("host_cache_size ", "0")
if err != nil {
log.Error(err, "failed to add key to config section", "key", "host_cache_size", "value", "0")
}
} else {
_, err := s.NewBooleanKey("skip-host-cache")
if err != nil {
log.Error(err, "failed to add boolean key to config section", "key", "skip-host-cache")
}
}
}

func addReplicationRepositoryByVersion(s *ini.Section, version semver.Version) {
// https://dev.mysql.com/doc/relnotes/mysql/8.3/en/news-8-3-0.html
if version.LT(semver.MustParse("8.3.0")) {
_, err := s.NewKey("relay-log-info-repository", "TABLE")
if err != nil {
log.Error(err, "failed to add key to config section", "key", "relay-log-info-repository", "value", "TABLE")
}

// https://github.com/github/orchestrator/issues/323#issuecomment-338451838
_, err = s.NewKey("master-info-repository", "TABLE")
if err != nil {
log.Error(err, "failed to add key to config section", "key", "master-info-repository", "value", "TABLE")
}
}
}

// helper function to write to string ini.File
// nolint: interfacer
func writeConfigs(cfg *ini.File) (string, error) {
Expand All @@ -191,11 +225,7 @@ var mysqlCommonConfigs = map[string]string{
"skip-slave-start": "on",

// Crash safe
"relay-log-info-repository": "TABLE",
"relay-log-recovery": "on",

// https://github.com/github/orchestrator/issues/323#issuecomment-338451838
"master-info-repository": "TABLE",
"relay-log-recovery": "on",

"default-storage-engine": "InnoDB",
"gtid-mode": "on",
Expand Down Expand Up @@ -256,5 +286,4 @@ var mysql8xConfigs = map[string]string{
var mysqlMasterSlaveBooleanConfigs = []string{
// Safety
"skip-name-resolve",
"skip-host-cache",
}

0 comments on commit fc97d09

Please sign in to comment.