forked from mydumper/mydumper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_mydumper.sh
executable file
·453 lines (411 loc) · 13.9 KB
/
test_mydumper.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
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
#!/bin/bash
mydumper_log="/tmp/test_mydumper.log"
tmp_mydumper_log="/tmp/test_mydumper.log.tmp"
myloader_log="/tmp/test_myloader.log"
tmp_myloader_log="/tmp/test_myloader.log.tmp"
mydumper_stor_dir="/tmp/data"
mysqldumplog=/tmp/mysqldump.sql
myloader_stor_dir=$mydumper_stor_dir
stream_stor_dir="/tmp/stream_data"
die()
{
[ -n "$1" ] && echo "$1" >&2;
exit 1
}
finish()
{
echo "Test finished successfully!"
exit 0
}
if [ -x ./mydumper -a -x ./myloader ]
then
mydumper="./mydumper"
myloader="./myloader"
else
mydumper=`which mydumper` ||
die "mydumper not found!"
myloader=`which myloader` ||
die "myloader not found!"
fi
mysqldump_exe=`which mariadb-dump` ||
mysqldump_exe=`which mysqldump` ||
die "mysqldump client not found!"
mysql_exe=`which mariadb` ||
mysql_exe=`which mysql` ||
die "mysql client not found!"
if [ -z "$MYSQLX_UNIX_PORT" -a -z "$MYSQL_UNIX_PORT" ]
then
for d in /var/lib/mysql /var/run /tmp
do
if [ -S $d/mysqlx.sock ]; then
export MYSQLX_UNIX_PORT=$d/mysqlx.sock
echo "X socket: $MYSQLX_UNIX_PORT"
fi
if [ -S $d/mysql.sock ]; then
export MYSQL_UNIX_PORT=$d/mysql.sock
echo "Socket: $MYSQL_UNIX_PORT"
break
elif [ -S $d/mysqld.sock ]; then
export MYSQL_UNIX_PORT=$d/mysqld.sock
echo "Socket: $MYSQL_UNIX_PORT"
break
fi
done
fi
if [ -z "$MYSQLX_UNIX_PORT" -a -z "$MYSQL_UNIX_PORT" ]
then
export MYSQL_HOST=127.0.0.1
export MYSQL_TCP_PORT=3306
echo "Using TCP connection to $MYSQL_HOST:$MYSQL_TCP_PORT"
fi
mysqldump()
{
# mysqldump doesn't respect $MYSQL_HOST
local host_arg=${MYSQL_HOST:+-h $MYSQL_HOST}
$mysqldump_exe --no-defaults $host_arg -f -uroot "$@" || exit
}
export -f mysqldump
mysql()
{
# mysql seems to respect $MYSQL_HOST
$mysql_exe --no-defaults -f -uroot "$@" || exit
}
export -f mysql
# LD_PRELOAD=/usr/lib/x86_64-linux-gnu/libjemalloc.so
# export LD_PRELOAD
export G_DEBUG=fatal-criticals
> $mydumper_log
> $myloader_log
optstring_long="case:,rr-myloader,rr-mydumper,debug,prepare"
optstring_short="c:LDd"
opts=$(getopt -o "${optstring_short}" --long "${optstring_long}" --name "$0" -- "$@") ||
exit $?
eval set -- "$opts"
unset prepare_only
unset case_num
unset case_repeat
unset rr_myloader
unset rr_mydumper
log_level="-v 4"
while true
do
case "$1" in
-c|--case)
if [[ "$2" == *:* ]]
then
case_repeat=${2##*:}
[[ case_repeat -lt 1 ]] &&
case_repeat=$(printf "%u/2\n" -2 | bc) # infinity (almost)
fi
case_num=${2%%:*}
case_num=${case_num###}
echo "Executing test case: #${case_num}${case_repeat:+ for $case_repeat times} "
case_repeat=${case_repeat:-1}
shift 2;;
-L|--rr-myloader)
myloader="rr record $myloader"
shift;;
-D|--rr-mydumper)
mydumper="rr record $mydumper"
shift;;
-d|--debug)
log_level="--debug"
shift;;
--prepare)
prepare_only=1
shift;;
--) shift; break;;
esac
done
for i in $*
do
if [ "$($mydumper --version | grep "$i" | wc -l)" != "1" ]
then
exit 1
fi
if [ "$($myloader --version | grep "$i" | wc -l)" != "1" ]
then
exit 1
fi
done
if [ -x /usr/bin/time ]
then
declare -a time2=(/usr/bin/time -f 'real: %e; usr: %U; sys: %S; data: %D; faults: %F; rfaults: %R; fsi: %I; fso: %O; socki: %r; socko: %s; mem: %K; rss_avg: %t; rss_max: %M; shared: %X; stack: %p; cpu: %P; swaps: %W; ctx0: %c; ctx1: %w; sigs: %k; ret: %x')
else
declare -a time2=(time -p)
fi
ulimit -c unlimited
core_pattern=$(cat /proc/sys/kernel/core_pattern)
echo "Core pattern: $core_pattern"
echo "Core limit: $(ulimit -c)"
print_core()
{
[[ -n "$(which gdb 2> /dev/null)" && "$core_pattern" =~ ^core ]] ||
return
local core=$(find . -name "core*" -print -quit)
if [ -n "$core" ]
then
gdb -q --batch -c $core $mydumper -ex "set print frame-arguments all" -ex "bt full"
rm -f "$core"
fi
}
backtrace ()
{
echo "Backtrace is:"
local i=0
while caller $i
do
i=$((i+1))
done
}
test_case_dir (){
# Test case
# We should consider each test case, with different mydumper/myloader parameters
s=$*
echo "Case #${number}${case_cycle:+:$case_cycle}"
mydumper_parameters=${s%%"-- "*}
myloader_parameters=${s#*"-- "}
if [ "${mydumper_parameters}" != "" ]
then
# Prepare
rm -rf ${mydumper_stor_dir}
mkdir -p ${mydumper_stor_dir}
# Export
echo "Exporting database: ${mydumper_parameters}"
rm -rf /tmp/fifodir
"${time2[@]}" $mydumper -u root -M $log_level -L $tmp_mydumper_log ${mydumper_parameters}
error=$?
cat $tmp_mydumper_log >> $mydumper_log
if (( $error > 0 ))
then
print_core
echo "Retrying export due error"
echo "Exporting database: ${mydumper_parameters}"
rm -rf /tmp/fifodir
rm -rf ${mydumper_stor_dir} ${myloader_stor_dir}
$mydumper -u root -M $log_level -L $tmp_mydumper_log ${mydumper_parameters}
error=$?
cat $tmp_mydumper_log >> $mydumper_log
if (( $error > 0 ))
then
print_core
mysqldump --all-databases > $mysqldumplog
echo "Error running: $mydumper -u root -M $log_level -L $mydumper_log ${mydumper_parameters}"
cat $tmp_mydumper_log
mv $tmp_mydumper_log $mydumper_stor_dir
backtrace
exit $error
fi
fi
fi
if [ "$PARTIAL" != "1" ]
then
echo "DROP DATABASE IF EXISTS sakila;
DROP DATABASE IF EXISTS myd_test;
DROP DATABASE IF EXISTS myd_test_no_fk;
DROP DATABASE IF EXISTS empty_db;" | mysql
fi
if [ "${myloader_parameters}" != "" ]
then
# Import
echo "Importing database: ${myloader_parameters}"
mysqldump --all-databases > $mysqldumplog
rm -rf /tmp/fifodir
"${time2[@]}" $myloader -u root $log_level -L $tmp_myloader_log ${myloader_parameters}
error=$?
cat $tmp_myloader_log >> $myloader_log
if (( $error > 0 ))
then
print_core
echo "Retrying import due error"
echo "Importing database: ${myloader_parameters}"
mysqldump --all-databases > $mysqldumplog
rm -rf /tmp/fifodir
$myloader -u root $log_level -L $tmp_myloader_log ${myloader_parameters}
error=$?
cat $tmp_myloader_log >> $myloader_log
if (( $error > 0 ))
then
print_core
mv $mysqldumplog $mydumper_stor_dir
echo "Error running: $myloader -u root $log_level -L $myloader_log ${myloader_parameters}"
echo "Error running myloader with mydumper: $mydumper -u root -M $log_level -L $mydumper_log ${mydumper_parameters}"
cat $tmp_mydumper_log
cat $tmp_myloader_log
mv $tmp_mydumper_log $mydumper_stor_dir
mv $tmp_myloader_log $mydumper_stor_dir
backtrace
exit $error
fi
fi
fi
}
test_case_stream (){
# Test case
# We should consider each test case, with different mydumper/myloader parameters
s=$*
echo "Case #${number}${case_cycle:+:$case_cycle}"
mydumper_parameters=${s%%"-- "*}
myloader_parameters=${s#*"-- "}
if [ "${mydumper_parameters}" != "" ] && [ "${myloader_parameters}" != "" ]
then
# Prepare
rm -rf ${mydumper_stor_dir} ${myloader_stor_dir}
mkdir -p ${mydumper_stor_dir} ${myloader_stor_dir}
# Export
echo "Exporting database: $mydumper --stream -u root -M $log_level -L $tmp_mydumper_log ${mydumper_parameters} | $myloader ${myloader_general_options} -u root $log_level -L $tmp_myloader_log ${myloader_parameters} --stream"
rm -rf /tmp/fifodir
"${time2[@]}" $mydumper --stream -u root -M $log_level -L $tmp_mydumper_log ${mydumper_parameters} > /tmp/stream.sql
error=$?
mysqldump --all-databases > $mysqldumplog
if (( $error > 0 ))
then
echo "Retrying export due error"
echo "Exporting database: $mydumper --stream -u root -M $log_level -L $tmp_mydumper_log ${mydumper_parameters} | $myloader ${myloader_general_options} -u root $log_level -L $tmp_myloader_log ${myloader_parameters} --stream"
rm -rf ${mydumper_stor_dir} ${myloader_stor_dir}
rm -rf /tmp/fifodir
$mydumper --stream -u root -M $log_level -L $tmp_mydumper_log ${mydumper_parameters} > /tmp/stream.sql
error=$?
mysqldump --all-databases > $mysqldumplog
if (( $error > 0 ))
then
echo "Error running: $mydumper --stream -u root -M $log_level -L $mydumper_log ${mydumper_parameters}"
cat $tmp_mydumper_log
mv $tmp_mydumper_log $mydumper_stor_dir
backtrace
exit $error
fi
fi
if [ "$PARTIAL" != "1" ]
then
echo "DROP DATABASE IF EXISTS sakila;
DROP DATABASE IF EXISTS myd_test;
DROP DATABASE IF EXISTS myd_test_no_fk;
DROP DATABASE IF EXISTS empty_db;" | mysql
fi
rm -rf /tmp/fifodir
cat /tmp/stream.sql | $myloader ${myloader_general_options} -u root $log_level -L $tmp_myloader_log ${myloader_parameters} --stream
error=$?
cat $tmp_myloader_log >> $myloader_log
cat $tmp_mydumper_log >> $mydumper_log
if (( $error > 0 ))
then
echo "Retrying import due error"
rm -rf /tmp/fifodir
cat /tmp/stream.sql | $myloader ${myloader_general_options} -u root $log_level -L $tmp_myloader_log ${myloader_parameters} --stream
error=$?
cat $tmp_myloader_log >> $myloader_log
cat $tmp_mydumper_log >> $mydumper_log
if (( $error > 0 ))
then
mv $mysqldumplog $mydumper_stor_dir
echo "Error running: $mydumper --stream -u root -M $log_level -L $mydumper_log ${mydumper_parameters}"
echo "Error running: $myloader ${myloader_general_options} -u root $log_level -L $myloader_log ${myloader_parameters} --stream"
cat $tmp_mydumper_log
cat $tmp_myloader_log
mv $tmp_mydumper_log $mydumper_stor_dir
mv $tmp_myloader_log $mydumper_stor_dir
backtrace
exit $error
fi
fi
fi
}
do_case()
{
number=$(( $number + 1 ))
if [[ -n "$case_num" ]]
then
if [[ "$case_num" -ne $number ]]
then
return
fi
case_cycle=0
while ((case_cycle++ < case_repeat))
do
"$@" || exit
done
finish
fi
unset case_cycle
"$@"
}
number=0
prepare_full_test()
{
if [ ! -f "sakila-db.tar.gz" ]; then
wget -O sakila-db.tar.gz https://midenok-forks.github.io/sakila-db.tar.gz ||
exit
fi
tar xzf sakila-db.tar.gz
sed -i 's/last_update TIMESTAMP/last_update TIMESTAMP NOT NULL/g;s/NOT NULL NOT NULL/NOT NULL/g' sakila-db/sakila-schema.sql
mysql < sakila-db/sakila-schema.sql
mysql < sakila-db/sakila-data.sql
echo "Import testing database"
DATABASE=myd_test
mysql < test/mydumper_testing_db.sql
# export -- import
# 1000 rows -- database must not exist
if [[ -n "$prepare_only" ]]; then
exit
fi
mydumper_general_options="-u root -R -E -G -o ${mydumper_stor_dir} --regex "'^(?!(mysql\.|sys\.))'" --fifodir=/tmp/fifodir $log_level $MYDUMPER_ARGS"
myloader_general_options="-o --max-threads-for-index-creation=1 --max-threads-for-post-actions=1 --fifodir=/tmp/fifodir $log_level $MYLOADER_ARGS"
}
full_test_global(){
prepare_full_test
# single file compressed -- overriting database
# test_case_dir -c ${mydumper_general_options} -- ${myloader_general_options} -d ${myloader_stor_dir}
PARTIAL=0
for test in test_case_dir test_case_stream
do
echo "Executing test: $test"
for compress_mode in "" "-c GZIP" "-c ZSTD"
do
for backup_mode in "" "--load-data" "--csv"
do
for innodb_optimize_key_mode in "" "--innodb-optimize-keys=AFTER_IMPORT_ALL_TABLES" "--innodb-optimize-keys=AFTER_IMPORT_PER_TABLE"
do
for rows_and_filesize_mode in "" "-r 1000" "-r 10:100:10000" "-F 10" "-r 10:100:10000 -F 10"
do
do_case $test $backup_mode $compress_mode $rows_and_filesize_mode ${mydumper_general_options} -- ${myloader_general_options} -d ${myloader_stor_dir} --serialized-table-creation $innodb_optimize_key_mode
# statement size to 2MB -- overriting database
do_case $test $backup_mode $compress_mode $rows_and_filesize_mode -s 2000000 ${mydumper_general_options} -- ${myloader_general_options} -d ${myloader_stor_dir} --serialized-table-creation $innodb_optimize_key_mode
# compress and rows
do_case $test $backup_mode $compress_mode $rows_and_filesize_mode --use-savepoints --less-locking ${mydumper_general_options} -- ${myloader_general_options} -d ${myloader_stor_dir} --serialized-table-creation $innodb_optimize_key_mode
# ANSI_QUOTES
# $test -r 1000 -G ${mydumper_general_options} --defaults-file="test/mydumper.cnf" -- ${myloader_general_options} -d ${myloader_stor_dir} --serialized-table-creation --defaults-file="test/mydumper.cnf"
done
done
done
done
myloader_stor_dir=$stream_stor_dir
done
myloader_stor_dir=$mydumper_stor_dir
}
full_test_per_table(){
prepare_full_test
PARTIAL=1
echo "Starting per table tests"
for test in test_case_dir test_case_stream
do
echo "Executing tests: $test"
do_case $test -G --lock-all-tables -B empty_db ${mydumper_general_options} -- ${myloader_general_options} -d ${myloader_stor_dir} --serialized-table-creation
# exporting specific database -- overriting database
do_case $test -B myd_test_no_fk ${mydumper_general_options} -- ${myloader_general_options} -d ${myloader_stor_dir} --serialized-table-creation
# exporting specific table -- overriting database
do_case $test -B myd_test -T myd_test.mydumper_aipk_uuid ${mydumper_general_options} -- ${myloader_general_options} -d ${myloader_stor_dir}
# exporting specific database -- overriting database
do_case $test -B myd_test_no_fk ${mydumper_general_options} -- ${myloader_general_options} -B myd_test_2 -d ${myloader_stor_dir} --serialized-table-creation
do_case $test --no-data -G ${mydumper_general_options} -- ${myloader_general_options} -d ${myloader_stor_dir} --serialized-table-creation
myloader_stor_dir=$stream_stor_dir
done
}
full_test(){
full_test_global
full_test_per_table
}
full_test &&
finish
#cat $mydumper_log
#cat $myloader_log