forked from Percona-QA/percona-qa
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pquery-mass-reduce.sh
executable file
·47 lines (42 loc) · 2.62 KB
/
pquery-mass-reduce.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
#!/bin/bash
# Created by Roel Van de Paar, Percona LLC
# This script starts x (first option) new reducers based on the pquery-results.sh output (one reducer per issue seen - using the first failing trail for that issue)
# Internal variables
SCRIPT_PWD=$(cd `dirname $0` && pwd)
if [ "$1" == "" ]; then
echo "Assert: This script expects one option, namely how many reducers to start on pquery-results.sh output."
echo "Additionally one can pass a second option to 'skip' a number of results. For example, ./pquery-mass-reduce.sh 10 5 will start to reduce items 6-16 of the pquery-results.sh output."
echo "Note that it is likely not wise to start more then 10-15 reducers, unless you are using a very high-end server."
echo "That last note is applicable when pquery-go-expert.sh was used. If not, then likely much less (2-4) reducers should be started, or they need to be monitored more closely. For the reason why, please see the extensive help text near the top of the pquery-go-expert.sh script"
echo "Terminating."
exit 1
elif [ "$(echo $1 | sed 's|^[0-9]\+||')" != "" ]; then
echo "Assert: option passed is not numeric. If you do not know how to use this script, execute it without options to see more information"
exit 1
fi
if [ "$2" == "" ]; then
SKIP=0
elif [ "$(echo $2 | sed 's|^[0-9]\+||')" != "" ]; then
echo "Assert: an option passed is not numeric. If you do not know how to use this script, execute it without options to see more information"
exit 1
else
SKIP=$2
fi
TOTAL=$[ $1 + $SKIP ]
RND=${RANDOM}
# For each issue, take the first trial number and sent it to a file
${SCRIPT_PWD}/pquery-results.sh | grep -o "reducers.*" | sed 's|reducers ||;s|[,)]\+.*||' > /tmp/${RND}.txt
# Now put the issues into an issue array
mapfile -t issues < /tmp/${RND}.txt; rm -f /tmp/${RND}.txt 2>/dev/null
# Now loop though the issues. When the counter reaches the amount passed to this scirpt, the loop will terminate
COUNTER=0
for TRIAL in "${issues[@]}"; do
COUNTER=$[ $COUNTER + 1 ]
if [ $COUNTER -gt $SKIP ]; then
screen -admS s${COUNTER} bash -c "./reducer${TRIAL}.sh;bash" # Start reducer, and when done give a usable bash prompt
sleep 0.3 # Avoid a /dev/shm/<epoch> directory conflict (yes, it happened)
echo "Started screen with name 's${COUNTER}' and started ./reducer${TRIAL}.sh within it for issue: $(grep " TEXT=" reducer${TRIAL}.sh | sed 's| TEXT="||;s|"$||')"
fi
if [ $COUNTER -eq $TOTAL ]; then break; fi
done
echo "Done! started $[ $COUNTER - $SKIP ] screen sessions named s$[ ${SKIP} + 1 ]-${COUNTER}. To reconnect to any of them, use: $ screen -d -r s<nr> where <nr> matches the number listed above!"