Skip to content

Commit 7f16d54

Browse files
authored
Merge pull request #437 from runkecheng/feature_mysql8
*: Optimize mysql8 related logic.
2 parents 7cad2ca + 4feba83 commit 7f16d54

File tree

11 files changed

+114
-72
lines changed

11 files changed

+114
-72
lines changed

api/v1alpha1/mysqlcluster_types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ type MysqlOpts struct {
120120

121121
// InitTokuDB represents if install tokudb engine.
122122
// +optional
123-
// +kubebuilder:default:=true
123+
// +kubebuilder:default:=false
124124
InitTokuDB bool `json:"initTokuDB,omitempty"`
125125

126126
// A map[string]string that will be passed to my.cnf file.

charts/mysql-operator/crds/mysql.radondb.com_backups.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ spec:
4848
description: HostName represents the host for which to take backup
4949
type: string
5050
image:
51-
default: radondb/mysql-sidecar:latest
51+
default: radondb/mysql57-sidecar:v2.2.0
5252
description: To specify the image that will be used for sidecar container.
5353
type: string
5454
required:

charts/mysql-operator/crds/mysql.radondb.com_mysqlclusters.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ spec:
137137
description: Name for new database to create.
138138
type: string
139139
initTokuDB:
140-
default: true
140+
default: false
141141
description: InitTokuDB represents if install tokudb engine.
142142
type: boolean
143143
mysqlConf:
@@ -252,7 +252,7 @@ spec:
252252
cpu: 10m
253253
memory: 32Mi
254254
imagePullPolicy: IfNotPresent
255-
sidecarImage: radondb/mysql-sidecar:latest
255+
sidecarImage: radondb/mysql57-sidecar:v2.2.0
256256
description: PodPolicy defines the policy to extra specification.
257257
properties:
258258
affinity:
@@ -1182,7 +1182,7 @@ spec:
11821182
schedulerName:
11831183
type: string
11841184
sidecarImage:
1185-
default: radondb/mysql-sidecar:latest
1185+
default: radondb/mysql57-sidecar:v2.2.0
11861186
description: To specify the image that will be used for sidecar
11871187
container.
11881188
type: string

charts/mysql-operator/values.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ tolerationSeconds: 30
2121

2222
manager:
2323
image: radondb/mysql-operator
24-
tag: latest
24+
tag: v2.2.0
2525
resources: {}
2626
# We usually recommend not to specify default resources and to leave this as a conscious
2727
# choice for the user. This also increases chances charts run on environments with little

config/samples/mysql_v1alpha1_mysqlcluster.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ spec:
6262

6363
podPolicy:
6464
imagePullPolicy: IfNotPresent
65-
sidecarImage: radondb/mysql-sidecar:latest
65+
sidecarImage: radondb/mysql57-sidecar:v2.2.0
6666
busyboxImage: busybox:1.32
6767

6868
slowLogTail: false

config/samples/mysql_v1alpha1_mysqlcluster_mysql8.yaml

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,74 @@
11
apiVersion: mysql.radondb.com/v1alpha1
22
kind: MysqlCluster
33
metadata:
4-
name: mysql8-sample
4+
name: sample
55
spec:
66
replicas: 3
77
mysqlVersion: "8.0"
8+
89
# the backupSecretName specify the secret file name which store S3 information,
910
# if you want S3 backup or restore, please create backup_secret.yaml, uncomment below and fill secret name:
1011
# backupSecretName:
11-
12+
1213
# if you want create mysqlcluster from S3, uncomment and fill the directory in S3 bucket below:
13-
# restoreFrom: "backup_2022324174848"
14+
# restoreFrom:
15+
1416
mysqlOpts:
1517
rootPassword: "RadonDB@123"
1618
rootHost: localhost
1719
user: radondb_usr
1820
password: RadonDB@123
1921
database: radondb
22+
## tokudb is not supported in mysql8.
23+
# initTokuDB: false
24+
2025
# A simple map between string and string.
2126
# Such as:
2227
# mysqlConf:
2328
# expire_logs_days: "7"
2429
mysqlConf: {}
30+
2531
resources:
2632
requests:
2733
cpu: 100m
2834
memory: 256Mi
2935
limits:
3036
cpu: 500m
3137
memory: 1Gi
38+
3239
xenonOpts:
3340
image: radondb/xenon:1.1.5-alpha
3441
admitDefeatHearbeatCount: 5
3542
electionTimeout: 10000
43+
3644
resources:
3745
requests:
3846
cpu: 50m
3947
memory: 128Mi
4048
limits:
4149
cpu: 100m
4250
memory: 256Mi
51+
4352
metricsOpts:
4453
enabled: false
4554
image: prom/mysqld-exporter:v0.12.1
55+
4656
resources:
4757
requests:
4858
cpu: 10m
4959
memory: 32Mi
5060
limits:
5161
cpu: 100m
5262
memory: 128Mi
63+
5364
podPolicy:
54-
imagePullPolicy: Always
65+
imagePullPolicy: IfNotPresent
5566
sidecarImage: radondb/mysql80-sidecar:v2.2.0
5667
busyboxImage: busybox:1.32
68+
5769
slowLogTail: false
5870
auditLogTail: false
71+
5972
labels: {}
6073
annotations: {}
6174
affinity: {}
@@ -67,10 +80,10 @@ spec:
6780
requests:
6881
cpu: 10m
6982
memory: 32Mi
83+
7084
persistence:
7185
enabled: true
7286
accessModes:
73-
- ReadWriteOnce
87+
- ReadWriteOnce
7488
#storageClass: ""
7589
size: 20Gi
76-
backupSecretName: sample-backup-secret

config/samples/mysql_v1alpha1_mysqlcluster_podAntiAffinity.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ spec:
6262

6363
podPolicy:
6464
imagePullPolicy: IfNotPresent
65-
sidecarImage: radondb/mysql-sidecar:latest
65+
sidecarImage: radondb/mysql57-sidecar:v2.2.0
6666
busyboxImage: busybox:1.32
6767

6868
slowLogTail: false

mysqlcluster/syncer/config_map.go

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,13 @@ func NewConfigMapSyncer(cli client.Client, c *mysqlcluster.MysqlCluster) syncer.
5151
return fmt.Errorf("failed to create mysql configs: %s", err)
5252
}
5353

