@@ -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"
9697func buildMysqlConfData (cluster * mysqlcluster.MysqlCluster ) (string , error ) {
9798 cfg := ini .Empty ()
9899 sec := cfg .Section ("mysqld" )
99-
100- if cluster . GetMySQLSemVer () .Major == 5 {
100+ version := cluster . GetMySQLSemVer ()
101+ if version .Major == 5 {
101102 addKVConfigsToSection (sec , convertMapToKVConfig (mysql5xConfigs ))
102- } else if cluster . GetMySQLSemVer () .Major == 8 {
103+ } else if version .Major == 8 {
103104 addKVConfigsToSection (sec , convertMapToKVConfig (mysql8xConfigs ))
104105 }
105106
106107 // boolean configs
107108 addBConfigsToSection (sec , mysqlMasterSlaveBooleanConfigs )
109+ addSkipHostCacheByVersion (sec , version )
110+ addReplicationRepositoryByVersion (sec , version )
108111 // add custom configs, would overwrite common configs
109112 addKVConfigsToSection (sec , convertMapToKVConfig (mysqlCommonConfigs ), cluster .Spec .MysqlConf )
110113
@@ -170,6 +173,39 @@ func addBConfigsToSection(s *ini.Section, boolConfigs ...[]string) {
170173 }
171174}
172175
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+
173209// helper function to write to string ini.File
174210// nolint: interfacer
175211func writeConfigs (cfg * ini.File ) (string , error ) {
@@ -191,11 +227,7 @@ var mysqlCommonConfigs = map[string]string{
191227 "skip-slave-start" : "on" ,
192228
193229 // 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" ,
199231
200232 "default-storage-engine" : "InnoDB" ,
201233 "gtid-mode" : "on" ,
@@ -256,5 +288,4 @@ var mysql8xConfigs = map[string]string{
256288var mysqlMasterSlaveBooleanConfigs = []string {
257289 // Safety
258290 "skip-name-resolve" ,
259- "skip-host-cache" ,
260291}
0 commit comments