~dbpercona/percona-qa/readme

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
#!/bin/bash
# Created by Roel Van de Paar, Percona LLC

# This script quickly tests all available mysqld options

if [ ! -r ./bin/mysqld ]; then
  if [ ! -r ./mysqld ]; then
    echo "This script quickly tests all mysqld options. Note it expects cores to be written to /cores/core.pid. Location can be changed in-script, but not filename"
    echo "To set your server up in this way (in terms of corefile generation), see core file setting part of setup_server.sh, available at lp:percona-qa"
    echo "Error: no ./bin/mysqld or ./mysqld found!"
    exit 1
  else 
    cd ..
  fi
fi

# User Variables
CORELOC="/cores"  # No trailing slash

# Option values array ('' = use option without a value, which works for non-value options, for example; --core-file)
declare -a VALUES=('-1' '0' '1' '2' '10' '1026' '-1125899906842624' '1125899906842624' 'a' '&&1' '%' 'NONE' '-NULL' 'NULL' '.' '..' '')

# Vars
MYSQLD_START_TIMEOUT=10  # Default: 30, but this may be tuned down on non-loaded servers with single threaded testruns. Increase when there is more load.
RANDOMD=$(echo $RANDOM$RANDOM$RANDOM | sed 's/..\(......\).*/\1/')
WORKDIR=/tmp/$RANDOMD  # Here we keep the log files, option list, failed items
RUNDIR=/dev/shm/$RANDOMD  # Here we keep a copy of the data template dir and here we do the actual mysqld runs (--datadir=...)
FINDS="^Error:|ERROR|allocated at line|missing DBUG_RETURN|^safe_mutex:|Invalid.*old.*table or database|InnoDB: Warning|InnoDB: Error:|InnoDB: Operating system error|Error while setting value"
IGNOR="Lock wait timeout exceeded|Deadlock found when trying to get lock|innodb_log_block_size has been changed|Sort aborted:|ERROR: the age of the last checkpoint is [0-9]*,|consider increasing server sort buffer size|.ERROR. Event Scheduler:.*does[ ]*n.t exist"
CORES=0

echoit(){
  echo "[$(date +'%T')] [$CORES] [$OPTIONS] $1"
  echo "[$(date +'%T')] [$CORES] [$OPTIONS] $1" >> /$WORKDIR/test_mysqld_options.log
}