54-
dataSpecial, err := buildMysqlSpecialConf(c)
54+
dataPlugin, err := buildMysqlPluginConf(c)
5555
if err != nil {
56-
return fmt.Errorf("failed to create mysql special configs: %s", err)
56+
return fmt.Errorf("failed to create mysql plugin configs: %s", err)
5757
}
5858
cm.Data = map[string]string{
5959
"my.cnf": data,
60-
utils.SpecialConfig: dataSpecial,
60+
utils.PluginConfigs: dataPlugin,
6161
}
6262

6363
return nil
@@ -70,10 +70,14 @@ func buildMysqlConf(c *mysqlcluster.MysqlCluster) (string, error) {
7070
sec := cfg.Section("mysqld")
7171

7272
c.EnsureMysqlConf()
73-
if c.Spec.MysqlVersion == "8.0" {
74-
delete(mysqlCommonConfigs, "query_cache_size")
75-
delete(mysqlStaticConfigs, "query_cache_type")
73+
74+
switch c.Spec.MysqlVersion {
75+
case "8.0":
76+
addKVConfigsToSection(sec, mysql80Configs)
77+
case "5.7":
78+
addKVConfigsToSection(sec, mysql57Configs)
7679
}
80+
7781
addKVConfigsToSection(sec, mysqlSysConfigs, mysqlCommonConfigs, mysqlStaticConfigs, c.Spec.MysqlOpts.MysqlConf)
7882

7983
if c.Spec.MysqlOpts.InitTokuDB {
@@ -94,12 +98,12 @@ func buildMysqlConf(c *mysqlcluster.MysqlCluster) (string, error) {
9498
return data, nil
9599
}
96100

97-
// Build the Special Cnf file.
98-
func buildMysqlSpecialConf(c *mysqlcluster.MysqlCluster) (string, error) {
101+
// Build the Plugin Cnf file.
102+
func buildMysqlPluginConf(c *mysqlcluster.MysqlCluster) (string, error) {
99103
cfg := ini.Empty(ini.LoadOptions{IgnoreInlineComment: true})
100104
sec := cfg.Section("mysqld")
101105

102-
addKVConfigsToSection(sec, specialConfigs)
106+
addKVConfigsToSection(sec, pluginConfigs)
103107
data, err := writeConfigs(cfg)
104108
if err != nil {
105109
return "", err

mysqlcluster/syncer/variables.go renamed to mysqlcluster/syncer/mysql_configs.go

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -40,55 +40,73 @@ var mysqlSysConfigs = map[string]string{
4040
"slave_parallel_type": "LOGICAL_CLOCK",
4141
"relay_log": "/var/lib/mysql/mysql-relay-bin",
4242
"relay_log_index": "/var/lib/mysql/mysql-relay-bin.index",
43-
"master_info_repository": "TABLE",
44-
"relay_log_info_repository": "TABLE",
4543
"slow_query_log": "1",
4644
"tmp_table_size": "32M",
4745
"tmpdir": "/var/lib/mysql",
4846
}
4947

50-
var specialConfigs = map[string]string{
48+
var pluginConfigs = map[string]string{
5149
"plugin-load": "\"semisync_master.so;semisync_slave.so;audit_log.so;connection_control.so\"",
52-
"audit_log_file": "/var/log/mysql/mysql-audit.log",
53-
"audit_log_exclude_accounts": "\"root@localhost,root@127.0.0.1," + utils.ReplicationUser + "@%," + utils.MetricsUser + "@%\"",
54-
"audit_log_buffer_size": "16M",
50+
5551
"rpl_semi_sync_master_enabled": "OFF",
5652
"rpl_semi_sync_slave_enabled": "ON",
5753
"rpl_semi_sync_master_wait_no_slave": "ON",
5854
"rpl_semi_sync_master_timeout": "1000000000000000000",
59-
//"audit-log": "ON",
55+
56+
"audit_log_file": "/var/log/mysql/mysql-audit.log",
57+
"audit_log_exclude_accounts": "\"root@localhost,root@127.0.0.1," + utils.ReplicationUser + "@%," + utils.MetricsUser + "@%\"",
58+
"audit_log_buffer_size": "16M",
6059
"audit_log_policy": "NONE",
6160
"audit_log_rotate_on_size": "104857600",
6261
"audit_log_rotations": "6",
6362
"audit_log_format": "OLD",
63+
6464
"connection_control_failed_connections_threshold": "3",
6565
"connection_control_min_connection_delay": "1000",
6666
"connection_control_max_connection_delay": "2147483647",
67-
"default-authentication-plugin": "mysql_native_password",
67+
}
68+
69+
var mysql57Configs = map[string]string{
70+
"query-cache-type": "0",
71+
"query-cache-size": "0",
72+
"sql-mode": "STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER," +
73+
"NO_AUTO_VALUE_ON_ZERO,NO_ENGINE_SUBSTITUTION,NO_ZERO_DATE,NO_ZERO_IN_DATE,ONLY_FULL_GROUP_BY",
74+
75+
"expire-logs-days": "7",
76+
77+
"master_info_repository": "TABLE",
78+
"relay_log_info_repository": "TABLE",
79+
"slave_rows_search_algorithms": "INDEX_SCAN,HASH_SCAN",
80+
}
81+
82+
var mysql80Configs = map[string]string{
83+
"sql-mode": "STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_VALUE_ON_ZERO,NO_ENGINE_SUBSTITUTION," +
84+
"NO_ZERO_DATE,NO_ZERO_IN_DATE,ONLY_FULL_GROUP_BY",
85+
// 7 days = 7 * 24 * 60 * 60
86+
"binlog_expire_logs_seconds": "604800",
87+
// use 5.7 auth plugin to be backward compatible
88+
"default-authentication-plugin": "mysql_native_password",
6889
}
6990

7091
// mysqlCommonConfigs is the map of the mysql common configs.
7192
var mysqlCommonConfigs = map[string]string{
7293
"character_set_server": "utf8mb4",
7394
"interactive_timeout": "3600",
7495
"default-time-zone": "+08:00",
75-
"expire_logs_days": "7",
7696
"key_buffer_size": "33554432",
7797
"log_bin_trust_function_creators": "1",
7898
"long_query_time": "3",
7999
"binlog_cache_size": "32768",
80100
"binlog_stmt_cache_size": "32768",
81101
"max_connections": "1024",
82102
"max_connect_errors": "655360",
83-
"query_cache_size": "0",
84103
"sync_master_info": "1000",
85104
"sync_relay_log": "1000",
86105
"sync_relay_log_info": "1000",
87106
"table_open_cache": "2000",
88107
"thread_cache_size": "128",
89108
"wait_timeout": "3600",
90109
"group_concat_max_len": "1024",
91-
"slave_rows_search_algorithms": "INDEX_SCAN,HASH_SCAN",
92110
"max_allowed_packet": "1073741824",
93111
"event_scheduler": "OFF",
94112
"innodb_print_all_deadlocks": "0",
@@ -102,12 +120,10 @@ var mysqlCommonConfigs = map[string]string{
102120
// mysqlStaticConfigs is the map of the mysql static configs.
103121
// The mysql need restart, if modify the config.
104122
var mysqlStaticConfigs = map[string]string{
105-
106123
"default-storage-engine": "InnoDB",
107124
"back_log": "2048",
108125
"ft_min_word_len": "4",
109126
"lower_case_table_names": "0",
110-
"query_cache_type": "OFF",
111127
"innodb_ft_max_token_size": "84",
112128
"innodb_ft_min_token_size": "3",
113129
"sql_mode": "STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION",

0 commit comments

Comments
 (0)