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