Skip to content

Commit eab31b7

Browse files
committed
Support config adapt to mysql 8.3.0
1 parent 0727310 commit eab31b7

File tree

1 file changed

+51
-17
lines changed

1 file changed

+51
-17
lines changed

pkg/controller/mysqlcluster/internal/syncer/config_map.go

Lines changed: 51 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"sort"
2323
"strings"
2424

25+
"github.com/blang/semver"
2526
"github.com/go-ini/ini"
2627
core "k8s.io/api/core/v1"
2728
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -96,17 +97,20 @@ fi
9697
func buildMysqlConfData(cluster *mysqlcluster.MysqlCluster) (string, error) {
9798
cfg := ini.Empty()
9899
sec := cfg.Section("mysqld")
99-
100-
if cluster.GetMySQLSemVer().Major == 5 {
101-
addKVConfigsToSection(sec, convertMapToKVConfig(mysql5xConfigs))
102-
} else if cluster.GetMySQLSemVer().Major == 8 {
103-
addKVConfigsToSection(sec, convertMapToKVConfig(mysql8xConfigs))
104-
}
105-
106-
// boolean configs
107-
addBConfigsToSection(sec, mysqlMasterSlaveBooleanConfigs)
108-
// add custom configs, would overwrite common configs
109-
addKVConfigsToSection(sec, convertMapToKVConfig(mysqlCommonConfigs), cluster.Spec.MysqlConf)
100+
version := cluster.GetMySQLSemVer()
101+
102+
addBConfigsToSection(
103+
sec,
104+
mysqlMasterSlaveBooleanConfigs,
105+
getBConfigsByVersion(version),
106+
)
107+
// add custom configs in the latest order, so they can override the default ones
108+
addKVConfigsToSection(
109+
sec,
110+
getKVConfigsByVersion(version),
111+
convertMapToKVConfig(mysqlCommonConfigs),
112+
cluster.Spec.MysqlConf,
113+
)
110114

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

124128
}
125129

130+
func getKVConfigsByVersion(version semver.Version) map[string]intstr.IntOrString {
131+
configs := make(map[string]intstr.IntOrString)
132+
133+
if version.Major == 5 {
134+
configs = convertMapToKVConfig(mysql5xConfigs)
135+
} else {
136+
configs = convertMapToKVConfig(mysql8xConfigs)
137+
}
138+
139+
// https://dev.mysql.com/doc/relnotes/mysql/8.3/en/news-8-3-0.html
140+
if version.LT(semver.MustParse("8.3.0")) {
141+
configs["relay-log-info-repository"] = intstr.Parse("TABLE")
142+
configs["master-info-repository"] = intstr.Parse("TABLE")
143+
}
144+
145+
// https://dev.mysql.com/doc/relnotes/mysql/8.0/en/news-8-0-30.html
146+
if version.GTE(semver.MustParse("8.0.30")) {
147+
// set host_cache_size to 0 for backward compatibility
148+
configs["host_cache_size"] = intstr.Parse("0")
149+
}
150+
151+
return configs
152+
}
153+
154+
func getBConfigsByVersion(version semver.Version) []string {
155+
var configs []string
156+
157+
// https://dev.mysql.com/doc/relnotes/mysql/8.0/en/news-8-0-30.html
158+
if version.LT(semver.MustParse("8.0.30")) {
159+
configs = append(configs, "skip-host-cache")
160+
}
161+
162+
return configs
163+
}
164+
126165
func convertMapToKVConfig(m map[string]string) map[string]intstr.IntOrString {
127166
config := make(map[string]intstr.IntOrString)
128167

@@ -191,11 +230,7 @@ var mysqlCommonConfigs = map[string]string{
191230
"skip-slave-start": "on",
192231

193232
// Crash safe
194-
"relay-log-info-repository": "TABLE",
195-
"relay-log-recovery": "on",
196-
197-
// https://github.com/github/orchestrator/issues/323#issuecomment-338451838
198-
"master-info-repository": "TABLE",
233+
"relay-log-recovery": "on",
199234

200235
"default-storage-engine": "InnoDB",
201236
"gtid-mode": "on",
@@ -256,5 +291,4 @@ var mysql8xConfigs = map[string]string{
256291
var mysqlMasterSlaveBooleanConfigs = []string{
257292
// Safety
258293
"skip-name-resolve",
259-
"skip-host-cache",
260294
}

0 commit comments

Comments
 (0)