@@ -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+ addConfigsToSectionByVersion (sec , version )
108110 // add custom configs, would overwrite common configs
109111 addKVConfigsToSection (sec , convertMapToKVConfig (mysqlCommonConfigs ), cluster .Spec .MysqlConf )
110112
@@ -170,6 +172,37 @@ func addBConfigsToSection(s *ini.Section, boolConfigs ...[]string) {
170172 }
171173}
172174
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+
173206// helper function to write to string ini.File
174207// nolint: interfacer
175208func writeConfigs (cfg * ini.File ) (string , error ) {
@@ -191,11 +224,7 @@ var mysqlCommonConfigs = map[string]string{
191224 "skip-slave-start" : "on" ,
192225
193226 // 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" ,
199228
200229 "default-storage-engine" : "InnoDB" ,
201230 "gtid-mode" : "on" ,
@@ -256,5 +285,4 @@ var mysql8xConfigs = map[string]string{
256285var mysqlMasterSlaveBooleanConfigs = []string {
257286 // Safety
258287 "skip-name-resolve" ,
259- "skip-host-cache" ,
260288}
0 commit comments