-
Notifications
You must be signed in to change notification settings - Fork 44
/
Copy pathpquery-run.sh
executable file
·2056 lines (1998 loc) · 122 KB
/
pquery-run.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
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/bash
# Created by Roel Van de Paar, Percona LLC
# Updated by Ramesh Sivaraman, Percona LLC
# Updated by Mohit Joshi, Percona LLC
# ========================================= User configurable variables ==========================================================
# Note: if an option is passed to this script, it will use that option as the configuration file instead, for example ./pquery-run.sh pquery-run-ps.conf
CONFIGURATION_FILE=pquery-run.conf # Do not use any path specifiers, the .conf file should be in the same path as pquery-run.sh
#CONFIGURATION_FILE=pquery-run-RocksDB.conf # RocksDB testing
# ========================================= Improvement ideas ====================================================================
# * SAVE_TRIALS_WITH_CORE_OR_VALGRIND_ONLY=0 (These likely include some of the 'SIGKILL' issues - no core but terminated)
# * SQL hashing s/t2/t1/, hex values "0x"
# * Full MTR grammar on one-liners
# * Interleave all statements with another that is likely to cause issues, for example "USE mysql"
# ========================================= MAIN CODE ============================================================================
# Internal variables: DO NOT CHANGE!
RANDOM=`date +%s%N | cut -b14-19`; RANDOMD=$(echo $RANDOM$RANDOM$RANDOM | sed 's/..\(......\).*/\1/')
SCRIPT_AND_PATH=$(readlink -f $0); SCRIPT=$(echo ${SCRIPT_AND_PATH} | sed 's|.*/||'); SCRIPT_PWD=$(cd `dirname $0` && pwd)
WORKDIRACTIVE=0; SAVED=0; TRIAL=0; MYSQLD_START_TIMEOUT=60; TIMEOUT_REACHED=0; STOREANYWAY=0; PQUERY3=0
# Set ASAN coredump options
# https://github.com/google/sanitizers/wiki/SanitizerCommonFlags
# https://github.com/google/sanitizers/wiki/AddressSanitizerFlags
export ASAN_OPTIONS=quarantine_size_mb=512:atexit=true:detect_invalid_pointer_pairs=1:dump_instruction_bytes=true:abort_on_error=1 # This used to have disable_core=0 (now disable_coredump=0 ?) - TODO: check optimal setting
# Read configuration
if [ "$1" != "" ]; then CONFIGURATION_FILE=$1; fi
if [ ! -r ${SCRIPT_PWD}/${CONFIGURATION_FILE} ]; then echo "Assert: the confiruation file ${SCRIPT_PWD}/${CONFIGURATION_FILE} cannot be read!"; exit 1; fi
source ${SCRIPT_PWD}/$CONFIGURATION_FILE
PQUERY_TOOL_NAME=$(basename ${PQUERY_BIN})
if [ "${SEED}" == "" ]; then SEED=${RANDOMD}; fi
if [[ ${PQUERY_TOOL_NAME} == "pquery3-ps" || ${PQUERY_TOOL_NAME} == "pquery3-pxc" ]]; then PQUERY3=1; fi
# Safety checks: ensure variables are correctly set to avoid rm -Rf issues (if not set correctly, it was likely due to altering internal variables at the top of this file)
if [ "${WORKDIR}" == "/sd[a-z][/]" ]; then echo "Assert! \$WORKDIR == '${WORKDIR}' - is it missing the \$RANDOMD suffix?"; exit 1; fi
if [ "${RUNDIR}" == "/dev/shm[/]" ]; then echo "Assert! \$RUNDIR == '${RUNDIR}' - is it missing the \$RANDOMD suffix?"; exit 1; fi
if [ "$(echo ${RANDOMD} | sed 's|[0-9]|/|g')" != "//////" ]; then echo "Assert! \$RANDOMD == '${RANDOMD}'. This looks incorrect - it should be 6 numbers exactly"; exit 1; fi
if [ "${SKIPCHECKDIRS}" == "" ]; then # Used in/by pquery-reach.sh TODO: find a better way then hacking to avoid these checks. Check; why do they fail when called from pquery-reach.sh?
if [ "$(echo ${WORKDIR} | grep -oi "$RANDOMD" | head -n1)" != "${RANDOMD}" ]; then echo "Assert! \$WORKDIR == '${WORKDIR}' - is it missing the \$RANDOMD suffix?"; exit 1; fi
if [ "$(echo ${RUNDIR} | grep -oi "$RANDOMD" | head -n1)" != "${RANDOMD}" ]; then echo "Assert! \$WORKDIR == '${WORKDIR}' - is it missing the \$RANDOMD suffix?"; exit 1; fi
fi
# Other safety checks
if [ "$(echo ${PQUERY_BIN} | sed 's|\(^/pquery\)|\1|')" == "/pquery" ]; then echo "Assert! \$PQUERY_BIN == '${PQUERY_BIN}' - is it missing the \$SCRIPT_PWD prefix?"; exit 1; fi
if [ ! -r ${PQUERY_BIN} ]; then echo "${PQUERY_BIN} specified in the configuration file used (${SCRIPT_PWD}/${CONFIGURATION_FILE}) cannot be found/read"; exit 1; fi
if [ ! -r ${OPTIONS_INFILE} ]; then echo "${OPTIONS_INFILE} specified in the configuration file used (${SCRIPT_PWD}/${CONFIGURATION_FILE}) cannot be found/read"; exit 1; fi
# Try and raise ulimit for user processes (see setup_server.sh for how to set correct soft/hard nproc settings in limits.conf)
ulimit -u 7000
# Check input file (when generator is not used)
if [ ${USE_GENERATOR_INSTEAD_OF_INFILE} -ne 1 -a ! -r ${INFILE} ]; then
echo "Assert! \$INFILE (${INFILE}) cannot be read? Check file existence and privileges!"
exit 1
fi
#Format version string (thanks to wsrep_sst_xtrabackup-v2)
normalize_version(){
local major=0
local minor=0
local patch=0
# Only parses purely numeric version numbers, 1.2.3
# Everything after the first three values are ignored
if [[ $1 =~ ^([0-9]+)\.([0-9]+)\.?([0-9]*)([\.0-9])*$ ]]; then
major=${BASH_REMATCH[1]}
minor=${BASH_REMATCH[2]}
patch=${BASH_REMATCH[3]}
fi
printf %02d%02d%02d $major $minor $patch
}
#Version comparison script (thanks to wsrep_sst_xtrabackup-v2)
check_for_version()
{
local local_version_str="$( normalize_version $1 )"
local required_version_str="$( normalize_version $2 )"
if [[ "$local_version_str" < "$required_version_str" ]]; then
return 1
else
return 0
fi
}
# Output function
echoit(){
echo "[$(date +'%T')] [$SAVED] $1"
if [ ${WORKDIRACTIVE} -eq 1 ]; then echo "[$(date +'%T')] [$SAVED] $1" >> /${WORKDIR}/pquery-run.log; fi
}
# Find mysqld binary
if [ -r ${BASEDIR}/bin/mysqld ]; then
BIN=${BASEDIR}/bin/mysqld
else
# Check if this is a debug build by checking if debug string is present in dirname
if [[ ${BASEDIR} = *debug* ]]; then
if [ -r ${BASEDIR}/bin/mysqld-debug ]; then
BIN=${BASEDIR}/bin/mysqld-debug
else
echoit "Assert: there is no (script readable) mysqld binary at ${BASEDIR}/bin/mysqld[-debug] ?"
exit 1
fi
else
echoit "Assert: there is no (script readable) mysqld binary at ${BASEDIR}/bin/mysqld ?"
exit 1
fi
fi
#Store MySQL version string
MYSQL_VERSION=$(${BASEDIR}/bin/mysqld --version 2>&1 | grep -oe '[0-9]\.[0-9][\.0-9]*' | head -n1)
# JEMALLOC for PS/TokuDB
PSORNOT1=$(${BIN} --version | grep -oi 'Percona' | sed 's|p|P|' | head -n1)
PSORNOT2=$(${BIN} --version | grep -oi '5.7.[0-9]\+-[0-9]' | cut -f2 -d'-' | head -n1); if [ "${PSORNOT2}" == "" ]; then PSORNOT2=0; fi
if [ "${SKIP_JEMALLOC_FOR_PS}" != "1" ]; then
if [ "${PSORNOT1}" == "Percona" ] || [ ${PSORNOT2} -ge 1 ]; then
if [ -r `find /usr/*lib*/ -name libjemalloc.so.1 | head -n1` ]; then
export LD_PRELOAD=`find /usr/*lib*/ -name libjemalloc.so.1 | head -n1`
else
echoit "Assert! Binary (${BIN} reported itself as Percona Server, yet jemalloc was not found, please install it!";
echoit "For Centos7 you can do this by: sudo yum -y install epel-release; sudo yum -y install jemalloc;"
echoit "For Ubuntu you can do this by: sudo apt-get install libjemalloc-dev;"
exit 1;
fi
fi
else
if [ "${PSORNOT1}" == "Percona" ] || [ ${PSORNOT2} -ge 1 ]; then
echoit "*** IMPORTANT WARNING ***: SKIP_JEMALLOC_FOR_PS was set to 1, and thus JEMALLOC will not be LD_PRELOAD'ed. However, the mysqld binary (${BIN}) reports itself as Percona Server. If you are going to test TokuDB, JEMALLOC should be LD_PRELOAD'ed. If not testing TokuDB, then this warning can be safely ignored."
fi
fi
#Sanity check for PXB Crash testing run
if [[ ${PXB_CRASH_RUN} -eq 1 ]]; then
echoit "MODE: Percona Xtrabackup crash test run"
if [[ ! -d ${PXB_BASEDIR} ]]; then
echoit "Assert: $PXB_BASEDIR does not exist. Terminating!"
exit 1
fi
fi
# Automatic variable adjustments
if [ "$1" == "pxc" -o "$2" == "pxc" -o "$1" == "PXC" -o "$2" == "PXC" ]; then PXC=1; fi # Check if this is a a PXC run as indicated by first or second option to this script
if [ "$(whoami)" == "root" ]; then MYEXTRA="--user=root ${MYEXTRA}"; fi
if [ "${PXC_CLUSTER_RUN}" == "1" ]; then
echoit "As PXC_CLUSTER_RUN=1, this script is auto-assuming this is a PXC run and will set PXC=1"
PXC=1
fi
if [ "${GRP_RPL_CLUSTER_RUN}" == "1" ]; then
echoit "As GRP_RPL_CLUSTER_RUN=1, this script is auto-assuming this is a Group Replication run and will set GRP_RPL=1"
GRP_RPL=1
fi
if [ "${PXC}" == "1" ]; then
if [ ${QUERIES_PER_THREAD} -lt 2147483647 ]; then # Starting up a cluster takes more time, so don't rotate too quickly
echoit "Note: As this is a PXC=1 run, and QUERIES_PER_THREAD was set to only ${QUERIES_PER_THREAD}, this script is setting the queries per thread to the required minimum of 2147483647 for this run."
QUERIES_PER_THREAD=2147483647 # Max int
fi
if [ ${PQUERY_RUN_TIMEOUT} -lt 60 ]; then # Starting up a cluster takes more time, so don't rotate too quickly
echoit "Note: As this is a PXC=1 run, and PQUERY_RUN_TIMEOUT was set to only ${PQUERY_RUN_TIMEOUT}, this script is setting the timeout to the required minimum of 120 for this run."
PQUERY_RUN_TIMEOUT=60
fi
ADD_RANDOM_OPTIONS=0
ADD_RANDOM_TOKUDB_OPTIONS=0
ADD_RANDOM_ROCKSDB_OPTIONS=0
GRP_RPL=0
GRP_RPL_CLUSTER_RUN=0
fi
if [ "${GRP_RPL}" == "1" ]; then
if [ ${QUERIES_PER_THREAD} -lt 2147483647 ]; then # Starting up a cluster takes more time, so don't rotate too quickly
echoit "Note: As this is a GRP_RPL=1 run, and QUERIES_PER_THREAD was set to only ${QUERIES_PER_THREAD}, this script is setting the queries per thread to the required minimum of 2147483647 for this run."
QUERIES_PER_THREAD=2147483647 # Max int
fi
if [ ${PQUERY_RUN_TIMEOUT} -lt 120 ]; then # Starting up a cluster takes more time, so don't rotate too quickly
echoit "Note: As this is a GRP_RPL=1 run, and PQUERY_RUN_TIMEOUT was set to only ${PQUERY_RUN_TIMEOUT}, this script is setting the timeout to the required minimum of 120 for this run."
PQUERY_RUN_TIMEOUT=120
fi
ADD_RANDOM_TOKUDB_OPTIONS=0
ADD_RANDOM_ROCKSDB_OPTIONS=0
PXC=0
PXC_CLUSTER_RUN=0
fi
if [ ${QUERY_DURATION_TESTING} -eq 1 ]; then echoit "MODE: Query Duration Testing"; fi
if [ ${QUERY_DURATION_TESTING} -ne 1 -a ${QUERY_CORRECTNESS_TESTING} -ne 1 -a ${CRASH_RECOVERY_TESTING} -ne 1 ]; then
if [ "${VALGRIND_RUN}" == "1" ]; then
if [ ${THREADS} -eq 1 ]; then
echoit "MODE: Single threaded Valgrind pquery testing"
else
echoit "MODE: Multi threaded Valgrind pquery testing"
fi
else
if [ ${THREADS} -eq 1 ]; then
echoit "MODE: Single threaded pquery testing"
else
echoit "MODE: Multi threaded pquery testing"
fi
fi
fi
if [ ${THREADS} -gt 1 ]; then # We may want to drop this to 20 seconds required?
if [ ${PQUERY_RUN_TIMEOUT} -lt 30 ]; then
echoit "Note: As this is a multi-threaded run, and PQUERY_RUN_TIMEOUT was set to only ${PQUERY_RUN_TIMEOUT}, this script is setting the timeout to the required minimum of 30 for this run."
PQUERY_RUN_TIMEOUT=30
fi
if [ ${QUERY_DURATION_TESTING} -eq 1 ]; then
echoit "Note: As this is a QUERY_DURATION_TESTING=1 run, and THREADS was set to ${THREADS}, this script is setting the number of threads to the required setting of 1 thread for this run."
THREADS=1
fi
fi
if [ ${CRASH_RECOVERY_TESTING} -eq 1 ]; then
echoit "MODE: Crash Recovery Testing"
INFILE=$CRASH_RECOVERY_INFILE
if [ -a ${QUERY_DURATION_TESTING} -eq 1]; then
echoit "CRASH_RECOVERY_TESTING and QUERY_DURATION_TESTING cannot be both active at the same time due to parsing limitations. This is the case. Please disable one of them."
exit 1
fi
if [ ${QUERY_CORRECTNESS_TESTING} -eq 1]; then
echoit "CRASH_RECOVERY_TESTING and QUERY_CORRECTNESS_TESTING cannot be both active at the same time due to parsing limitations. This is the case. Please disable one of them."
exit 1
fi
if [ ${THREADS} -lt 50 ]; then
echoit "Note: As this is a CRASH_RECOVERY_TESTING=1 run, and THREADS was set to only ${THREADS}, this script is setting the number of threads to the required minimum of 50 for this run."
THREADS=50
fi
if [ ${PQUERY_RUN_TIMEOUT} -lt 30 ]; then
echoit "Note: As this is a CRASH_RECOVERY_TESTING=1 run, and PQUERY_RUN_TIMEOUT was set to only ${PQUERY_RUN_TIMEOUT}, this script is setting the timeout to the required minimum of 30 for this run."
PQUERY_RUN_TIMEOUT=30
fi
fi
if [ ${QUERY_CORRECTNESS_TESTING} -eq 1 ]; then
echoit "MODE: Query Correctness Testing"
if [ ${QUERY_DURATION_TESTING} -eq 1 ]; then
echoit "QUERY_CORRECTNESS_TESTING and QUERY_DURATION_TESTING cannot be both active at the same time due to parsing limitations. This is the case. Please disable one of them."
exit 1
fi
if [ ${THREADS} -ne 1 ]; then
echoit "Note: As this is a QUERY_CORRECTNESS_TESTING=1 run, and THREADS was set to ${THREADS}, this script is setting the number of threads to the required setting of 1 thread for this run."
THREADS=1
fi
fi
if [ ${USE_GENERATOR_INSTEAD_OF_INFILE} -eq 1 -a ${STORE_COPY_OF_INFILE} -eq 1 ]; then
echoit "Note: as the SQL Generator will be used instead of an input file (and as such there is more then one inputfile), STORE_COPY_OF_INFILE has automatically been set to 0."
STORE_COPY_OF_INFILE=0
fi
if [ "${VALGRIND_RUN}" == "1" ]; then
echoit "Note: As this is a VALGRIND_RUN=1 run, this script is increasing MYSQLD_START_TIMEOUT (${MYSQLD_START_TIMEOUT}) by 240 seconds because Valgrind is very slow in starting up mysqld."
MYSQLD_START_TIMEOUT=$[ ${MYSQLD_START_TIMEOUT} + 240 ]
if [ ${MYSQLD_START_TIMEOUT} -lt 300 ]; then
echoit "Note: As this is a VALGRIND_RUN=1 run, and MYSQLD_START_TIMEOUT was set to only ${MYSQLD_START_TIMEOUT}), this script is setting the timeout to the required minimum of 300 for this run."
MYSQLD_START_TIMEOUT=300
fi
echoit "Note: As this is a VALGRIND_RUN=1 run, this script is increasing PQUERY_RUN_TIMEOUT (${PQUERY_RUN_TIMEOUT}) by 180 seconds because Valgrind is very slow in processing SQL."
PQUERY_RUN_TIMEOUT=$[ ${PQUERY_RUN_TIMEOUT} + 180 ]
fi
# Trap ctrl-c
trap ctrl-c SIGINT
ctrl-c(){
echoit "CTRL+C Was pressed. Attempting to terminate running processes..."
KILL_PIDS1=`ps -ef | grep "$RANDOMD" | grep -v "grep" | awk '{print $2}' | tr '\n' ' '`
KILL_PIDS2=
if [ ${USE_GENERATOR_INSTEAD_OF_INFILE} -eq 1 ]; then
KILL_PIDS2=`ps -ef | grep generator | grep -v "grep" | awk '{print $2}' | tr '\n' ' '`
fi
KILL_PIDS="${KILL_PIDS1} ${KILL_PIDS2}"
if [ "${KILL_PIDS}" != "" ]; then
echoit "Terminating the following PID's: ${KILL_PIDS}"
kill -9 ${KILL_PIDS} >/dev/null 2>&1
fi
if [ -d ${RUNDIR}/${TRIAL}/ ]; then
echoit "Done. Moving the trial $0 was currently working on to workdir as ${WORKDIR}/${TRIAL}/..."
mv ${RUNDIR}/${TRIAL}/ ${WORKDIR}/ 2>&1 | tee -a /${WORKDIR}/pquery-run.log
fi
if [ $USE_GENERATOR_INSTEAD_OF_INFILE -eq 1 ]; then
echoit "Attempting to cleanup generator temporary files..."
rm -f ${SCRIPT_PWD}/generator/generator${RANDOMD}.sh
rm -f ${SCRIPT_PWD}/generator/out${RANDOMD}*.sql
fi
if [ "$PMM" == "1" ]; then
echoit "Attempting to cleanup PMM client services..."
sudo pmm-admin remove --all > /dev/null
fi
echoit "Attempting to cleanup the pquery rundir ${RUNDIR}..."
rm -Rf ${RUNDIR}
if [ $SAVED -eq 0 -a ${SAVE_SQL} -eq 0 ]; then
echoit "There were no coredumps saved, and SAVE_SQL=0, so the workdir can be safely deleted. Doing so..."
WORKDIRACTIVE=0
rm -Rf ${WORKDIR}
else
echoit "The results of this run can be found in the workdir ${WORKDIR}..."
fi
echoit "Done. Terminating pquery-run.sh with exit code 2..."
exit 2
}
savetrial(){ # Only call this if you definitely want to save a trial
echoit "Copying rundir from ${RUNDIR}/${TRIAL} to ${WORKDIR}/${TRIAL}"
mv ${RUNDIR}/${TRIAL}/ ${WORKDIR}/ 2>&1 | tee -a /${WORKDIR}/pquery-run.log
if [ "$PMM_CLEAN_TRIAL" == "1" ];then
echoit "Removing mysql instance (pq${RANDOMD}-${TRIAL}) from pmm-admin"
sudo pmm-admin remove mysql pq${RANDOMD}-${TRIAL} > /dev/null
fi
SAVED=$[ $SAVED + 1 ]
}
removetrial(){
echoit "Removing trial rundir ${RUNDIR}/${TRIAL}"
if [ "${RUNDIR}" != "" -a "${TRIAL}" != "" -a -d ${RUNDIR}/${TRIAL}/ ]; then # Protection against dangerous rm's
rm -Rf ${RUNDIR}/${TRIAL}/
fi
if [ "$PMM_CLEAN_TRIAL" == "1" ];then
echoit "Removing mysql instance (pq${RANDOMD}-${TRIAL}) from pmm-admin"
sudo pmm-admin remove mysql pq${RANDOMD}-${TRIAL} > /dev/null
fi
}
removelasttrial(){
if [ ${TRIAL} -gt 2 ]; then
echoit "Removing last successful trial workdir ${WORKDIR}/$((${TRIAL}-2))"
if [ "${WORKDIR}" != "" -a "${TRIAL}" != "" -a -d ${WORKDIR}/$((${TRIAL}-2))/ ]; then
rm -Rf ${WORKDIR}/$((${TRIAL}-2))/
fi
echoit "Removing the ${WORKDIR}/step_$((${TRIAL}-2)).dll file"
rm ${WORKDIR}/step_$((${TRIAL}-2)).dll
fi
}
savesql(){
echoit "Copying sql trace(s) from ${RUNDIR}/${TRIAL} to ${WORKDIR}/${TRIAL}"
mkdir ${WORKDIR}/${TRIAL}
cp ${RUNDIR}/${TRIAL}/*.sql ${WORKDIR}/${TRIAL}/
rm -Rf ${RUNDIR}/${TRIAL}
sync; sleep 0.2
if [ -d ${RUNDIR}/${TRIAL} ]; then
echoit "Assert: tried to remove ${RUNDIR}/${TRIAL}, but it looks like removal failed. Check what is holding lock? (lsof tool may help)."
echoit "As this is not necessarily a fatal error (there is likely enough space on ${RUNDIR} to continue working), pquery-run.sh will NOT terminate."
echoit "However, this looks like a shortcoming in pquery-run.sh (likely in the mysqld termination code) which needs debugging and fixing. Please do."
fi
}
check_cmd(){
CMD_PID=$1
ERROR_MSG=$2
if [ ${CMD_PID} -ne 0 ]; then echo -e "\nERROR: $ERROR_MSG. Terminating!"; exit 1; fi
}
if [[ $PXC -eq 1 ]];then
# Creating default my.cnf file
SUSER=root
SPASS=
rm -rf ${BASEDIR}/my.cnf
echo "[mysqld]" > ${BASEDIR}/my.cnf
echo "basedir=${BASEDIR}" >> ${BASEDIR}/my.cnf
echo "wsrep-debug=1" >> ${BASEDIR}/my.cnf
echo "innodb_file_per_table" >> ${BASEDIR}/my.cnf
echo "innodb_autoinc_lock_mode=2" >> ${BASEDIR}/my.cnf
if ! check_for_version $MYSQL_VERSION "8.0.0" ; then
echo "innodb_locks_unsafe_for_binlog=1" >> ${BASEDIR}/my.cnf
echo "wsrep_sst_auth=$SUSER:$SPASS" >> ${BASEDIR}/my.cnf
else
echo "log-error-verbosity=3" >> ${BASEDIR}/my.cnf
fi
echo "wsrep-provider=${BASEDIR}/lib/libgalera_smm.so" >> ${BASEDIR}/my.cnf
echo "wsrep_sst_method=xtrabackup-v2" >> ${BASEDIR}/my.cnf
echo "core-file" >> ${BASEDIR}/my.cnf
echo "log-output=none" >> ${BASEDIR}/my.cnf
echo "wsrep_slave_threads=2" >> ${BASEDIR}/my.cnf
echo "log_bin=binlog" >> ${BASEDIR}/my.cnf
echo "binlog_format=ROW" >> ${BASEDIR}/my.cnf
echo "gtid_mode=ON" >> ${BASEDIR}/my.cnf
echo "log_slave_updates=ON" >> ${BASEDIR}/my.cnf
echo "enforce_gtid_consistency=ON" >> ${BASEDIR}/my.cnf
echo "master_verify_checksum=on" >> ${BASEDIR}/my.cnf
echo "binlog_checksum=CRC32" >> ${BASEDIR}/my.cnf
if [[ "$ENCRYPTION_RUN" == 1 ]];then
if check_for_version $MYSQL_VERSION "8.0.0" ; then
echo "binlog-encryption=ON" >> ${BASEDIR}/my.cnf
echo "innodb_temp_tablespace_encrypt=ON" >> ${BASEDIR}/my.cnf
echo "encrypt_tmp_files=ON" >> ${BASEDIR}/my.cnf
echo "default_table_encryption=ON" >> ${BASEDIR}/my.cnf
echo "innodb_redo_log_encrypt=ON" >> ${BASEDIR}/my.cnf
echo "innodb_undo_log_encrypt=ON" >> ${BASEDIR}/my.cnf
echo "innodb_sys_tablespace_encrypt=ON" >> ${BASEDIR}/my.cnf
echo "pxc_encrypt_cluster_traffic=ON" >> ${BASEDIR}/my.cnf
fi
if [[ $WITH_KEYRING_VAULT -ne 1 ]];then
echo "early-plugin-load=keyring_file.so" >> ${BASEDIR}/my.cnf
echo "keyring_file_data=keyring" >> ${BASEDIR}/my.cnf
fi
else
if check_for_version $MYSQL_VERSION "8.0.0" ; then
echo "pxc_encrypt_cluster_traffic=OFF" >> ${BASEDIR}/my.cnf
fi
fi
fi
pxc_startup(){
IS_STARTUP=$1
ADDR="127.0.0.1"
RPORT=$(( (RANDOM%21 + 10)*1000 ))
SOCKET1=${RUNDIR}/${TRIAL}/node1/node1_socket.sock
SOCKET2=${RUNDIR}/${TRIAL}/node2/node2_socket.sock
SOCKET3=${RUNDIR}/${TRIAL}/node3/node3_socket.sock
if check_for_version $MYSQL_VERSION "5.7.0" ; then
if [[ "$ENCRYPTION_RUN" == 1 ]];then
if check_for_version $MYSQL_VERSION "8.0.0" ; then
MID="${BASEDIR}/bin/mysqld --no-defaults --initialize-insecure --early-plugin-load=keyring_file.so --keyring_file_data=keyring --innodb_sys_tablespace_encrypt=ON --basedir=${BASEDIR}"
else
MID="${BASEDIR}/bin/mysqld --no-defaults --initialize-insecure --basedir=${BASEDIR}"
fi
else
MID="${BASEDIR}/bin/mysqld --no-defaults --initialize-insecure --basedir=${BASEDIR}"
fi
else
MID="${BASEDIR}/scripts/mysql_install_db --no-defaults --basedir=${BASEDIR}"
fi
if [ "$IS_STARTUP" != "startup" ]; then
echo "echo '=== Starting PXC cluster for recovery...'" > ${RUNDIR}/${TRIAL}/start_pxc_recovery
echo "sed -i 's|safe_to_bootstrap:.*$|safe_to_bootstrap: 1|' ${WORKDIR}/${TRIAL}/node1/grastate.dat" >> ${RUNDIR}/${TRIAL}/start_pxc_recovery
fi
unset PXC_PORTS
unset PXC_LADDRS
PXC_PORTS=""
PXC_LADDRS=""
for i in `seq 1 3`;do
if [ "$IS_STARTUP" == "startup" ]; then
node="${WORKDIR}/node${i}.template"
if ! check_for_version $MYSQL_VERSION "5.7.0" ; then
mkdir -p $node
fi
DATADIR=${WORKDIR}
else
node="${RUNDIR}/${TRIAL}/node${i}"
DATADIR="${RUNDIR}/${TRIAL}"
fi
mkdir -p $DATADIR/tmp${i}
RBASE1="$(( RPORT + ( 100 * $i ) ))"
LADDR1="127.0.0.1:$(( RBASE1 + 8 ))"
PXC_PORTS+=("$RBASE1")
PXC_LADDRS+=("$LADDR1")
cp ${BASEDIR}/my.cnf ${DATADIR}/n${i}.cnf
sed -i "2i server-id=10${i}" ${DATADIR}/n${i}.cnf
sed -i "2i wsrep_node_incoming_address=$ADDR" ${DATADIR}/n${i}.cnf
sed -i "2i wsrep_node_address=$ADDR" ${DATADIR}/n${i}.cnf
sed -i "2i log-error=$node/node${i}.err" ${DATADIR}/n${i}.cnf
sed -i "2i port=$RBASE1" ${DATADIR}/n${i}.cnf
sed -i "2i datadir=$node" ${DATADIR}/n${i}.cnf
sed -i "2i socket=$node/node${i}_socket.sock" ${DATADIR}/n${i}.cnf
sed -i "2i tmpdir=$DATADIR/tmp${i}" ${DATADIR}/n${i}.cnf
if [[ "$ENCRYPTION_RUN" != 1 ]];then
sed -i "2i wsrep_provider_options=\"gmcast.listen_addr=tcp://$LADDR1;$WSREP_PROVIDER_OPT\"" ${DATADIR}/n${i}.cnf
else
sed -i "2i wsrep_provider_options=\"gmcast.listen_addr=tcp://$LADDR1;$WSREP_PROVIDER_OPT;socket.ssl_key=${WORKDIR}/cert/server-key.pem;socket.ssl_cert=${WORKDIR}/cert/server-cert.pem;socket.ssl_ca=${WORKDIR}/cert/ca.pem\"" ${DATADIR}/n${i}.cnf
echo "ssl-ca = ${WORKDIR}/cert/ca.pem" >> ${DATADIR}/n${i}.cnf
echo "ssl-cert = ${WORKDIR}/cert/server-cert.pem" >> ${DATADIR}/n${i}.cnf
echo "ssl-key = ${WORKDIR}/cert/server-key.pem" >> ${DATADIR}/n${i}.cnf
echo "[client]" >> ${DATADIR}/n${i}.cnf
echo "ssl-ca = ${WORKDIR}/cert/ca.pem" >> ${DATADIR}/n${i}.cnf
echo "ssl-cert = ${WORKDIR}/cert/client-cert.pem" >> ${DATADIR}/n${i}.cnf
echo "ssl-key = ${WORKDIR}/cert/client-key.pem" >> ${DATADIR}/n${i}.cnf
echo "[sst]" >> ${DATADIR}/n${i}.cnf
echo "encrypt = 4" >> ${DATADIR}/n${i}.cnf
echo "ssl-ca = ${WORKDIR}/cert/ca.pem" >> ${DATADIR}/n${i}.cnf
echo "ssl-cert = ${WORKDIR}/cert/server-cert.pem" >> ${DATADIR}/n${i}.cnf
echo "ssl-key = ${WORKDIR}/cert/server-key.pem" >> ${DATADIR}/n${i}.cnf
fi
if [ "$IS_STARTUP" == "startup" ]; then
${MID} --datadir=$node > ${WORKDIR}/startup_node1.err 2>&1 || exit 1;
fi
done
if [[ "$ENCRYPTION_RUN" == 1 ]];then
if [ "$IS_STARTUP" == "startup" ]; then
mkdir ${WORKDIR}/cert
if check_for_version $MYSQL_VERSION "5.7.0" ; then
cp ${WORKDIR}/node1.template/*.pem ${WORKDIR}/cert/
else
pushd ${WORKDIR}/cert
openssl genrsa 2048 > ca-key.pem
openssl req -new -x509 -nodes -days 3600 -key ca-key.pem -out ca.pem -subj '/CN=www.percona.com/O=Database Performance./C=US'
openssl req -newkey rsa:2048 -days 3600 -nodes -keyout server-key.pem -out server-req.pem -subj '/CN=www.percona.com/O=Database Performance./C=AU'
openssl rsa -in server-key.pem -out server-key.pem
openssl x509 -req -in server-req.pem -days 3600 -CA ca.pem -CAkey ca-key.pem -set_serial 01 -out server-cert.pem
popd
fi
fi
fi
get_error_socket_file(){
NR=$1
if [ "$IS_STARTUP" == "startup" ]; then
ERR_FILE="${WORKDIR}/node${NR}.template/node${NR}.err"
SOCKET="${WORKDIR}/node${NR}.template/node${NR}_socket.sock"
else
ERR_FILE="${RUNDIR}/${TRIAL}/node${NR}/node${NR}.err"
SOCKET="${RUNDIR}/${TRIAL}/node${NR}/node${NR}_socket.sock"
fi
}
if [[ $WITH_KEYRING_VAULT -eq 1 ]]; then
MYEXTRA_KEYRING="--early-plugin-load=keyring_vault.so --loose-keyring_vault_config=$WORKDIR/vault/keyring_vault_pxc${i}.cnf"
fi
if [ "${VALGRIND_RUN}" == "1" ]; then
VALGRIND_CMD="${VALGRIND_CMD}"
else
VALGRIND_CMD=""
fi
for j in `seq 1 3`;do
IS_FAILED=0
sed -i "2i wsrep_cluster_address=gcomm://${PXC_LADDRS[1]},${PXC_LADDRS[2]},${PXC_LADDRS[3]}" ${DATADIR}/n${j}.cnf
get_error_socket_file ${j}
if [[ ${j} -eq 1 ]]; then
$VALGRIND_CMD ${BASEDIR}/bin/mysqld --defaults-file=${DATADIR}/n${j}.cnf $STARTUP_OPTION $MYEXTRA_KEYRING $MYEXTRA $PXC_MYEXTRA --wsrep-new-cluster > ${ERR_FILE} 2>&1 &
else
$VALGRIND_CMD ${BASEDIR}/bin/mysqld --defaults-file=${DATADIR}/n${j}.cnf \
$STARTUP_OPTION $MYEXTRA_KEYRING $MYEXTRA $PXC_MYEXTRA > ${ERR_FILE} 2>&1 &
fi
for X in $(seq 0 ${PXC_START_TIMEOUT}); do
sleep 1
if ${BASEDIR}/bin/mysqladmin -uroot -S${SOCKET} ping > /dev/null 2>&1; then
break
else
if grep -qi "Address already in use" ${ERR_FILE} ; then
echoit "Assert! The text '[ERROR] Aborting' was found in the error log due to a IP port conflict (the port was already in use)"
if [ "$IS_STARTUP" == "startup" ]; then
IS_FAILED=1
break
else
removetrial
FAILEDSTARTABORT=1
IS_FAILED=1
break
fi
fi
if grep -qi "ERROR. Aborting" ${ERR_FILE} ; then
if [ ${PXC_ADD_RANDOM_OPTIONS} -eq 0 ]; then # Halt for PXC_ADD_RANDOM_OPTIONS=0 runs which have 'ERROR. Aborting' in the error log, as they should not produce errors like these, given that the PXC_MYEXTRA and WSREP_PROVIDER_OPT lists are/should be high-quality/non-faulty
echoit "Assert! '[ERROR] Aborting' was found in the error log. This is likely an issue with one of the \$PXC_MYEXTRA (${PXC_MYEXTRA}) startup or \$WSREP_PROVIDER_OPT ($WSREP_PROVIDER_OPT) congifuration options. Saving trial for further analysis, and dumping error log here for quick analysis. Please check the output against these variables settings. The respective files for these options (${PXC_WSREP_OPTIONS_INFILE} and ${PXC_WSREP_PROVIDER_OPTIONS_INFILE}) may require editing."
grep "ERROR" $ERROR_LOG | tee -a /${WORKDIR}/pquery-run.log
if [ ${PXC_IGNORE_ALL_OPTION_ISSUES} -eq 1 ]; then
echoit "PXC_IGNORE_ALL_OPTION_ISSUES=1, so irrespective of the assert given, pquery-run.sh will continue running. Please check your option files!"
else
savetrial
echoit "Remember to cleanup/delete the rundir: rm -Rf ${RUNDIR}"
exit 1
fi
else # Do not halt for PXC_ADD_RANDOM_OPTIONS=1 runs, they are likely to produce errors like these as PXC_MYEXTRA was randomly changed
echoit "'[ERROR] Aborting' was found in the error log. This is likely an issue with one of the \$PXC_MYEXTRA (${PXC_MYEXTRA}) startup options. As \$PXC_ADD_RANDOM_OPTIONS=1, this is likely to be encountered given the random addition of mysqld options. Not saving trial. If you see this error for every trial however, set \$PXC_ADD_RANDOM_OPTIONS=0 & try running pquery-run.sh again. If it still fails, it is likely that your base \$MYEXTRA (${MYEXTRA}) setting is faulty."
grep "ERROR" ${ERR_FILE} | tee -a /${WORKDIR}/pquery-run.log
FAILEDSTARTABORT=1
IS_FAILED=1
break
fi
fi
fi
done
if [[ $IS_FAILED -eq 1 ]]; then
break
fi
done
if [ "$IS_STARTUP" != "startup" ]; then
echo "RUNDIR=$RUNDIR" >> ${RUNDIR}/${TRIAL}/start_pxc_recovery
echo "WORKDIR=$WORKDIR" >> ${RUNDIR}/${TRIAL}/start_pxc_recovery
echo "sed -i \"s|\$RUNDIR|\$WORKDIR|g\" ${WORKDIR}/${TRIAL}/n1.cnf" >> ${RUNDIR}/${TRIAL}/start_pxc_recovery
echo "sed -i \"s|\$RUNDIR|\$WORKDIR|g\" ${WORKDIR}/${TRIAL}/n2.cnf" >> ${RUNDIR}/${TRIAL}/start_pxc_recovery
echo "sed -i \"s|\$RUNDIR|\$WORKDIR|g\" ${WORKDIR}/${TRIAL}/n3.cnf" >> ${RUNDIR}/${TRIAL}/start_pxc_recovery
echo "startup_check(){ " >> ${RUNDIR}/${TRIAL}/start_pxc_recovery
echo " SOCKET=\$1" >> ${RUNDIR}/${TRIAL}/start_pxc_recovery
echo " for X in \`seq 0 200\`; do" >> ${RUNDIR}/${TRIAL}/start_pxc_recovery
echo " sleep 1" >> ${RUNDIR}/${TRIAL}/start_pxc_recovery
echo " if ${BASEDIR}/bin/mysqladmin -uroot -S\${SOCKET} ping > /dev/null 2>&1; then" >> ${RUNDIR}/${TRIAL}/start_pxc_recovery
echo " break" >> ${RUNDIR}/${TRIAL}/start_pxc_recovery
echo " fi" >> ${RUNDIR}/${TRIAL}/start_pxc_recovery
echo " done" >> ${RUNDIR}/${TRIAL}/start_pxc_recovery
echo "}" >> ${RUNDIR}/${TRIAL}/start_pxc_recovery
echo "" >> ${RUNDIR}/${TRIAL}/start_pxc_recovery
echo "$VALGRIND_CMD ${BASEDIR}/bin/mysqld --defaults-file=${WORKDIR}/${TRIAL}/n1.cnf $STARTUP_OPTION $MYEXTRA_KEYRING $MYEXTRA $PXC_MYEXTRA --wsrep-new-cluster > ${RUNDIR}/${TRIAL}/node1/node1.err 2>&1 &" >> ${RUNDIR}/${TRIAL}/start_pxc_recovery
echo "startup_check ${SOCKET1}" >> ${RUNDIR}/${TRIAL}/start_pxc_recovery
echo "$VALGRIND_CMD ${BASEDIR}/bin/mysqld --defaults-file=${WORKDIR}/${TRIAL}/n2.cnf $STARTUP_OPTION $MYEXTRA_KEYRING $MYEXTRA $PXC_MYEXTRA > ${RUNDIR}/${TRIAL}/node2/node2.err 2>&1 &" >> ${RUNDIR}/${TRIAL}/start_pxc_recovery
echo "startup_check ${SOCKET2}" >> ${RUNDIR}/${TRIAL}/start_pxc_recovery
echo "$VALGRIND_CMD ${BASEDIR}/bin/mysqld --defaults-file=${WORKDIR}/${TRIAL}/n3.cnf $STARTUP_OPTION $MYEXTRA_KEYRING $MYEXTRA $PXC_MYEXTRA > ${RUNDIR}/${TRIAL}/node3/node3.err 2>&1 &" >> ${RUNDIR}/${TRIAL}/start_pxc_recovery
echo "startup_check ${SOCKET3}" >> ${RUNDIR}/${TRIAL}/start_pxc_recovery
echo "" >> ${RUNDIR}/${TRIAL}/start_pxc_recovery
echo "echo \"${BASEDIR}/bin/mysqladmin -uroot -S${WORKDIR}/${TRIAL}/node3/node3_socket.sock shutdown > /dev/null 2>&1\" > ${WORKDIR}/${TRIAL}/stop_pxc_recovery" >> ${RUNDIR}/${TRIAL}/start_pxc_recovery
echo "echo \"${BASEDIR}/bin/mysqladmin -uroot -S${WORKDIR}/${TRIAL}/node2/node2_socket.sock shutdown > /dev/null 2>&1\" >> ${WORKDIR}/${TRIAL}/stop_pxc_recovery" >> ${RUNDIR}/${TRIAL}/start_pxc_recovery
echo "echo \"${BASEDIR}/bin/mysqladmin -uroot -S${WORKDIR}/${TRIAL}/node1/node1_socket.sock shutdown > /dev/null 2>&1\" >> ${WORKDIR}/${TRIAL}/stop_pxc_recovery" >> ${RUNDIR}/${TRIAL}/start_pxc_recovery
echo "chmod +x ${WORKDIR}/${TRIAL}/stop_pxc_recovery" >> ${RUNDIR}/${TRIAL}/start_pxc_recovery
chmod +x ${RUNDIR}/${TRIAL}/start_pxc_recovery
fi
if [ "$IS_STARTUP" == "startup" ]; then
${BASEDIR}/bin/mysql -uroot -S${WORKDIR}/node${NR}.template/node${NR}_socket.sock -e "create database if not exists test" > /dev/null 2>&1
fi
}
gr_startup(){
ADDR="127.0.0.1"
RPORT=$(( RANDOM%21 + 10 ))
RBASE="$(( RPORT*1000 ))"
RBASE1="$(( RBASE + 1 ))"
RBASE2="$(( RBASE + 2 ))"
RBASE3="$(( RBASE + 3 ))"
LADDR1="$ADDR:$(( RBASE + 101 ))"
LADDR2="$ADDR:$(( RBASE + 102 ))"
LADDR3="$ADDR:$(( RBASE + 103 ))"
SUSER=root
SPASS=
MID="${BASEDIR}/bin/mysqld --no-defaults --initialize-insecure --basedir=${BASEDIR}"
if [ ${GRP_RPL_CLUSTER_RUN} -eq 1 ]; then
MYEXTRA="$MYEXTRA --plugin-load=group_replication.so --group_replication_single_primary_mode=OFF"
else
MYEXTRA="$MYEXTRA --plugin-load=group_replication.so"
fi
if [ "$1" == "startup" ]; then
node1="${WORKDIR}/node1.template"
node2="${WORKDIR}/node2.template"
node3="${WORKDIR}/node3.template"
else
node1="${RUNDIR}/${TRIAL}/node1"
node2="${RUNDIR}/${TRIAL}/node2"
node3="${RUNDIR}/${TRIAL}/node3"
fi
gr_startup_chk(){
ERROR_LOG=$1
if grep -qi "ERROR. Aborting" $ERROR_LOG ; then
if grep -qi "TCP.IP port. Address already in use" $ERROR_LOG ; then
echoit "Assert! The text '[ERROR] Aborting' was found in the error log due to a IP port conflict (the port was already in use)"
removetrial
else
echoit "Assert! '[ERROR] Aborting' was found in the error log. This is likely an issue with one of the \$MYEXTRA (${MYEXTRA}) startup options. Saving trial for further analysis, and dumping error log here for quick analysis. Please check the output against these variables settings."
grep "ERROR" $ERROR_LOG | tee -a /${WORKDIR}/pquery-run.log
savetrial
echoit "Remember to cleanup/delete the rundir: rm -Rf ${RUNDIR}"
exit 1
fi
fi
}
if [ "$1" == "startup" ]; then
${MID} --datadir=$node1 > ${WORKDIR}/startup_node1.err 2>&1 || exit 1;
fi
${BASEDIR}/bin/mysqld --no-defaults \
--basedir=${BASEDIR} --datadir=$node1 \
--innodb_file_per_table $MYEXTRA --innodb_autoinc_lock_mode=2 --innodb_locks_unsafe_for_binlog=1 \
--server_id=1 --gtid_mode=ON --enforce_gtid_consistency=ON \
--master_info_repository=TABLE --relay_log_info_repository=TABLE \
--binlog_checksum=NONE --log_slave_updates=ON --log_bin=binlog \
--binlog_format=ROW --innodb_flush_method=O_DIRECT \
--core-file --sql-mode=no_engine_substitution \
--loose-innodb --secure-file-priv= --loose-innodb-status-file=1 \
--log-error=$node1/node1.err \
--socket=$node1/node1_socket.sock --log-output=none \
--port=$RBASE1 --transaction_write_set_extraction=XXHASH64 \
--loose-group_replication_group_name="aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa" \
--loose-group_replication_start_on_boot=off --loose-group_replication_local_address="$LADDR1" \
--loose-group_replication_group_seeds="$LADDR1,$LADDR2,$LADDR3" \
--loose-group_replication_bootstrap_group=off --super_read_only=OFF > $node1/node1.err 2>&1 &
for X in $(seq 0 ${GRP_RPL_START_TIMEOUT}); do
sleep 1
if ${BASEDIR}/bin/mysqladmin -uroot -S$node1/node1_socket.sock ping > /dev/null 2>&1; then
sleep 2
if [ "$1" == "startup" ]; then
${BASEDIR}/bin/mysql -uroot -S$node1/node1_socket.sock -Bse "SET SQL_LOG_BIN=0;CREATE USER rpl_user@'%';GRANT REPLICATION SLAVE ON *.* TO rpl_user@'%' IDENTIFIED BY 'rpl_pass';FLUSH PRIVILEGES;SET SQL_LOG_BIN=1;" > /dev/null 2>&1
${BASEDIR}/bin/mysql -uroot -S$node1/node1_socket.sock -Bse "CHANGE MASTER TO MASTER_USER='rpl_user', MASTER_PASSWORD='rpl_pass' FOR CHANNEL 'group_replication_recovery';" > /dev/null 2>&1
${BASEDIR}/bin/mysql -uroot -S$node1/node1_socket.sock -Bse "SET GLOBAL group_replication_bootstrap_group=ON;START GROUP_REPLICATION;SET GLOBAL group_replication_bootstrap_group=OFF;SELECT SLEEP(10);" > /dev/null 2>&1
${BASEDIR}/bin/mysql -uroot -S$node1/node1_socket.sock -Bse "create database if not exists test" > /dev/null 2>&1
else
${BASEDIR}/bin/mysql -uroot -S$node1/node1_socket.sock -Bse "SET GLOBAL group_replication_bootstrap_group=ON;START GROUP_REPLICATION;SET GLOBAL group_replication_bootstrap_group=OFF;SELECT SLEEP(5);" > /dev/null 2>&1
fi
break
fi
gr_startup_chk $node1/node1.err
done
if [ "$1" == "startup" ]; then
${MID} --datadir=$node2 > ${WORKDIR}/startup_node2.err 2>&1 || exit 1;
fi
${BASEDIR}/bin/mysqld --no-defaults \
--basedir=${BASEDIR} --datadir=$node2 \
--innodb_file_per_table $MYEXTRA --innodb_autoinc_lock_mode=2 --innodb_locks_unsafe_for_binlog=1 \
--server_id=1 --gtid_mode=ON --enforce_gtid_consistency=ON \
--master_info_repository=TABLE --relay_log_info_repository=TABLE \
--binlog_checksum=NONE --log_slave_updates=ON --log_bin=binlog \
--binlog_format=ROW --innodb_flush_method=O_DIRECT \
--core-file --sql-mode=no_engine_substitution \
--loose-innodb --secure-file-priv= --loose-innodb-status-file=1 \
--log-error=$node2/node2.err \
--socket=$node2/node2_socket.sock --log-output=none \
--port=$RBASE2 --transaction_write_set_extraction=XXHASH64 \
--loose-group_replication_group_name="aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa" \
--loose-group_replication_start_on_boot=off --loose-group_replication_local_address="$LADDR2" \
--loose-group_replication_group_seeds="$LADDR1,$LADDR2,$LADDR3" \
--loose-group_replication_bootstrap_group=off --super_read_only=OFF > $node2/node2.err 2>&1 &
for X in $(seq 0 ${GRP_RPL_START_TIMEOUT}); do
sleep 1
if ${BASEDIR}/bin/mysqladmin -uroot -S$node2/node2_socket.sock ping > /dev/null 2>&1; then
sleep 2
if [ "$1" == "startup" ]; then
${BASEDIR}/bin/mysql -uroot -S$node2/node2_socket.sock -Bse "SET SQL_LOG_BIN=0;CREATE USER rpl_user@'%';GRANT REPLICATION SLAVE ON *.* TO rpl_user@'%' IDENTIFIED BY 'rpl_pass';FLUSH PRIVILEGES;SET SQL_LOG_BIN=1;" > /dev/null 2>&1
${BASEDIR}/bin/mysql -uroot -S$node2/node2_socket.sock -Bse "CHANGE MASTER TO MASTER_USER='rpl_user', MASTER_PASSWORD='rpl_pass' FOR CHANNEL 'group_replication_recovery';" > /dev/null 2>&1
${BASEDIR}/bin/mysql -uroot -S$node2/node2_socket.sock -Bse "START GROUP_REPLICATION;" > /dev/null 2>&1
else
${BASEDIR}/bin/mysql -uroot -S$node2/node2_socket.sock -Bse "START GROUP_REPLICATION;SELECT SLEEP(5);" > /dev/null 2>&1
fi
break
fi
gr_startup_chk $node2/node2.err
done
if [ "$1" == "startup" ]; then
${MID} --datadir=$node3 > ${WORKDIR}/startup_node3.err 2>&1 || exit 1;
fi
${BASEDIR}/bin/mysqld --no-defaults \
--basedir=${BASEDIR} --datadir=$node3 \
--innodb_file_per_table $MYEXTRA --innodb_autoinc_lock_mode=2 --innodb_locks_unsafe_for_binlog=1 \
--server_id=1 --gtid_mode=ON --enforce_gtid_consistency=ON \
--master_info_repository=TABLE --relay_log_info_repository=TABLE \
--binlog_checksum=NONE --log_slave_updates=ON --log_bin=binlog \
--binlog_format=ROW --innodb_flush_method=O_DIRECT \
--core-file --sql-mode=no_engine_substitution \
--loose-innodb --secure-file-priv= --loose-innodb-status-file=1 \
--log-error=$node3/node3.err \
--socket=$node3/node3_socket.sock --log-output=none \
--port=$RBASE3 --transaction_write_set_extraction=XXHASH64 \
--loose-group_replication_group_name="aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa" \
--loose-group_replication_start_on_boot=off --loose-group_replication_local_address="$LADDR3" \
--loose-group_replication_group_seeds="$LADDR1,$LADDR2,$LADDR3" \
--loose-group_replication_bootstrap_group=off --super_read_only=OFF > $node3/node3.err 2>&1 &
for X in $(seq 0 ${GRP_RPL_START_TIMEOUT}); do
sleep 1
if ${BASEDIR}/bin/mysqladmin -uroot -S$node3/node3_socket.sock ping > /dev/null 2>&1; then
sleep 2
if [ "$1" == "startup" ]; then
${BASEDIR}/bin/mysql -uroot -S$node3/node3_socket.sock -Bse "SET SQL_LOG_BIN=0;CREATE USER rpl_user@'%';GRANT REPLICATION SLAVE ON *.* TO rpl_user@'%' IDENTIFIED BY 'rpl_pass';FLUSH PRIVILEGES;SET SQL_LOG_BIN=1;" > /dev/null 2>&1
${BASEDIR}/bin/mysql -uroot -S$node3/node3_socket.sock -Bse "CHANGE MASTER TO MASTER_USER='rpl_user', MASTER_PASSWORD='rpl_pass' FOR CHANNEL 'group_replication_recovery';" > /dev/null 2>&1
${BASEDIR}/bin/mysql -uroot -S$node3/node3_socket.sock -Bse "START GROUP_REPLICATION;" > /dev/null 2>&1
else
${BASEDIR}/bin/mysql -uroot -S$node3/node3_socket.sock -Bse "START GROUP_REPLICATION;SELECT SLEEP(5);" > /dev/null 2>&1
fi
break
fi
gr_startup_chk $node3/node3.err
done
}
pquery_test(){
TRIAL=$[ ${TRIAL} + 1 ]
SOCKET=${RUNDIR}/${TRIAL}/socket.sock
echoit "====== TRIAL #${TRIAL} ======"
echoit "Ensuring there are no relevant servers running..."
KILLPID=$(ps -ef | grep "${RUNDIR}" | grep -v grep | awk '{print $2}' | tr '\n' ' ')
(sleep 0.2; kill -9 $KILLPID >/dev/null 2>&1; timeout -k4 -s9 4s wait $KILLPID >/dev/null 2>&1) &
timeout -k5 -s9 5s wait $KILLDPID >/dev/null 2>&1 # The sleep 0.2 + subsequent wait (cought before the kill) avoids the annoying 'Killed' message from being displayed in the output. Thank you to user 'Foonly' @ forums.whirlpool.net.au
echoit "Clearing rundir..."
rm -Rf ${RUNDIR}/*
if [ ${USE_GENERATOR_INSTEAD_OF_INFILE} -eq 1 ]; then
echoit "Generating new SQL inputfile using the SQL Generator..."
SAVEDIR=${PWD}
cd ${SCRIPT_PWD}/generator/
if [ ${TRIAL} -eq 1 -o $[ ${TRIAL} % ${GENERATE_NEW_QUERIES_EVERY_X_TRIALS} ] -eq 0 ]; then
if [ "${RANDOMD}" == "" ]; then
echoit "Assert: RANDOMD is empty. This should not happen. Terminating."
exit 1
fi
cp generator.sh generator${RANDOMD}.sh
sed -i "s|^[ \t]*OUTPUT_FILE[ \t]*=.*|OUTPUT_FILE=out${RANDOMD}|" generator${RANDOMD}.sh
./generator${RANDOMD}.sh ${QUERIES_PER_GENERATOR_RUN} >/dev/null
if [ ! -r out${RANDOMD}.sql ]; then
echoit "Assert: out${RANDOMD}.sql not present in ${PWD} after generator execution! This script left ${PWD}/generator${RANDOMD}.sh in place to check what happened"
exit 1
fi
rm -f generator${RANDOMD}.sh
if [[ "${MYEXTRA^^}" != *"ROCKSDB"* ]]; then # If this is not a RocksDB run, exclude RocksDB SE
sed -i "s|RocksDB|InnoDB|" out${RANDOMD}.sql
fi
if [[ "${MYEXTRA^^}" != *"HA_TOKUDB"* ]]; then # If this is not a TokuDB enabled run, exclude TokuDB SE
sed -i "s|TokuDB|InnoDB|" out${RANDOMD}.sql
fi
if [ ${ADD_INFILE_TO_GENERATED_SQL} -eq 1 ]; then
cat ${INFILE} >> out${RANDOMD}.sql
fi
fi
INFILE=${PWD}/out${RANDOMD}.sql
cd ${SAVEDIR}
fi
echoit "Generating new trial workdir ${RUNDIR}/${TRIAL}..."
ISSTARTED=0
if [[ ${PXC} -eq 0 && ${GRP_RPL} -eq 0 ]]; then
if check_for_version $MYSQL_VERSION "8.0.0" ; then
mkdir -p ${RUNDIR}/${TRIAL}/data ${RUNDIR}/${TRIAL}/tmp ${RUNDIR}/${TRIAL}/log # Cannot create /data/test, /data/mysql in 8.0
else
mkdir -p ${RUNDIR}/${TRIAL}/data/test ${RUNDIR}/${TRIAL}/data/mysql ${RUNDIR}/${TRIAL}/tmp ${RUNDIR}/${TRIAL}/log
fi
echo 'SELECT 1;' > ${RUNDIR}/${TRIAL}/startup_failure_thread-0.sql # Add fake file enabling pquery-prep-red.sh/reducer.sh to be used with/for mysqld startup issues
if [ ${QUERY_CORRECTNESS_TESTING} -eq 1 ]; then
echoit "Copying datadir from template for Primary mysqld..."
elif [[ ${PQUERY3} -eq 1 && ${TRIAL} -gt 1 ]]; then
echoit "Copying datadir from Trial $WORKDIR/$((${TRIAL}-1)) into $WORKDIR/${TRIAL}..."
else
echoit "Copying datadir from template..."
fi
if [ `ls -l ${WORKDIR}/data.template/* | wc -l` -eq 0 ]; then
echoit "Assert: ${WORKDIR}/data.template/ is empty? Check ${WORKDIR}/log/mysql_install_db.txt to see if the original template creation worked ok. Terminating."
echoit "Note that this can be caused by not having perl-Data-Dumper installed (sudo yum install perl-Data-Dumper), which is required for mysql_install_db."
exit 1
elif [[ ${PQUERY3} -eq 1 && ${TRIAL} -gt 1 ]]; then
cp -R ${WORKDIR}/$((${TRIAL}-1))/data/* ${RUNDIR}/${TRIAL}/data 2>&1
else
cp -R ${WORKDIR}/data.template/* ${RUNDIR}/${TRIAL}/data 2>&1
fi
MYEXTRA_SAVE_IT=${MYEXTRA}
if [ ${ADD_RANDOM_OPTIONS} -eq 1 ]; then # Add random mysqld --options to MYEXTRA
OPTIONS_TO_ADD=
NR_OF_OPTIONS_TO_ADD=$(( RANDOM % MAX_NR_OF_RND_OPTS_TO_ADD + 1 ))
for X in $(seq 1 ${NR_OF_OPTIONS_TO_ADD}); do
OPTION_TO_ADD="$(shuf --random-source=/dev/urandom ${OPTIONS_INFILE} | head -n1)"
if [ "$(echo ${OPTION_TO_ADD} | sed 's| ||g;s|.*query.alloc.block.size=1125899906842624.*||' )" != "" ]; then # http://bugs.mysql.com/bug.php?id=78238
OPTIONS_TO_ADD="${OPTIONS_TO_ADD} ${OPTION_TO_ADD}"
fi
done
echoit "ADD_RANDOM_OPTIONS=1: adding mysqld option(s) ${OPTIONS_TO_ADD} to this run's MYEXTRA..."
MYEXTRA="${MYEXTRA} ${OPTIONS_TO_ADD}"
if [ ${QUERY_CORRECTNESS_TESTING} -eq 1 ]; then
MYEXTRA2="${MYEXTRA2} ${OPTIONS_TO_ADD}"
fi
fi
if [ ${ADD_RANDOM_TOKUDB_OPTIONS} -eq 1 ]; then # Add random tokudb --options to MYEXTRA
OPTIONS_TO_ADD=
NR_OF_OPTIONS_TO_ADD=$(( RANDOM % MAX_NR_OF_RND_OPTS_TO_ADD + 1 ))
for X in $(seq 1 ${NR_OF_OPTIONS_TO_ADD}); do
OPTION_TO_ADD=
OPTION_TO_ADD="$(shuf --random-source=/dev/urandom ${TOKUDB_OPTIONS_INFILE} | head -n1)"
OPTIONS_TO_ADD="${OPTIONS_TO_ADD} ${OPTION_TO_ADD}"
done
echoit "ADD_RANDOM_TOKUDB_OPTIONS=1: adding TokuDB mysqld option(s) ${OPTIONS_TO_ADD} to this run's MYEXTRA..."
MYEXTRA="${MYEXTRA} ${OPTIONS_TO_ADD}"
if [ ${QUERY_CORRECTNESS_TESTING} -eq 1 ]; then
MYEXTRA2="${MYEXTRA2} ${OPTIONS_TO_ADD}"
fi
fi
if [ "${ADD_RANDOM_ROCKSDB_OPTIONS}" == "" ]; then # Backwards compatibility for .conf files without this option
ADD_RANDOM_ROCKSDB_OPTIONS=0
fi
if [ ${ADD_RANDOM_ROCKSDB_OPTIONS} -eq 1 ]; then # Add random rocksdb --options to MYEXTRA
OPTION_TO_ADD=
OPTIONS_TO_ADD=
NR_OF_OPTIONS_TO_ADD=$(( RANDOM % MAX_NR_OF_RND_OPTS_TO_ADD + 1 ))
for X in $(seq 1 ${NR_OF_OPTIONS_TO_ADD}); do
OPTION_TO_ADD="$(shuf --random-source=/dev/urandom ${ROCKSDB_OPTIONS_INFILE} | head -n1)"
OPTIONS_TO_ADD="${OPTIONS_TO_ADD} ${OPTION_TO_ADD}"
done
echoit "ADD_RANDOM_ROCKSDB_OPTIONS=1: adding RocksDB mysqld option(s) ${OPTIONS_TO_ADD} to this run's MYEXTRA..."
MYEXTRA="${MYEXTRA} ${OPTIONS_TO_ADD}"
if [ ${QUERY_CORRECTNESS_TESTING} -eq 1 ]; then
MYEXTRA2="${MYEXTRA2} ${OPTIONS_TO_ADD}"
fi
fi
echo "${MYEXTRA}" | if grep -qi "innodb[_-]log[_-]checksum[_-]algorithm"; then
# Ensure that mysqld server startup will not fail due to a mismatched checksum algo between the original MID and the changed MYEXTRA options
rm ${RUNDIR}/${TRIAL}/data/ib_log*
fi
PORT=$[50000 + ( $RANDOM % ( 9999 ) ) ]
if [ ${QUERY_CORRECTNESS_TESTING} -eq 1 ]; then
echoit "Starting Primary mysqld. Error log is stored at ${RUNDIR}/${TRIAL}/log/master.err"
else
echoit "Starting mysqld. Error log is stored at ${RUNDIR}/${TRIAL}/log/master.err"
fi
if [ "${VALGRIND_RUN}" == "0" ]; then
CMD="${BIN} ${MYSAFE} ${MYEXTRA} --basedir=${BASEDIR} --datadir=${RUNDIR}/${TRIAL}/data --tmpdir=${RUNDIR}/${TRIAL}/tmp \
--core-file --port=$PORT --pid_file=${RUNDIR}/${TRIAL}/pid.pid --socket=${SOCKET} \
--log-output=none --log-error=${RUNDIR}/${TRIAL}/log/master.err"
else
CMD="${VALGRIND_CMD} ${BIN} ${MYSAFE} ${MYEXTRA} --basedir=${BASEDIR} --datadir=${RUNDIR}/${TRIAL}/data --tmpdir=${RUNDIR}/${TRIAL}/tmp \
--core-file --port=$PORT --pid_file=${RUNDIR}/${TRIAL}/pid.pid --socket=${SOCKET} \
--log-output=none --log-error=${RUNDIR}/${TRIAL}/log/master.err"
fi
$CMD > ${RUNDIR}/${TRIAL}/log/master.err 2>&1 &
MPID="$!"
if [ ${QUERY_CORRECTNESS_TESTING} -eq 1 ]; then
echoit "Starting Secondary mysqld. Error log is stored at ${RUNDIR}/${TRIAL}/log2/master.err"
if check_for_version $MYSQL_VERSION "8.0.0" ; then
mkdir -p ${RUNDIR}/${TRIAL}/data2 ${RUNDIR}/${TRIAL}/tmp2 ${RUNDIR}/${TRIAL}/log2 # Cannot create /data/test, /data/mysql in 8.0
else
mkdir -p ${RUNDIR}/${TRIAL}/data2/test ${RUNDIR}/${TRIAL}/data2/mysql ${RUNDIR}/${TRIAL}/tmp2 ${RUNDIR}/${TRIAL}/log2
fi
echoit "Copying datadir from template for Secondary mysqld..."
cp -R ${WORKDIR}/data.template/* ${RUNDIR}/${TRIAL}/data2 2>&1
PORT2=$[ $PORT + 1 ]
if [ "${VALGRIND_RUN}" == "0" ]; then
CMD2="${BIN} ${MYSAFE} ${MYEXTRA2} --basedir=${BASEDIR} --datadir=${RUNDIR}/${TRIAL}/data2 --tmpdir=${RUNDIR}/${TRIAL}/tmp2 \
--core-file --port=$PORT2 --pid_file=${RUNDIR}/${TRIAL}/pid2.pid --socket=${RUNDIR}/${TRIAL}/socket2.sock \
--log-output=none --log-error=${RUNDIR}/${TRIAL}/log2/master.err"
else
CMD2="${VALGRIND_CMD} ${BIN} ${MYSAFE} ${MYEXTRA2} --basedir=${BASEDIR} --datadir=${RUNDIR}/${TRIAL}/data2 --tmpdir=${RUNDIR}/${TRIAL}/tmp2 \
--core-file --port=$PORT2 --pid_file=${RUNDIR}/${TRIAL}/pid2.pid --socket=${RUNDIR}/${TRIAL}/socket2.sock \
--log-output=none --log-error=${RUNDIR}/${TRIAL}/log2/master.err"
fi
$CMD2 > ${RUNDIR}/${TRIAL}/log2/master.err 2>&1 &
MPID2="$!"
sleep 1
fi
echo "## Good for reproducing mysqld (5.7+) startup issues only (full issues need a data dir, so use mysql_install_db or mysqld --init for those)" > ${RUNDIR}/${TRIAL}/start
echo "## Another strategy is to activate the data dir copy below, this way the server will be brought up with the same state as it crashed/was shutdown" >> ${RUNDIR}/${TRIAL}/start
echo "echo '=== Setting up directories...'" >> ${RUNDIR}/${TRIAL}/start
echo "rm -Rf ${RUNDIR}/${TRIAL}" >> ${RUNDIR}/${TRIAL}/start
echo "mkdir -p ${RUNDIR}/${TRIAL}/data ${RUNDIR}/${TRIAL}/tmp ${RUNDIR}/${TRIAL}/log" >> ${RUNDIR}/${TRIAL}/start
echo "#cp -R ./data/* ${RUNDIR}/${TRIAL}/data # When using this, please also remark the 'Data dir init' below to avoid overwriting the data directory" >> ${RUNDIR}/${TRIAL}/start
echo "echo '=== Data dir init...'" >> ${RUNDIR}/${TRIAL}/start
echo "${BIN} --no-defaults --initialize-insecure --basedir=${BASEDIR} --datadir=${RUNDIR}/${TRIAL}/data --tmpdir=${RUNDIR}/${TRIAL}/tmp --core-file --port=$PORT --pid_file=${RUNDIR}/${TRIAL}/pid.pid --socket=${SOCKET} --log-output=none --log-error=${RUNDIR}/${TRIAL}/log/master.err" >> ${RUNDIR}/${TRIAL}/start
echo "echo '=== Starting mysqld...'" >> ${RUNDIR}/${TRIAL}/start
echo "${CMD} > ${RUNDIR}/${TRIAL}/log/master.err 2>&1" >> ${RUNDIR}/${TRIAL}/start
if [ "${MYEXTRA}" != "" ]; then
echo "# Same startup command, but without MYEXTRA included:" >> ${RUNDIR}/${TRIAL}/start
echo "#$(echo ${CMD} | sed "s|${MYEXTRA}||") > ${RUNDIR}/${TRIAL}/log/master.err 2>&1" >> ${RUNDIR}/${TRIAL}/start
fi
if [ "${MYSAFE}" != "" ]; then
if [ "${MYEXTRA}" != "" ]; then
echo "# Same startup command, but without MYEXTRA and MYSAFE included:" >> ${RUNDIR}/${TRIAL}/start
echo "#$(echo ${CMD} | sed "s|${MYEXTRA}||;s|${MYSAFE}||") > ${RUNDIR}/${TRIAL}/log/master.err 2>&1" >> ${RUNDIR}/${TRIAL}/start
else
echo "# Same startup command, but without MYSAFE included (and MYEXTRA was already empty):" >> ${RUNDIR}/${TRIAL}/start
echo "#$(echo ${CMD} | sed "s|${MYSAFE}||") > ${RUNDIR}/${TRIAL}/log/master.err 2>&1" >> ${RUNDIR}/${TRIAL}/start
fi
fi
chmod +x ${RUNDIR}/${TRIAL}/start
echo "BASEDIR=$BASEDIR" > ${RUNDIR}/${TRIAL}/start_recovery
echo "${CMD//$RUNDIR/$WORKDIR} --init-file=${WORKDIR}/recovery-user.sql > ${WORKDIR}/${TRIAL}/log/master.err 2>&1 &" >> ${RUNDIR}/${TRIAL}/start_recovery ; chmod +x ${RUNDIR}/${TRIAL}/start_recovery
# New MYEXTRA/MYSAFE variables pass & VALGRIND run check method as of 2015-07-28 (MYSAFE & MYEXTRA stored in a text file inside the trial dir, VALGRIND file created if used)
if [ ${QUERY_CORRECTNESS_TESTING} -eq 1 ]; then
echo "${MYSAFE} ${MYEXTRA}" > ${RUNDIR}/${TRIAL}/MYEXTRA.left # When changing this, also search for/edit other '\.left' and '\.right' occurences in this file
echo "${MYSAFE} ${MYEXTRA2}" > ${RUNDIR}/${TRIAL}/MYEXTRA.right
else
echo "${MYSAFE} ${MYEXTRA}" > ${RUNDIR}/${TRIAL}/MYEXTRA
fi
echo "${MYINIT}" > ${RUNDIR}/${TRIAL}/MYINIT
if [ "${VALGRIND_RUN}" == "1" ]; then
touch ${RUNDIR}/${TRIAL}/VALGRIND
fi
# Restore orignal MYEXTRA for the next trial (MYEXTRA is no longer needed anywhere else. If this changes in the future, relocate this to below the changed code)
MYEXTRA=${MYEXTRA_SAVE_IT}
# Give up to x (start timeout) seconds for mysqld to start, but check intelligently for known startup issues like "Error while setting value" for options
if [ "${VALGRIND_RUN}" == "0" ]; then
echoit "Waiting for mysqld (pid: ${MPID}) to fully start..."
if [ ${QUERY_CORRECTNESS_TESTING} -eq 1 ]; then
echoit "Waiting for mysqld (pid: ${MPID2}) to fully start..."
fi
else
echoit "Waiting for mysqld (pid: ${MPID}) to fully start (note this is slow for Valgrind runs, and can easily take 35-90 seconds even on an high end server)..."
if [ ${QUERY_CORRECTNESS_TESTING} -eq 1 ]; then
echoit "Waiting for mysqld (pid: ${MPID2}) to fully start (note this is slow for Valgrind runs, and can easily take 35-90 seconds even on an high end server)..."
fi
fi
BADVALUE=0
FAILEDSTARTABORT=0
for X in $(seq 0 ${MYSQLD_START_TIMEOUT}); do
sleep 1
if ${BASEDIR}/bin/mysqladmin -uroot -S${SOCKET} ping > /dev/null 2>&1; then
if [ ${QUERY_CORRECTNESS_TESTING} -eq 1 ]; then
if ${BASEDIR}/bin/mysqladmin -uroot -S${RUNDIR}/${TRIAL}/socket2.sock ping > /dev/null 2>&1; then
break
fi
else
break
fi
fi
if [ "${MPID}" == "" ]; then echoit "Assert! ${MPID} empty. Terminating!"; exit 1; fi
if [ ${QUERY_CORRECTNESS_TESTING} -eq 1 ]; then
if [ "${MPID2}" == "" ]; then echoit "Assert! ${MPID2} empty. Terminating!"; exit 1; fi
fi
if grep -qi "ERROR. Aborting" ${RUNDIR}/${TRIAL}/log/master.err; then
if grep -qi "TCP.IP port. Address already in use" ${RUNDIR}/${TRIAL}/log/master.err; then
echoit "Assert! The text '[ERROR] Aborting' was found in the error log due to a IP port conflict (the port was already in use)"
removetrial
else
if [ ${ADD_RANDOM_OPTIONS} -eq 0 ]; then # Halt for ADD_RANDOM_OPTIONS=0 runs, they should not produce errors like these, as MYEXTRA should be high-quality/non-faulty
echoit "Assert! '[ERROR] Aborting' was found in the error log. This is likely an issue with one of the \$MEXTRA (or \$MYSAFE) startup parameters. Saving trial for further analysis, and dumping error log here for quick analysis. Please check the output against the \$MYEXTRA (or \$MYSAFE if it was modified) settings. You may also want to try setting \$MYEXTRA=\"${MYEXTRA}\" directly in start (as created by startup.sh using your base directory)."
grep "ERROR" ${RUNDIR}/${TRIAL}/log/master.err | tee -a /${WORKDIR}/pquery-run.log
savetrial
echoit "Remember to cleanup/delete the rundir: rm -Rf ${RUNDIR}"
exit 1
else # Do not halt for ADD_RANDOM_OPTIONS=1 runs, they are likely to produce errors like these as MYEXTRA was randomly changed
echoit "'[ERROR] Aborting' was found in the error log. This is likely an issue with one of the MYEXTRA startup parameters. As ADD_RANDOM_OPTIONS=1, this is likely to be encountered. Not saving trial. If you see this error for every trial however, set \$ADD_RANDOM_OPTIONS=0 & try running pquery-run.sh again. If it still fails, your base \$MYEXTRA setting is faulty."
grep "ERROR" ${RUNDIR}/${TRIAL}/log/master.err | tee -a /${WORKDIR}/pquery-run.log
FAILEDSTARTABORT=1
break
fi
fi
fi
if [ $(ls -l ${RUNDIR}/${TRIAL}/*/*core* 2>/dev/null | wc -l) -ge 1 ]; then break; fi # Break the wait-for-server-started loop if a core file is found. Handling of core is done below.
done
# Check if mysqld is alive and if so, set ISSTARTED=1 so pquery will run