test_options(){
  OPTIONS=$(echo $OPTIONS | sed 's|[ ]*$||') 
  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) &
  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/data/* $RUNDIR/log/* $RUNDIR/pid.pid $RUNDIR/socket.sock
  echoit "Generating new workdir..."
  mkdir -p $RUNDIR/data/test $RUNDIR/data/mysql $RUNDIR/log
  echoit "Copying datadir from template..."
  cp -R $RUNDIR/data.template/* $RUNDIR/data
  PORT=$[50000 + ( $RANDOM % ( 9999 ) ) ] 
  echoit "Starting mysqld..."
  CMD="./bin/mysqld --basedir=$PWD --datadir=$RUNDIR/data --core-file \
                    --port=$PORT --pid_file=$RUNDIR/pid.pid --socket=$RUNDIR/socket.sock \
                    --log-error=$RUNDIR/log/master.err $OPTIONS"
  $CMD >> $RUNDIR/log/master.err 2>&1 &
  MPID="$!"
  # Give up to 30 seconds for mysqld to start, but check intelligently for known startup issues like "Error while setting value" for options
  echoit "Waiting for mysqld (pid: $MPID) to fully start..."
  BADVALUE=0
  for X in $(seq 0 $MYSQLD_START_TIMEOUT); do
    sleep 1
    if ./bin/mysqladmin -uroot -S$RUNDIR/socket.sock ping > /dev/null 2>&1; then
      break
    fi
    if egrep -qi "Error while setting value" $RUNDIR/log/master.err; then
      BADVALUE=1
      break
    elif [ "$MPID" == "" ]; then
      echo_it "Assert! $MPID empty"
      exit 1
    fi
  done

  if [ $BADVALUE -eq 1 ]; then
    echoit "=== Fail: An option value is reported to be erroneous by mysqld."
  else
    # Check if mysqld is alive
    if ./bin/mysqladmin -uroot -S$RUNDIR/socket.sock ping > /dev/null 2>&1; then
      echoit "Server started ok. Now checking results..."
      if egrep -qi "value.*adjusted to" $RUNDIR/log/master.err; then
        echoit "=== Modified: an option value was modified by mysqld."
      elif egrep -qi "ignoring option.*due to invalid value" $RUNDIR/log/master.err; then
        echoit "=== Ignored: an option value was ignored by mysqld." 
      elif egrep -qi "option.*value.*wasn't recognized" $RUNDIR/log/master.err; then
        echoit "=== Not recognized: an option value was not recognized by mysqld."
      else
        echoit "=== Success: option (set) worked OK!"
      fi
    else
      echoit "Server failed to start correctly. Checking if there is a coredump for the PID..."
      sleep 2  # Delay to ensure core was written completely
      if [ $(ls -l ${CORELOC}/core.${MPID}* 2>/dev/null | wc -l) -ge 1 ]; then
        CORES=$[ $CORES + 1 ]
        echoit "=== !!! Fail: an option failed and generated a core at $(ls ${CORELOC}/core.${MPID}*)"
        echoit "Copying vardir from $RUNDIR/data to $WORKDIR/data.${MPID} and moving core"
        mv $RUNDIR/data $WORKDIR/data.${MPID}
        mv $RUNDIR/log $WORKDIR/log.${MPID}
        mv ${CORELOC}/core.${MPID}* $WORKDIR/data.${MPID}/
      else
        echoit "=== ??? Fail: an option failed, but did not generate a core. Relevant error log content:"
        egrep "$FINDS" $RUNDIR/log/master.err | grep -v "$IGNOR" | sed 's|^|^  |'
        egrep "$FINDS" $RUNDIR/log/master.err | grep -v "$IGNOR" | sed 's|^|^  |' >> /$WORKDIR/test_mysqld_options.log
      fi 
    fi
  fi
}

# Setup
rm -Rf $WORKDIR $RUNDIR
mkdir $WORKDIR $RUNDIR
echoit "Workdir: $WORKDIR | Rundir: $RUNDIR | Basedir: $PWD"
echoit "Generating initial rundir subdirectories..."
mkdir -p $RUNDIR/data/test $RUNDIR/data/mysql $RUNDIR/log
echoit "Generating datadir template (using mysql_install_db)..."
if [ -r ./bin/mysql_install_db ]; then 
  ./bin/mysql_install_db --force --no-defaults --basedir=$PWD --datadir=$RUNDIR/data > $RUNDIR/log/mysql_install_db.txt 2>&1
elif [ -r ./scripts/mysql_install_db ]; then 
  ./scripts/mysql_install_db --force --no-defaults --basedir=$PWD --datadir=$RUNDIR/data > $RUNDIR/log/mysql_install_db.txt 2>&1
else 
  echo "Error: mysql_install_db not found in $PWD/scripts nor in $PWD/bin"
  exit 1
fi
mv $RUNDIR/data $RUNDIR/data.template

# Fetch mysqld options
echoit "Fetching options from mysqld"
./bin/mysqld --help --verbose 2>&1 | grep "^  --[a-z]" | sed 's|^  ||;s| .*||;s|=#||;s|\[=name\]||;s|\[\]||;s|=name||' > /$WORKDIR/mysqld_options.txt

option_add(){
  if [ "$2" == "" ]; then
    OPTIONS="${OPTIONS}$1 "
  else
    OPTIONS="${OPTIONS}$1=$2 "
  fi
}

# Start actual option testing, combinations up to 4 options supported (and easy to expand)
echoit "Starting option/value testing iterations"
COUNT=0
LEVEL=1
for VALUE4 in "${VALUES[@]}"; do
  for OPTION4 in $(cat /$WORKDIR/mysqld_options.txt); do
    for VALUE3 in "${VALUES[@]}"; do
      for OPTION3 in $(cat /$WORKDIR/mysqld_options.txt); do
        for VALUE2 in "${VALUES[@]}"; do
          for OPTION2 in $(cat /$WORKDIR/mysqld_options.txt); do
            for VALUE1 in "${VALUES[@]}"; do
              for OPTION1 in $(cat /$WORKDIR/mysqld_options.txt); do
                OPTIONS=""
                COUNT=$[ $COUNT + 1 ]
                if [ $COUNT -ge 10 ]; then  # Periodical reporting of workdir
                  COUNT=0
                  echoit "Periodical reporting: Workdir: $WORKDIR | Rundir: $RUNDIR"
                fi
                if [ $LEVEL -ge 4 ]; then
                  option_add $OPTION4 $VALUE4
                fi
                if [ $LEVEL -ge 3 ]; then
                  option_add $OPTION3 $VALUE3
                fi
                if [ $LEVEL -ge 2 ]; then
                  option_add $OPTION2 $VALUE2 
                fi
                option_add $OPTION1 $VALUE1
                test_options
                # Debug 
                # read -p "Press enter to continue..."
              done
            done
            LEVEL=2
          done
        done
        LEVEL=3
      done
    done
    LEVEL=4
  done
done