@@ -22,6 +22,7 @@ import (
22
22
"sort"
23
23
"strings"
24
24
25
+ "github.com/blang/semver"
25
26
"github.com/go-ini/ini"
26
27
core "k8s.io/api/core/v1"
27
28
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
96
97
func buildMysqlConfData (cluster * mysqlcluster.MysqlCluster ) (string , error ) {
97
98
cfg := ini .Empty ()
98
99
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
+ )
110
114
111
115
// include configs from /etc/mysql/conf.d/*.cnf
112
116
_ , err := sec .NewBooleanKey (fmt .Sprintf ("!includedir %s" , ConfDPath ))
@@ -123,6 +127,41 @@ func buildMysqlConfData(cluster *mysqlcluster.MysqlCluster) (string, error) {
123
127
124
128
}
125
129
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
+
126
165
func convertMapToKVConfig (m map [string ]string ) map [string ]intstr.IntOrString {
127
166
config := make (map [string ]intstr.IntOrString )
128
167
@@ -191,11 +230,7 @@ var mysqlCommonConfigs = map[string]string{
191
230
"skip-slave-start" : "on" ,
192
231
193
232
// 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" ,
199
234
200
235
"default-storage-engine" : "InnoDB" ,
201
236
"gtid-mode" : "on" ,
@@ -256,5 +291,4 @@ var mysql8xConfigs = map[string]string{
256
291
var mysqlMasterSlaveBooleanConfigs = []string {
257
292
// Safety
258
293
"skip-name-resolve" ,
259
- "skip-host-cache" ,
260
294
}
0 commit comments