Skip to content

Support config adapt to mysql 8.3.0 #926

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
68 changes: 51 additions & 17 deletions pkg/controller/mysqlcluster/internal/syncer/config_map.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"sort"
"strings"

"github.com/blang/semver"
"github.com/go-ini/ini"
core "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -96,17 +97,20 @@ fi
func buildMysqlConfData(cluster *mysqlcluster.MysqlCluster) (string, error) {
cfg := ini.Empty()
sec := cfg.Section("mysqld")

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

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

addBConfigsToSection(
sec,
mysqlMasterSlaveBooleanConfigs,
getBConfigsByVersion(version),
)
// add custom configs in the latest order, so they can override the default ones
addKVConfigsToSection(
sec,
getKVConfigsByVersion(version),
convertMapToKVConfig(mysqlCommonConfigs),
cluster.Spec.MysqlConf,
)

// include configs from /etc/mysql/conf.d/*.cnf
_, err := sec.NewBooleanKey(fmt.Sprintf("!includedir %s", ConfDPath))
Expand All @@ -123,6 +127,41 @@ func buildMysqlConfData(cluster *mysqlcluster.MysqlCluster) (string, error) {

}

func getKVConfigsByVersion(version semver.Version) map[string]intstr.IntOrString {
configs := make(map[string]intstr.IntOrString)

if version.Major == 5 {
configs = convertMapToKVConfig(mysql5xConfigs)
} else {
configs = convertMapToKVConfig(mysql8xConfigs)
}

// https://dev.mysql.com/doc/relnotes/mysql/8.3/en/news-8-3-0.html
if version.LT(semver.MustParse("8.3.0")) {
configs["relay-log-info-repository"] = intstr.Parse("TABLE")
configs["master-info-repository"] = intstr.Parse("TABLE")
}

// https://dev.mysql.com/doc/relnotes/mysql/8.0/en/news-8-0-30.html
if version.GTE(semver.MustParse("8.0.30")) {
// set host_cache_size to 0 for backward compatibility
configs["host_cache_size"] = intstr.Parse("0")
}

return configs
}

func getBConfigsByVersion(version semver.Version) []string {
var configs []string

// https://dev.mysql.com/doc/relnotes/mysql/8.0/en/news-8-0-30.html
if version.LT(semver.MustParse("8.0.30")) {
configs = append(configs, "skip-host-cache")
}

return configs
}

func convertMapToKVConfig(m map[string]string) map[string]intstr.IntOrString {
config := make(map[string]intstr.IntOrString)

Expand Down Expand Up @@ -191,11 +230,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 +291,4 @@ var mysql8xConfigs = map[string]string{
var mysqlMasterSlaveBooleanConfigs = []string{
// Safety
"skip-name-resolve",
"skip-host-cache",
}