@@ -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 {
100
+ version := cluster . GetMySQLSemVer ()
101
+ if version .Major == 5 {
101
102
addKVConfigsToSection (sec , convertMapToKVConfig (mysql5xConfigs ))
102
- } else if cluster . GetMySQLSemVer () .Major == 8 {
103
+ } else if version .Major == 8 {
103
104
addKVConfigsToSection (sec , convertMapToKVConfig (mysql8xConfigs ))
104
105
}
105
106
106
107
// boolean configs
107
108
addBConfigsToSection (sec , mysqlMasterSlaveBooleanConfigs )
109
+ addConfigsToSectionByVersion (sec , version )
108
110
// add custom configs, would overwrite common configs
109
111
addKVConfigsToSection (sec , convertMapToKVConfig (mysqlCommonConfigs ), cluster .Spec .MysqlConf )
110
112
@@ -170,6 +172,37 @@ func addBConfigsToSection(s *ini.Section, boolConfigs ...[]string) {
170
172
}
171
173
}
172
174
175
+ func addConfigsToSectionByVersion (s * ini.Section , version semver.Version ) {
176
+ // cannot find which version exactly removes the --skip-host-cache option
177
+ // but in https://dev.mysql.com/doc/relnotes/mysql/8.0/en/news-8-0-30.html, it is deprecated.
178
+ if version .GTE (semver .MustParse ("8.0.30" )) {
179
+ // set host_cache_size to 0 for backward compatibility
180
+ _ , err := s .NewKey ("host_cache_size " , "0" )
181
+ if err != nil {
182
+ log .Error (err , "failed to add key to config section" , "key" , "host_cache_size" , "value" , "0" )
183
+ }
184
+ } else {
185
+ _ , err := s .NewBooleanKey ("skip-host-cache" )
186
+ if err != nil {
187
+ log .Error (err , "failed to add boolean key to config section" , "key" , "skip-host-cache" )
188
+ }
189
+ }
190
+
191
+ // https://dev.mysql.com/doc/relnotes/mysql/8.3/en/news-8-3-0.html
192
+ if version .LT (semver .MustParse ("8.3.0" )) {
193
+ _ , err := s .NewKey ("relay-log-info-repository" , "TABLE" )
194
+ if err != nil {
195
+ log .Error (err , "failed to add key to config section" , "key" , "relay-log-info-repository" , "value" , "TABLE" )
196
+ }
197
+
198
+ // https://github.com/github/orchestrator/issues/323#issuecomment-338451838
199
+ _ , err = s .NewKey ("master-info-repository" , "TABLE" )
200
+ if err != nil {
201
+ log .Error (err , "failed to add key to config section" , "key" , "master-info-repository" , "value" , "TABLE" )
202
+ }
203
+ }
204
+ }
205
+
173
206
// helper function to write to string ini.File
174
207
// nolint: interfacer
175
208
func writeConfigs (cfg * ini.File ) (string , error ) {
@@ -191,11 +224,7 @@ var mysqlCommonConfigs = map[string]string{
191
224
"skip-slave-start" : "on" ,
192
225
193
226
// 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" ,
227
+ "relay-log-recovery" : "on" ,
199
228
200
229
"default-storage-engine" : "InnoDB" ,
201
230
"gtid-mode" : "on" ,
@@ -256,5 +285,4 @@ var mysql8xConfigs = map[string]string{
256
285
var mysqlMasterSlaveBooleanConfigs = []string {
257
286
// Safety
258
287
"skip-name-resolve" ,
259
- "skip-host-cache" ,
260
288
}
0 commit comments