1
+ #! /usr/bin/bash
2
+ CLUSTER=
3
+ IMAGE=
4
+ update () {
5
+ # set innodb_fast_shutdown=0 in yaml file
6
+ kubectl patch mysql $CLUSTER --type=merge --patch ' {"spec":
7
+ {"mysqlOpts":
8
+ {"mysqlConf": {"innodb_fast_shutdown":"0"}
9
+ }
10
+ }
11
+ }'
12
+
13
+ checkReadyOrClosed () {
14
+ kubectl get mysqlclusters.mysql.radondb.com -o jsonpath=' {.items[0].status.state}' 2> /dev/null | grep -q ' Ready' || kubectl get mysqlclusters.mysql.radondb.com -o jsonpath=' {.items[0].status.state}' 2> /dev/null | grep -q ' Closed'
15
+ }
16
+ checkStatefulSetUpdated () {
17
+ # it has ready
18
+ # get statefulset ready replicas
19
+ ready=$( kubectl get statefulsets.apps -o jsonpath=' {.items[0].status.readyReplicas}' 2> /dev/null)
20
+ updateVersion=$( kubectl get statefulsets.apps -o jsonpath=' {.items[0].status.updateRevision}' 2> /dev/null)
21
+ count=$( kubectl get pod -l " app.kubernetes.io/managed-by" =" mysql.radondb.com" -l " controller-revision-hash" =$updateVersion | awk ' NR>1{print $1}' | wc -l)
22
+ if [ $count -eq $ready ]; then
23
+ return 0
24
+ else
25
+ return 1
26
+ fi
27
+ }
28
+ waitReady () {
29
+ timeout=$1
30
+ SECONDS=0
31
+ echo -n Wating
32
+ until checkReadyOrClosed; do
33
+ sleep 2
34
+ echo -n " ."
35
+ if [ $SECONDS -gt $timeout ]; then
36
+ echo " timeout"
37
+ break
38
+ fi
39
+ done
40
+ echo
41
+ }
42
+
43
+ waitReady 30
44
+ until checkStatefulSetUpdated; do
45
+ echo " waiting for statefulset updated"
46
+ echo -n " ."
47
+ sleep 5
48
+ done
49
+ echo
50
+ pods=$( kubectl get pod -l " app.kubernetes.io/managed-by" =" mysql.radondb.com" | awk ' NR>1{print $1}' )
51
+ for p in $pods ; do
52
+ kubectl exec -it $p -c mysql -- bash << EOF
53
+ rm -rf /var/lib/mysql/ib_logfile*
54
+ EOF
55
+ done
56
+ kubectl patch mysql $CLUSTER --type=merge --patch " {\" spec\" :
57
+ {\" mysqlVersion\" : \" 8.0\" ,
58
+ \" podPolicy\" : {\" sidecarImage\" : \" $IMAGE \" }
59
+ }
60
+ }"
61
+
62
+ }
63
+
64
+ check () {
65
+ kubectl exec -it svc/$CLUSTER -leader -c mysql -- bash << EOF
66
+ mysqlcheck -u root -pRadonDB@123 --all-databases --check-upgrade
67
+ EOF
68
+ kubectl exec -it svc/$CLUSTER -leader -c mysql -- bash << EOF
69
+ mysql -uroot -pRadonDB@123 <<MOF
70
+ SELECT TABLE_SCHEMA, TABLE_NAME
71
+ FROM INFORMATION_SCHEMA.TABLES
72
+ WHERE ENGINE NOT IN ('innodb', 'ndbcluster')
73
+ AND CREATE_OPTIONS LIKE '%partitioned%';
74
+ MOF
75
+ EOF
76
+ # if has partition , alter them to innodb
77
+ # ALTER TABLE table_name ENGINE = INNODB;
78
+
79
+ # check the special table name in mysql57 information_schema
80
+ kubectl exec -it svc/$CLUSTER -leader -c mysql -- bash << EOF
81
+ mysql -uroot -pRadonDB@123 <<MOF
82
+ SELECT TABLE_SCHEMA, TABLE_NAME
83
+ FROM INFORMATION_SCHEMA.TABLES
84
+ WHERE LOWER(TABLE_SCHEMA) = 'mysql'
85
+ and LOWER(TABLE_NAME) IN
86
+ (
87
+ 'catalogs',
88
+ 'character_sets',
89
+ 'check_constraints',
90
+ 'collations',
91
+ 'column_statistics',
92
+ 'column_type_elements',
93
+ 'columns',
94
+ 'dd_properties',
95
+ 'events',
96
+ 'foreign_key_column_usage',
97
+ 'foreign_keys',
98
+ 'index_column_usage',
99
+ 'index_partitions',
100
+ 'index_stats',
101
+ 'indexes',
102
+ 'parameter_type_elements',
103
+ 'parameters',
104
+ 'resource_groups',
105
+ 'routines',
106
+ 'schemata',
107
+ 'st_spatial_reference_systems',
108
+ 'table_partition_values',
109
+ 'table_partitions',
110
+ 'table_stats',
111
+ 'tables',
112
+ 'tablespace_files',
113
+ 'tablespaces',
114
+ 'triggers',
115
+ 'view_routine_usage',
116
+ 'view_table_usage'
117
+ );
118
+ MOF
119
+ EOF
120
+
121
+ # if exist RENAME TABLE
122
+ # check the constraints name over 64
123
+ kubectl exec -it svc/$CLUSTER -leader -c mysql -- bash << EOF
124
+ mysql -uroot -pRadonDB@123 <<MOF
125
+ SELECT TABLE_SCHEMA, TABLE_NAME
126
+ FROM INFORMATION_SCHEMA.TABLES
127
+ WHERE TABLE_NAME IN
128
+ (SELECT LEFT(SUBSTR(ID,INSTR(ID,'/')+1),
129
+ INSTR(SUBSTR(ID,INSTR(ID,'/')+1),'_ibfk_')-1)
130
+ FROM INFORMATION_SCHEMA.INNODB_SYS_FOREIGN
131
+ WHERE LENGTH(SUBSTR(ID,INSTR(ID,'/')+1))>64);
132
+ MOF
133
+ EOF
134
+ # There must be no views with explicitly defined columns names that exceed 64 characters
135
+
136
+ # partitioned table
137
+ kubectl exec -it svc/$CLUSTER -leader -c mysql -- bash << EOF
138
+ mysql -uroot -pRadonDB@123 <<MOF
139
+ SELECT DISTINCT NAME, SPACE, SPACE_TYPE FROM INFORMATION_SCHEMA.INNODB_SYS_TABLES
140
+ WHERE NAME LIKE '%#P#%' AND SPACE_TYPE NOT LIKE 'Single';
141
+ MOF
142
+ EOF
143
+
144
+ # # ALTER TABLE table_name REORGANIZE PARTITION partition_name
145
+ # # INTO (partition_definition TABLESPACE=innodb_file_per_table);
146
+ # #
147
+
148
+ }
149
+
150
+ main () {
151
+ CHOICE=$1
152
+ CLUSTER=$2
153
+ IMAGE=$3
154
+ # choose the action
155
+ case $CHOICE in
156
+ " update" )
157
+ update
158
+ ;;
159
+ " check" )
160
+ check
161
+ ;;
162
+ * )
163
+ echo " Usage: $0 [update|check] [cluster name] [image name]"
164
+ ;;
165
+ esac
166
+
167
+ }
168
+ main " $@ "
0 commit comments