-
Notifications
You must be signed in to change notification settings - Fork 21
/
router-docker_test.sh
executable file
·213 lines (147 loc) · 5.17 KB
/
router-docker_test.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
#!/bin/bash
if [ $# -eq 0 ];
then
echo "$0: Missing arguments"
exit 1
elif [ $# -gt 2 ];
then
echo "$0: Too many arguments: $@"
exit 1
else
echo "We got some argument(s)"
echo "==========================="
echo "Number of arguments.: $#"
echo "List of arguments...: $@"
echo "Arg #1..............: $1"
echo "Arg #2..............: $2"
echo "==========================="
fi
set -xe
cleanup(){
sudo docker stop mysql1 mysql2 mysql3 mysql4 mysql-client mysql-router || true
sudo docker rm mysql1 mysql2 mysql3 mysql4 mysql-client mysql-router || true
sudo docker network rm innodbnet || true
rm -rf cluster1.json cluster.json || true
}
create_network(){
sudo docker network create innodbnet
}
create_mysql_config(){
for N in 1 2 3 4
do cat <<EOF > my$N.cnf
[mysqld]
plugin_load_add='group_replication.so'
EOF
echo "server_id=$(echo $[ $RANDOM % 40 + 10 ])" >> my$N.cnf
cat <<EOF >> my$N.cnf
binlog_checksum=NONE
enforce_gtid_consistency=ON
gtid_mode=ON
relay_log={{ ansible_hostname }}-relay-bin
innodb_dedicated_server=ON
binlog_transaction_dependency_tracking=WRITESET
slave_preserve_commit_order=ON
slave_parallel_type=LOGICAL_CLOCK
transaction_write_set_extraction=XXHASH64
EOF
done
}
start_mysql_containers(){
for N in 1 2 3 4
do sudo docker run -d --name=mysql$N --hostname=mysql$N --net=innodbnet \
-v $PWD/my$N.cnf:/etc/my.cnf \
-e MYSQL_ROOT_PASSWORD=root $1 \
-e PERCONA_TELEMETRY_URL=https://check-dev.percona.com/v1/telemetry/GenericReport
done
sleep 60
}
create_new_user(){
for N in 1 2 3 4
do sudo docker exec -it mysql$N mysql -uroot -proot \
-e "CREATE USER 'inno'@'%' IDENTIFIED BY 'inno';" \
-e "GRANT ALL privileges ON *.* TO 'inno'@'%' with grant option;" \
-e "reset master;"
done
sleep 30
}
verify_new_user(){
for N in 1 2 3 4
do sudo docker exec -it mysql$N mysql -uinno -pinno \
-e "SHOW VARIABLES WHERE Variable_name = 'hostname';" \
-e "SELECT user FROM mysql.user where user = 'inno';"
done
sleep 30
}
docker_restart(){
sudo docker restart mysql1 mysql2 mysql3 mysql4
sleep 10
}
create_cluster(){
sudo docker exec -it mysql1 mysqlsh -uinno -pinno -- dba create-cluster testCluster
}
add_slave(){
sudo docker exec -it mysql1 mysqlsh -uinno -pinno -- cluster add-instance --uri=inno@mysql2 --recoveryMethod=incremental
sleep 10
sudo docker exec -it mysql1 mysqlsh -uinno -pinno -- cluster add-instance --uri=inno@mysql3 --recoveryMethod=incremental
sleep 10
sudo docker exec -it mysql1 mysqlsh -uinno -pinno -- cluster add-instance --uri=inno@mysql4 --recoveryMethod=incremental
sleep 10
}
Router_Bootstrap(){
sudo docker run -d --name mysql-router --net=innodbnet -e MYSQL_HOST=mysql1 -e MYSQL_PORT=3306 -e MYSQL_USER=inno -e MYSQL_PASSWORD=inno -e MYSQL_INNODB_CLUSTER_MEMBERS=4 $1
}
data_add(){
sudo docker run -d --name=mysql-client --hostname=mysql-client --net=innodbnet -e MYSQL_ROOT_PASSWORD=root -e PERCONA_TELEMETRY_URL=https://check-dev.percona.com/v1/telemetry/GenericReport $1
sleep 10
echo "Adding sbtest user"
sudo docker exec -it mysql-client mysql -h mysql-router -P 6446 -uinno -pinno \
-e "CREATE SCHEMA sbtest; CREATE USER sbtest@'%' IDENTIFIED with mysql_native_password by 'password';" \
-e "GRANT ALL PRIVILEGES ON sbtest.* to sbtest@'%';"
echo "Verify sbtest user"
sudo docker exec -it mysql-client mysql -h mysql-router -P 6447 -uinno -pinno -e "select host , user from mysql.user where user='sbtest';"
sleep 5
echo "sysbench run"
sudo docker run --rm=true --net=innodbnet --name=sb-prepare severalnines/sysbench sysbench --db-driver=mysql --table-size=10000 --tables=1 --threads=1 --mysql-host=mysql-router --mysql-port=6446--mysql-user=sbtest --mysql-password=password /usr/share/sysbench/oltp_insert.lua prepare
sleep 20
echo "verify if data is inserted or not"
sudo docker exec -it mysql-client mysql -h mysql-router -P 6447 -uinno -pinno -e "SELECT count(*) from sbtest.sbtest1;"
}
verify_replication(){
for N in 1 2 3 4;
do
sudo docker exec -it mysql$N mysql -uinno -pinno -e "SHOW VARIABLES WHERE Variable_name = 'hostname';" -e "SELECT count(*) from sbtest.sbtest1;";
done
}
Fault_tolerance(){
echo "Stop One node"
sudo docker stop mysql1
sleep 10
echo "check status"
sudo docker exec -it mysql-client mysqlsh -h mysql-router -P 6446 -uinno -pinno -- cluster status >> cluster1.json
sed '1d' cluster1.json >> cluster.json
status=$(jq -r '.defaultReplicaSet.status' cluster.json)
echo $status
}
verify_status(){
if [[ "${status}" = "OK_PARTIAL" ]]; then
echo "Innodb cluster looks good"
exit 0
else
echo "Issue in Innodb Cluster"
exit 1
fi
}
cleanup
create_network
create_mysql_config
start_mysql_containers $1
create_new_user
verify_new_user
docker_restart
create_cluster
add_slave
Router_Bootstrap $2
data_add $1
verify_replication
Fault_tolerance
verify_status