-
Notifications
You must be signed in to change notification settings - Fork 75
/
upgrade_test.sh
executable file
·262 lines (226 loc) · 8.04 KB
/
upgrade_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
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
#!/bin/bash
source ./tools/test.env
source ./test/endtoend/utils.sh
function move_tables() {
echo "Apply 201_customer_tablets.yaml"
kubectl apply -f 201_customer_tablets.yaml > /dev/null
sleep 300
checkPodStatusWithTimeout "example-vttablet-zone1(.*)3/3(.*)Running(.*)" 6
checkPodStatusWithTimeout "example-customer-x-x-zone1-vtorc(.*)1/1(.*)Running(.*)"
killall kubectl
./pf.sh > /dev/null 2>&1 &
waitForKeyspaceToBeServing customer - 2
sleep 10
vtctldclient LegacyVtctlCommand -- MoveTables --source commerce --tables 'customer,corder' Create customer.commerce2customer
if [ $? -ne 0 ]; then
echo "MoveTables failed"
printMysqlErrorFiles
exit 1
fi
sleep 10
vdiff_out=$(vtctldclient LegacyVtctlCommand -- VDiff customer.commerce2customer)
echo "$vdiff_out" | grep "ProcessedRows: 5" | wc -l | grep "2" > /dev/null
if [ $? -ne 0 ]; then
echo -e "VDiff output is invalid, got:\n$vdiff_out"
# Allow failure
fi
vtctldclient LegacyVtctlCommand -- MoveTables --tablet_types='rdonly,replica' SwitchTraffic customer.commerce2customer
if [ $? -ne 0 ]; then
echo "SwitchTraffic for rdonly and replica failed"
printMysqlErrorFiles
exit 1
fi
vtctldclient LegacyVtctlCommand -- MoveTables --tablet_types='primary' SwitchTraffic customer.commerce2customer
if [ $? -ne 0 ]; then
echo "SwitchTraffic for primary failed"
printMysqlErrorFiles
exit 1
fi
vtctldclient LegacyVtctlCommand -- MoveTables Complete customer.commerce2customer
if [ $? -ne 0 ]; then
echo "MoveTables Complete failed"
printMysqlErrorFiles
exit 1
fi
sleep 10
}
function resharding() {
echo "Create new schemas for new shards"
applySchemaWithRetry create_commerce_seq.sql commerce
sleep 4
vtctldclient ApplyVSchema --vschema-file="vschema_commerce_seq.json" commerce
if [ $? -ne 0 ]; then
echo "ApplyVschema commerce_seq during resharding failed"
printMysqlErrorFiles
exit 1
fi
sleep 4
vtctldclient ApplyVSchema --vschema-file="vschema_customer_sharded.json" customer
if [ $? -ne 0 ]; then
echo "ApplyVschema customer_sharded during resharding failed"
printMysqlErrorFiles
exit 1
fi
sleep 4
applySchemaWithRetry create_customer_sharded.sql customer
sleep 4
echo "Apply 302_new_shards.yaml"
kubectl apply -f 302_new_shards.yaml
checkPodStatusWithTimeout "example-vttablet-zone1(.*)3/3(.*)Running(.*)" 12
checkPodStatusWithTimeout "example-customer-80-x-zone1-vtorc(.*)1/1(.*)Running(.*)"
checkPodStatusWithTimeout "example-customer-x-80-zone1-vtorc(.*)1/1(.*)Running(.*)"
killall kubectl
./pf.sh > /dev/null 2>&1 &
sleep 5
waitForKeyspaceToBeServing customer -80 2
waitForKeyspaceToBeServing customer 80- 2
echo "Ready to reshard ..."
sleep 15
vtctldclient LegacyVtctlCommand -- Reshard --source_shards '-' --target_shards '-80,80-' Create customer.cust2cust
if [ $? -ne 0 ]; then
echo "Reshard Create failed"
printMysqlErrorFiles
exit 1
fi
sleep 15
vdiff_out=$(vtctldclient LegacyVtctlCommand -- VDiff customer.cust2cust)
echo "$vdiff_out" | grep "ProcessedRows: 5" | wc -l | grep "2" > /dev/null
if [ $? -ne 0 ]; then
echo -e "VDiff output is invalid, got:\n$vdiff_out"
# Allow failure
fi
vtctldclient LegacyVtctlCommand -- Reshard --tablet_types='rdonly,replica' SwitchTraffic customer.cust2cust
if [ $? -ne 0 ]; then
echo "Reshard SwitchTraffic for replica,rdonly failed"
printMysqlErrorFiles
exit 1
fi
vtctldclient LegacyVtctlCommand -- Reshard --tablet_types='primary' SwitchTraffic customer.cust2cust
if [ $? -ne 0 ]; then
echo "Reshard SwitchTraffic for primary failed"
printMysqlErrorFiles
exit 1
fi
sleep 10
assertSelect ../common/select_customer-80_data.sql "customer/-80" << EOF
Using customer/-80
Customer
+-------------+--------------------+
| customer_id | email |
+-------------+--------------------+
| 1 | alice@domain.com |
| 2 | bob@domain.com |
| 3 | charlie@domain.com |
| 5 | eve@domain.com |
+-------------+--------------------+
COrder
+----------+-------------+----------+-------+
| order_id | customer_id | sku | price |
+----------+-------------+----------+-------+
| 1 | 1 | SKU-1001 | 100 |
| 2 | 2 | SKU-1002 | 30 |
| 3 | 3 | SKU-1002 | 30 |
| 5 | 5 | SKU-1002 | 30 |
+----------+-------------+----------+-------+
EOF
assertSelect ../common/select_customer80-_data.sql "customer/80-" << EOF
Using customer/80-
Customer
+-------------+----------------+
| customer_id | email |
+-------------+----------------+
| 4 | dan@domain.com |
+-------------+----------------+
COrder
+----------+-------------+----------+-------+
| order_id | customer_id | sku | price |
+----------+-------------+----------+-------+
| 4 | 4 | SKU-1002 | 30 |
+----------+-------------+----------+-------+
EOF
# Complete the reshard process
vtctldclient LegacyVtctlCommand -- Reshard Complete customer.cust2cust
if [ $? -ne 0 ]; then
echo "Reshard Complete failed"
printMysqlErrorFiles
exit 1
fi
kubectl apply -f 306_down_shard_0.yaml
checkPodStatusWithTimeout "example-vttablet-zone1(.*)3/3(.*)Running(.*)" 9
waitForKeyspaceToBeServing customer -80 2
waitForKeyspaceToBeServing customer 80- 2
}
function waitAndVerifySetup() {
sleep 10
checkPodStatusWithTimeout "example-zone1-vtctld(.*)1/1(.*)Running(.*)"
checkPodStatusWithTimeout "example-zone1-vtgate(.*)1/1(.*)Running(.*)"
checkPodStatusWithTimeout "example-etcd(.*)1/1(.*)Running(.*)" 3
checkPodStatusWithTimeout "example-vttablet-zone1(.*)3/3(.*)Running(.*)" 3
checkPodStatusWithTimeout "example-commerce-x-x-zone1-vtorc(.*)1/1(.*)Running(.*)"
}
function upgradeToLatest() {
echo "Apply operator-latest.yaml "
kubectl apply -f operator-latest.yaml
waitAndVerifySetup
echo "Upgrade all the other binaries"
kubectl apply -f cluster_upgrade.yaml
waitAndVerifySetup
killall kubectl
./pf.sh > /dev/null 2>&1 &
sleep 10
assertSelect ../common/select_commerce_data.sql "commerce" << EOF
Using commerce
Customer
+-------------+--------------------+
| customer_id | email |
+-------------+--------------------+
| 1 | alice@domain.com |
| 2 | bob@domain.com |
| 3 | charlie@domain.com |
| 4 | dan@domain.com |
| 5 | eve@domain.com |
+-------------+--------------------+
Product
+----------+-------------+-------+
| sku | description | price |
+----------+-------------+-------+
| SKU-1001 | Monitor | 100 |
| SKU-1002 | Keyboard | 30 |
+----------+-------------+-------+
COrder
+----------+-------------+----------+-------+
| order_id | customer_id | sku | price |
+----------+-------------+----------+-------+
| 1 | 1 | SKU-1001 | 100 |
| 2 | 2 | SKU-1002 | 30 |
| 3 | 3 | SKU-1002 | 30 |
| 4 | 4 | SKU-1002 | 30 |
| 5 | 5 | SKU-1002 | 30 |
+----------+-------------+----------+-------+
EOF
}
# Test setup
echo "Building the docker image"
docker build -f build/Dockerfile.release -t vitess-operator-pr:latest .
echo "Creating Kind cluster"
kind create cluster --wait 30s --name kind-${BUILDKITE_BUILD_ID} --image ${KIND_VERSION}
echo "Loading docker image into Kind cluster"
kind load docker-image vitess-operator-pr:latest --name kind-${BUILDKITE_BUILD_ID}
cd "$PWD/test/endtoend/operator"
killall kubectl
setupKubectlAccessForCI
get_started "operator.yaml" "101_initial_cluster.yaml"
verifyVtGateVersion "21.0.0"
checkSemiSyncSetup
# Initially too durability policy should be specified
verifyDurabilityPolicy "commerce" "semi_sync"
upgradeToLatest
verifyVtGateVersion "22.0.0"
checkSemiSyncSetup
# After upgrading, we verify that the durability policy is still semi_sync
verifyDurabilityPolicy "commerce" "semi_sync"
move_tables
resharding
# Teardown
echo "Deleting Kind cluster. This also deletes the volume associated with it"
kind delete cluster --name kind-${BUILDKITE_BUILD_ID}