Skip to content

Commit ffef446

Browse files
committed
hack localtests/test.sh to run sysbench
1 parent d1f4a11 commit ffef446

File tree

3 files changed

+115
-59
lines changed

3 files changed

+115
-59
lines changed

localtests/sysbench/create.sql

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
DROP TABLE IF EXISTS `sbtest1`;
2+
CREATE TABLE `sbtest1` (
3+
`id` int NOT NULL AUTO_INCREMENT,
4+
`k` int NOT NULL DEFAULT '0',
5+
`c` char(120) NOT NULL DEFAULT '',
6+
`pad` char(60) NOT NULL DEFAULT '',
7+
PRIMARY KEY (`id`),
8+
KEY `k_1` (`k`)
9+
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

localtests/sysbench/generate_load

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
#!/usr/bin/env bash

localtests/test.sh

Lines changed: 105 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ ghost_binary=""
1414
docker=false
1515
storage_engine=innodb
1616
exec_command_file=/tmp/gh-ost-test.bash
17+
generate_load_file=/tmp/gh-ost-generate-load.bash
1718
ghost_structure_output_file=/tmp/gh-ost-test.ghost.structure.sql
1819
orig_content_output_file=/tmp/gh-ost-test.orig.content.csv
1920
ghost_content_output_file=/tmp/gh-ost-test.ghost.content.csv
@@ -24,33 +25,35 @@ master_port=
2425
replica_host=
2526
replica_port=
2627
original_sql_mode=
27-
docker=false
28+
gen_load_pid=0
2829

2930
OPTIND=1
30-
while getopts "b:s:d" OPTION
31-
do
31+
while getopts "b:s:d" OPTION; do
3232
case $OPTION in
33-
b)
34-
ghost_binary="$OPTARG";;
35-
s)
36-
storage_engine="$OPTARG";;
37-
d)
38-
docker=true;;
33+
b)
34+
ghost_binary="$OPTARG"
35+
;;
36+
s)
37+
storage_engine="$OPTARG"
38+
;;
39+
d)
40+
docker=true
41+
;;
3942
esac
4043
done
41-
shift $((OPTIND-1))
44+
shift $((OPTIND - 1))
4245

4346
test_pattern="${1:-.}"
4447

