forked from Percona-QA/percona-qa
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pquery-failing-sql.sh
executable file
·56 lines (51 loc) · 2.4 KB
/
pquery-failing-sql.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
#!/bin/bash
# Internal variables
SCRIPT_PWD=$(cd `dirname $0` && pwd)
WORKD_PWD=$PWD
#Checking TRIAL number
if [ "" == "$1" ]; then
echo "This script expects one parameter: the trial number to extract failing queries"
echo "Please execute this script from within pquery's working/run directory"
exit 1
else
TRIAL=$1
fi
failing_queries_core(){
rm -Rf ${WORKD_PWD}/$TRIAL/gdb_PARSE.txt
cat ${SCRIPT_PWD}/extract_query.gdb | sed "s|file /tmp/gdb_PARSE.txt|file ${WORKD_PWD}/$TRIAL/gdb_PARSE.txt|" > ${WORKD_PWD}/$TRIAL/extract_query.gdb
# For debugging purposes, remove ">/dev/null" on the next line and observe output
gdb ${BIN} ${CORE} >/dev/null 2>&1 < ${WORKD_PWD}/$TRIAL/extract_query.gdb
# The double quotes ; ; are to prevent parsing mishaps where the query is invalid and has opened a multi-line situation
grep '^\$' ${WORKD_PWD}/$TRIAL/gdb_PARSE.txt | sed 's/^[\$0-9a-fx =]*"//;s/"$//;s/[ \t]*$//;s|\\"|"|g;s/$/; ;/' | grep -v '^\$' >> ${WORKD_PWD}/$TRIAL/${TRIAL}.sql.failing
}
failing_queries_error_log(){
# The double quotes ; ; are to prevent parsing mishaps where the query is invalid and has opened a multi-line situation
FAILING_QUERY_ERR=$(grep "Query ([x0-9a-fA-F]*):" $ERRLOG | sed 's|^Query ([x0-9a-fA-F]*): ||;s|$|; ;|')
if [ "$(echo ${FAILING_QUERY_ERR} | sed 's|: [0-9]\+|: 0|')" != "Connection ID (thread ID): 0; ;" ]; then # http://bugs.mysql.com/bug.php?id=81651
echo "${FAILING_QUERY_ERR}" >> ${WORKD_PWD}/$TRIAL/${TRIAL}.sql.failing
else
echo "SELECT 1;" >> ${WORKD_PWD}/$TRIAL/${TRIAL}.sql.failing
fi
}
# Second parameter is used only by the pquery-prep-red.sh script. If it is used, we know this is a pquery-prep-red.sh run
if [ "$2" == "1" ]; then
failing_queries_core
elif [ "$2" == "2" ]; then
failing_queries_error_log
else # Script is being manually executed, not via pquery-prep-red.sh
rm -Rf ${WORKD_PWD}/$TRIAL/${TRIAL}.sql.failing
ERRLOG="${WORKD_PWD}/${TRIAL}/log/master.err"
BIN=`ls -1 ${WORKD_PWD}/mysqld/mysqld 2>&1 | head -n1 | grep -v "No such file"`
if [ ! -r $BIN ]; then
echo "Assert! mysqld binary '$BIN' could not be read"
exit 1
fi
CORE=`ls -1 ${WORKD_PWD}/${TRIAL}/data/*core* 2>&1 | head -n1 | grep -v "No such file"`
if [ ! -r $CORE ]; then
echo "Assert! coredump '$CORE' could not be read"
exit 1
fi
failing_queries_core
failing_queries_error_log
echo "Saved failing queries in ${WORKD_PWD}/$TRIAL/${TRIAL}.sql.failing"
fi