4548
verify_master_and_replica() {
46-
if [ "$(gh-ost-test-mysql-master -e "select 1" -ss)" != "1" ] ; then
49+
if [ "$(gh-ost-test-mysql-master -e "select 1" -ss)" != "1" ]; then
4750
echo "Cannot verify gh-ost-test-mysql-master"
4851
exit 1
4952
fi
50-
read master_host master_port <<< $(gh-ost-test-mysql-master -e "select @@hostname, @@port" -ss)
53+
read master_host master_port <<<$(gh-ost-test-mysql-master -e "select @@hostname, @@port" -ss)
5154
[ "$master_host" == "$(hostname)" ] && master_host="127.0.0.1"
5255
echo "# master verified at $master_host:$master_port"
53-
if ! gh-ost-test-mysql-master -e "set global event_scheduler := 1" ; then
56+
if ! gh-ost-test-mysql-master -e "set global event_scheduler := 1"; then
5457
echo "Cannot enable event_scheduler on master"
5558
exit 1
5659
fi
@@ -60,22 +63,22 @@ verify_master_and_replica() {
6063
echo "Gracefully sleeping for 3 seconds while replica is setting up..."
6164
sleep 3
6265

63-
if [ "$(gh-ost-test-mysql-replica -e "select 1" -ss)" != "1" ] ; then
66+
if [ "$(gh-ost-test-mysql-replica -e "select 1" -ss)" != "1" ]; then
6467
echo "Cannot verify gh-ost-test-mysql-replica"
6568
exit 1
6669
fi
67-
if [ "$(gh-ost-test-mysql-replica -e "select @@global.binlog_format" -ss)" != "ROW" ] ; then
70+
if [ "$(gh-ost-test-mysql-replica -e "select @@global.binlog_format" -ss)" != "ROW" ]; then
6871
echo "Expecting test replica to have binlog_format=ROW"
6972
exit 1
7073
fi
71-
read replica_host replica_port <<< $(gh-ost-test-mysql-replica -e "select @@hostname, @@port" -ss)
74+
read replica_host replica_port <<<$(gh-ost-test-mysql-replica -e "select @@hostname, @@port" -ss)
7275
[ "$replica_host" == "$(hostname)" ] && replica_host="127.0.0.1"
7376
echo "# replica verified at $replica_host:$replica_port"
7477
}
7578

7679
exec_cmd() {
7780
echo "$@"
78-
command "$@" 1> $test_logfile 2>&1
81+
command "$@" 1>$test_logfile 2>&1
7982
return $?
8083
}
8184

@@ -84,7 +87,7 @@ echo_dot() {
8487
}
8588

8689
start_replication() {
87-
mysql_version="$(gh-ost-test-mysql-replica -e "select @@version")"
90+
mysql_version="$(gh-ost-test-mysql-replica -e "select @@version")"
8891
if [[ $mysql_version =~ "8.4" ]]; then
8992
seconds_behind_source="Seconds_Behind_Source"
9093
replica_terminology="replica"
@@ -95,9 +98,9 @@ start_replication() {
9598
gh-ost-test-mysql-replica -e "stop $replica_terminology; start $replica_terminology;"
9699

97100
num_attempts=0
98-
while gh-ost-test-mysql-replica -e "show $replica_terminology status\G" | grep $seconds_behind_source | grep -q NULL ; do
99-
((num_attempts=num_attempts+1))
100-
if [ $num_attempts -gt 10 ] ; then
101+
while gh-ost-test-mysql-replica -e "show $replica_terminology status\G" | grep $seconds_behind_source | grep -q NULL; do
102+
((num_attempts = num_attempts + 1))
103+
if [ $num_attempts -gt 10 ]; then
101104
echo
102105
echo "ERROR replication failure"
103106
exit 1
@@ -107,6 +110,31 @@ start_replication() {
107110
done
108111
}
109112

113+
generate_load_cmd() {
114+
local mysql_host="$1"
115+
local mysql_port="$2"
116+
cmd="sysbench oltp_write_only \
117+
--mysql-host="$mysql_host" \
118+
--mysql-port="$mysql_port" \
119+
--mysql-user=root \
120+
--mysql-password=opensesame \
121+
--mysql-db=test \
122+
--table-size=100000 \
123+
--tables=1 \
124+
--threads=8 \
125+
--time=60 \
126+
--report-interval=10 \
127+
--rate=200 \
128+
run"
129+
echo $cmd
130+
}
131+
132+
cleanup() {
133+
if [ $gen_load_pid -gt 0 ]; then
134+
kill $gen_load_pid
135+
fi
136+
}
137+
110138
test_single() {
111139
local test_name
112140
test_name="$1"
@@ -118,14 +146,14 @@ test_single() {
118146
replica_port="3308"
119147
fi
120148

121-
if [ -f $tests_path/$test_name/ignore_versions ] ; then
149+
if [ -f $tests_path/$test_name/ignore_versions ]; then
122150
ignore_versions=$(cat $tests_path/$test_name/ignore_versions)
123151
mysql_version=$(gh-ost-test-mysql-master -s -s -e "select @@version")
124152
mysql_version_comment=$(gh-ost-test-mysql-master -s -s -e "select @@version_comment")
125-
if echo "$mysql_version" | egrep -q "^${ignore_versions}" ; then
153+
if echo "$mysql_version" | egrep -q "^${ignore_versions}"; then
126154
echo -n "Skipping: $test_name"
127155
return 0
128-
elif echo "$mysql_version_comment" | egrep -i -q "^${ignore_versions}" ; then
156+
elif echo "$mysql_version_comment" | egrep -i -q "^${ignore_versions}"; then
129157
echo -n "Skipping: $test_name"
130158
return 0
131159
fi
@@ -137,56 +165,73 @@ test_single() {
137165
start_replication
138166
echo_dot
139167

140-
if [ -f $tests_path/$test_name/sql_mode ] ; then
168+
if [ -f $tests_path/$test_name/sql_mode ]; then
141169
gh-ost-test-mysql-master --default-character-set=utf8mb4 test -e "set @@global.sql_mode='$(cat $tests_path/$test_name/sql_mode)'"
142170
gh-ost-test-mysql-replica --default-character-set=utf8mb4 test -e "set @@global.sql_mode='$(cat $tests_path/$test_name/sql_mode)'"
143171
fi
144172

145-
gh-ost-test-mysql-master --default-character-set=utf8mb4 test < $tests_path/$test_name/create.sql
173+
gh-ost-test-mysql-master --default-character-set=utf8mb4 test <$tests_path/$test_name/create.sql
146174
test_create_result=$?
147175

148-
if [ $test_create_result -ne 0 ] ; then
176+
if [ $test_create_result -ne 0 ]; then
149177
echo
150178
echo "ERROR $test_name create failure. cat $tests_path/$test_name/create.sql:"
151179
cat $tests_path/$test_name/create.sql
152180
return 1
153181
fi
154182

155183
extra_args=""
156-
if [ -f $tests_path/$test_name/extra_args ] ; then
184+
if [ -f $tests_path/$test_name/extra_args ]; then
157185
extra_args=$(cat $tests_path/$test_name/extra_args)
158186
fi
159187
orig_columns="*"
160188
ghost_columns="*"
161189
order_by=""
162-
if [ -f $tests_path/$test_name/orig_columns ] ; then
190+
if [ -f $tests_path/$test_name/orig_columns ]; then
163191
orig_columns=$(cat $tests_path/$test_name/orig_columns)
164192
fi
165-
if [ -f $tests_path/$test_name/ghost_columns ] ; then
193+
if [ -f $tests_path/$test_name/ghost_columns ]; then
166194
ghost_columns=$(cat $tests_path/$test_name/ghost_columns)
167195
fi
168-
if [ -f $tests_path/$test_name/order_by ] ; then
196+
if [ -f $tests_path/$test_name/order_by ]; then
169197
order_by="order by $(cat $tests_path/$test_name/order_by)"
170198
fi
171199
# graceful sleep for replica to catch up
172200
echo_dot
173201
sleep 1
174-
#
202+
203+
table_name="gh_ost_test"
204+
205+
# run gh-ost with sysbench write load
206+
trap cleanup EXIT INT TERM
207+
if [[ "$test_name" == "sysbench" ]]; then
208+
table_name="sbtest1"
209+
load_cmd="$(generate_load_cmd $master_host $master_port)"
210+
echo $load_cmd >$generate_load_file
211+
bash $generate_load_file 1>$test_logfile 2>&1 &
212+
gen_load_pid=$!
213+
echo
214+
echo "Started sysbench (PID $gen_load_pid)"
215+
echo $load_cmd
216+
fi
217+
218+
ghost_table_name="_${table_name}_gho"
219+
175220
cmd="$ghost_binary \
176221
--user=gh-ost \
177222
--password=gh-ost \
178223
--host=$replica_host \
179224
--port=$replica_port \
180225
--assume-master-host=${master_host}:${master_port}
181226
--database=test \
182-
--table=gh_ost_test \
227+
--table=${table_name} \
183228
--storage-engine=${storage_engine} \
184229
--alter='engine=${storage_engine}' \
185230
--exact-rowcount \
186231
--assume-rbr \
187232
--initially-drop-old-table \
188233
--initially-drop-ghost-table \
189-
--throttle-query='select timestampdiff(second, min(last_update), now()) < 5 from _gh_ost_test_ghc' \
234+
--throttle-query='select timestampdiff(second, min(last_update), now()) < 5 from _${table_name}_ghc' \
190235
--throttle-flag-file=$throttle_flag_file \
191236
--serve-socket-file=/tmp/gh-ost.test.sock \
192237
--initially-drop-socket-file \
@@ -198,32 +243,33 @@ test_single() {
198243
--stack \
199244
--execute ${extra_args[@]}"
200245
echo_dot
201-
echo $cmd > $exec_command_file
246+
echo $cmd >$exec_command_file
202247
echo_dot
203-
bash $exec_command_file 1> $test_logfile 2>&1
248+
249+
bash $exec_command_file 1>$test_logfile 2>&1
204250

205251
execution_result=$?
206252

207-
if [ -f $tests_path/$test_name/sql_mode ] ; then
253+
if [ -f $tests_path/$test_name/sql_mode ]; then
208254
gh-ost-test-mysql-master --default-character-set=utf8mb4 test -e "set @@global.sql_mode='${original_sql_mode}'"
209255
gh-ost-test-mysql-replica --default-character-set=utf8mb4 test -e "set @@global.sql_mode='${original_sql_mode}'"
210256
fi
211257

212-
if [ -f $tests_path/$test_name/destroy.sql ] ; then
213-
gh-ost-test-mysql-master --default-character-set=utf8mb4 test < $tests_path/$test_name/destroy.sql
258+
if [ -f $tests_path/$test_name/destroy.sql ]; then
259+
gh-ost-test-mysql-master --default-character-set=utf8mb4 test <$tests_path/$test_name/destroy.sql
214260
fi
215261

216-
if [ -f $tests_path/$test_name/expect_failure ] ; then
217-
if [ $execution_result -eq 0 ] ; then
262+
if [ -f $tests_path/$test_name/expect_failure ]; then
263+
if [ $execution_result -eq 0 ]; then
218264
echo
219265
echo "ERROR $test_name execution was expected to exit on error but did not. cat $test_logfile"
220266
return 1
221267
fi
222-
if [ -s $tests_path/$test_name/expect_failure ] ; then
268+
if [ -s $tests_path/$test_name/expect_failure ]; then
223269
# 'expect_failure' file has content. We expect to find this content in the log.
224270
expected_error_message="$(cat $tests_path/$test_name/expect_failure)"
225-
if grep -q "$expected_error_message" $test_logfile ; then
226-
return 0
271+
if grep -q "$expected_error_message" $test_logfile; then
272+
return 0
227273
fi
228274
echo
229275
echo "ERROR $test_name execution was expected to exit with error message '${expected_error_message}' but did not. cat $test_logfile"
@@ -233,18 +279,18 @@ test_single() {
233279
return 0
234280
fi
235281

236-
if [ $execution_result -ne 0 ] ; then
282+
if [ $execution_result -ne 0 ]; then
237283
echo
238284
echo "ERROR $test_name execution failure. cat $test_logfile:"
239285
cat $test_logfile
240286
return 1
241287
fi
242288

243-
gh-ost-test-mysql-replica --default-character-set=utf8mb4 test -e "show create table _gh_ost_test_gho\G" -ss > $ghost_structure_output_file
289+
gh-ost-test-mysql-replica --default-character-set=utf8mb4 test -e "show create table ${ghost_table_name}\G" -ss >$ghost_structure_output_file
244290

245-
if [ -f $tests_path/$test_name/expect_table_structure ] ; then
291+
if [ -f $tests_path/$test_name/expect_table_structure ]; then
246292
expected_table_structure="$(cat $tests_path/$test_name/expect_table_structure)"
247-
if ! grep -q "$expected_table_structure" $ghost_structure_output_file ; then
293+
if ! grep -q "$expected_table_structure" $ghost_structure_output_file; then
248294
echo
249295
echo "ERROR $test_name: table structure was expected to include ${expected_table_structure} but did not. cat $ghost_structure_output_file:"
250296
cat $ghost_structure_output_file
@@ -253,14 +299,14 @@ test_single() {
253299
fi
254300

255301
echo_dot
256-
gh-ost-test-mysql-replica --default-character-set=utf8mb4 test -e "select ${orig_columns} from gh_ost_test ${order_by}" -ss > $orig_content_output_file
257-
gh-ost-test-mysql-replica --default-character-set=utf8mb4 test -e "select ${ghost_columns} from _gh_ost_test_gho ${order_by}" -ss > $ghost_content_output_file
302+
gh-ost-test-mysql-replica --default-character-set=utf8mb4 test -e "select ${orig_columns} from ${table_name} ${order_by}" -ss >$orig_content_output_file
303+
gh-ost-test-mysql-replica --default-character-set=utf8mb4 test -e "select ${ghost_columns} from ${ghost_table_name} ${order_by}" -ss >$ghost_content_output_file
258304
orig_checksum=$(cat $orig_content_output_file | md5sum)
259305
ghost_checksum=$(cat $ghost_content_output_file | md5sum)
260306

261-
if [ "$orig_checksum" != "$ghost_checksum" ] ; then
262-
gh-ost-test-mysql-replica --default-character-set=utf8mb4 test -e "select ${orig_columns} from gh_ost_test" -ss > $orig_content_output_file
263-
gh-ost-test-mysql-replica --default-character-set=utf8mb4 test -e "select ${ghost_columns} from _gh_ost_test_gho" -ss > $ghost_content_output_file
307+
if [ "$orig_checksum" != "$ghost_checksum" ]; then
308+
gh-ost-test-mysql-replica --default-character-set=utf8mb4 test -e "select ${orig_columns} from ${table_name}" -ss >$orig_content_output_file
309+
gh-ost-test-mysql-replica --default-character-set=utf8mb4 test -e "select ${ghost_columns} from ${ghost_table_name}" -ss >$ghost_content_output_file
264310
echo "ERROR $test_name: checksum mismatch"
265311
echo "---"
266312
diff $orig_content_output_file $ghost_content_output_file
@@ -275,14 +321,14 @@ build_binary() {
275321
echo "Building"
276322
rm -f $default_ghost_binary
277323
[ "$ghost_binary" == "" ] && ghost_binary="$default_ghost_binary"
278-
if [ -f "$ghost_binary" ] ; then
324+
if [ -f "$ghost_binary" ]; then
279325
echo "Using binary: $ghost_binary"
280326
return 0
281327
fi
282328

283329
go build -o $ghost_binary go/cmd/gh-ost/main.go
284330

285-
if [ $? -ne 0 ] ; then
331+
if [ $? -ne 0 ]; then
286332
echo "Build failure"
287333
exit 1
288334
fi
@@ -293,22 +339,22 @@ test_all() {
293339
test_dirs=$(find "$tests_path" -mindepth 1 -maxdepth 1 ! -path . -type d | grep "$test_pattern" | sort)
294340
while read -r test_dir; do
295341
test_name=$(basename "$test_dir")
296-
if ! test_single "$test_name" ; then
342+
if ! test_single "$test_name"; then
297343
create_statement=$(gh-ost-test-mysql-replica test -t -e "show create table _gh_ost_test_gho \G")
298-
echo "$create_statement" >> $test_logfile
344+
echo "$create_statement" >>$test_logfile
299345
echo "+ FAIL"
300346
return 1
301347
else
302348
echo
303349
echo "+ pass"
304350
fi
305-
mysql_version="$(gh-ost-test-mysql-replica -e "select @@version")"
351+
mysql_version="$(gh-ost-test-mysql-replica -e "select @@version")"
306352
replica_terminology="slave"
307353
if [[ $mysql_version =~ "8.4" ]]; then
308354
replica_terminology="replica"
309355
fi
310356
gh-ost-test-mysql-replica -e "start $replica_terminology"
311-
done <<< "$test_dirs"
357+
done <<<"$test_dirs"
312358
}
313359

314360
verify_master_and_replica

0 commit comments

Comments
 (0)