Merge more skip-load-data-file changes.

This commit is contained in:
Daniel Nichter
2012-08-01 09:41:36 -06:00
4 changed files with 94 additions and 67 deletions

View File

@@ -1,61 +1,69 @@
#!/bin/sh #!/bin/sh
start_ts=$(date +%s)
PIDFILE="/tmp/PORT/data/mysql_sandboxPORT.pid" PIDFILE="/tmp/PORT/data/mysql_sandboxPORT.pid"
SOCKETFILE="/tmp/PORT/mysql_sandboxPORT.sock" SOCKETFILE="/tmp/PORT/mysql_sandboxPORT.sock"
BASEDIR="PERCONA_TOOLKIT_SANDBOX" BASEDIR="PERCONA_TOOLKIT_SANDBOX"
sandbox_is_alive() { sandbox_is_alive() {
local pid=`cat /tmp/PORT/data/mysql_sandboxPORT.pid 2>/dev/null` # First, all these files must exist.
if [ -z "$pid" ]; then [ -f $PIDFILE -a -S $SOCKETFILE -a -s "/tmp/PORT/data/ibdata1" ] || return 1
return 0
fi
kill -0 $pid
local ps_alive=$?
# And that PID file must have a PID.
local pid=$(cat /tmp/PORT/data/mysql_sandboxPORT.pid 2>/dev/null)
[ "$pid" ] || return 1
# Second, MySQL is truly alive when it respond to a ping.
# It's not enough that the mysqld process is running because
# InnoDB can take time to create ibdata1, etc. So MySQL is
# only alive when it responds to queries.
$BASEDIR/bin/mysqladmin --defaults-file="/tmp/PORT/my.sandbox.cnf" ping >/dev/null 2>&1 $BASEDIR/bin/mysqladmin --defaults-file="/tmp/PORT/my.sandbox.cnf" ping >/dev/null 2>&1
local mysql_alive=$? [ $? -eq 0 ] || return 1
if [ $ps_alive -eq 0 ] && [ $mysql_alive -eq 0 ]; then
return 1 # sandbox is alive
else
return 0 return 0
fi
} }
if [ -f "$PIDFILE" ] || [ -S "$SOCKETFILE" ]; then _seq() {
sandbox_is_alive local i="$1"
if [ $? -eq 1 ]; then awk "BEGIN { for(i=1; i<=$i; i++) print i; }"
}
# #############################################################################
# Script starts here
# #############################################################################
# If there's a PID or socket file, MySQL may already be alive.
if [ -f "$PIDFILE" -o -S "$SOCKETFILE" ]; then
if sandbox_is_alive; then
echo "MySQL test server on port PORT is running." echo "MySQL test server on port PORT is running."
exit 0 exit 0
fi fi
# Sandbox exists but is not running. Clear it and then start it. # Sandbox exists but is not running. Clear it and then start it.
/tmp/PORT/stop >/dev/null 2>&1 /tmp/PORT/stop >/dev/null 2>&1
rm -rf $PIDFILE
rm -rf $SOCKETFILE
fi fi
PWD=`pwd`
cd $BASEDIR
$BASEDIR/bin/mysqld_safe --defaults-file=/tmp/PORT/my.sandbox.cnf > /dev/null 2>&1 &
cd $PWD
echo -n "Starting MySQL test server on port PORT... " echo -n "Starting MySQL test server on port PORT... "
for i in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15; do
if [ -f $PIDFILE -a -S $SOCKETFILE -a -s "/tmp/PORT/data/ibdata1" ]; then
break
fi
sleep 1
done
for i in 1 2 3 4 5; do # Start MySQL.
sandbox_is_alive cwd=$PWD
if [ $? -eq 1 ]; then cd $BASEDIR
echo "OK" $BASEDIR/bin/mysqld --defaults-file=/tmp/PORT/my.sandbox.cnf > /dev/null 2>&1 &
cd $PWD
# Wait for MySQL to actually be up, i.e. to respond to queries.
for i in $(_seq 60); do
if sandbox_is_alive; then
end_ts=$(date +%s)
t=$((end_ts - start_ts))
echo "OK (${t}s)"
exit 0 exit 0
fi fi
sleep 1 sleep 1
done done
echo "FAILED" end_ts=$(date +%s)
t=$((end_ts - start_ts))
echo "FAILED (${t}s)"
exit 1 exit 1

View File

@@ -1,40 +1,58 @@
#!/bin/sh #!/bin/sh
start_ts=$(date +%s)
PIDFILE="/tmp/PORT/data/mysql_sandboxPORT.pid" PIDFILE="/tmp/PORT/data/mysql_sandboxPORT.pid"
SOCKETFILE="/tmp/PORT/mysql_sandboxPORT.sock"
BASEDIR="PERCONA_TOOLKIT_SANDBOX" BASEDIR="PERCONA_TOOLKIT_SANDBOX"
sandbox_is_alive() { sandbox_is_alive() {
local pid=`cat /tmp/PORT/data/mysql_sandboxPORT.pid 2>/dev/null` # First, all these files must exist.
if [ -z "$pid" ]; then [ -f $PIDFILE -a -S $SOCKETFILE -a -s "/tmp/PORT/data/ibdata1" ] || return 1
return 0
fi
kill -0 $pid
local ps_alive=$?
# And that PID file must have a PID.
local pid=$(cat /tmp/PORT/data/mysql_sandboxPORT.pid 2>/dev/null)
[ "$pid" ] || return 1
# Second, MySQL is truly alive when it respond to a ping.
# It's not enough that the mysqld process is running because
# InnoDB can take time to create ibdata1, etc. So MySQL is
# only alive when it responds to queries.
$BASEDIR/bin/mysqladmin --defaults-file="/tmp/PORT/my.sandbox.cnf" ping >/dev/null 2>&1 $BASEDIR/bin/mysqladmin --defaults-file="/tmp/PORT/my.sandbox.cnf" ping >/dev/null 2>&1
local mysql_alive=$? [ $? -eq 0 ] || return 1
if [ $ps_alive -eq 0 ] && [ $mysql_alive -eq 0 ]; then
return 1 # sandbox is alive
else
return 0 return 0
fi
} }
exit_status=0 _seq() {
local i="$1"
awk "BEGIN { for(i=1; i<=$i; i++) print i; }"
}
# #############################################################################
# Script starts here
# #############################################################################
echo -n "Stopping MySQL test server on port PORT... " echo -n "Stopping MySQL test server on port PORT... "
sandbox_is_alive if sandbox_is_alive; then
if [ $? -eq 1 ]; then
$BASEDIR/bin/mysqladmin --defaults-file=/tmp/PORT/my.sandbox.cnf shutdown $BASEDIR/bin/mysqladmin --defaults-file=/tmp/PORT/my.sandbox.cnf shutdown
exit_status=$?
fi fi
if [ $exit_status -eq 0 ]; then for i in $(_seq 60); do
echo "OK" if sandbox_is_alive; then
else sleep 1
echo "FAILED" continue
fi fi
rm -rf $PIDFILE 2>/dev/null
rm -rf $SOCKETFILE 2>/dev/null
end_ts=$(date +%s)
t=$((end_ts - start_ts))
echo "OK (${t}s)"
exit 0
done
exit $exit_status end_ts=$(date +%s)
t=$((end_ts - start_ts))
echo "FAILED (${t}s)"
exit 1

View File

@@ -1,8 +1,13 @@
#!/bin/sh #!/bin/sh
# This script makes Maatkit sandbox servers for mk-test-env. # This script starts a Percona Toolkit sandbox sever. sandbox/test-env
# It's a "low level" script that is not usually called directly. # uses it, and many tests use it to create special, temporary sandbox
# Exit 0 means everything was successful, else exit 1 on problems. # servers. The actual startup is done by /tmp/PORT/start, which this
# script calls after doing a bunch of sanity checks.
#
# Exit 0 if the sandbox server started ok, else 1 and debug_sandbox()
# is caleld to print some info to STDERR about what state the sandbox
# server might have been in.
die() { die() {
echo $1 >&2 echo $1 >&2
@@ -10,16 +15,12 @@ die() {
} }
debug_sandbox() { debug_sandbox() {
set -x
local port="$1" local port="$1"
echo
echo "MySQL processes:" >&2
ps x | grep mysql >&2 ps x | grep mysql >&2
echo
if [ -d "/tmp/$port" ]; then if [ -d "/tmp/$port" ]; then
ls -lh /tmp/$port/* >&2 ls -lh /tmp/$port/* >&2
echo
cat /tmp/$port/data/mysqld.log >&2 cat /tmp/$port/data/mysqld.log >&2
echo
tail -n 100 /tmp/$port/data/genlog >&2 tail -n 100 /tmp/$port/data/genlog >&2
else else
echo "/tmp/$port does not exist" >&2 echo "/tmp/$port does not exist" >&2
@@ -28,8 +29,8 @@ debug_sandbox() {
make_sandbox() { make_sandbox() {
# Make the sandbox dir and extract the base files. # Make the sandbox dir and extract the base files.
rm -rf /tmp/$port || die "can't rm /tmp/$port" rm -rf /tmp/$port || die "Failed to rm /tmp/$port"
mkdir /tmp/$port || die "mkdir /tmp/$port failed" mkdir /tmp/$port || die "Failed to mkdir /tmp/$port"
cp $PERCONA_TOOLKIT_BRANCH/sandbox/servers/$version/my.sandbox.cnf /tmp/$port cp $PERCONA_TOOLKIT_BRANCH/sandbox/servers/$version/my.sandbox.cnf /tmp/$port
tar xzf $PERCONA_TOOLKIT_BRANCH/sandbox/servers/$version/data.tar.gz -C /tmp/$port tar xzf $PERCONA_TOOLKIT_BRANCH/sandbox/servers/$version/data.tar.gz -C /tmp/$port
@@ -84,7 +85,7 @@ make_sandbox() {
/tmp/$port/use -e 'SHOW /*!40100 ENGINE*/ INNODB STATUS' | grep 'INNODB MONITOR OUTPUT' >/dev/null 2>&1 /tmp/$port/use -e 'SHOW /*!40100 ENGINE*/ INNODB STATUS' | grep 'INNODB MONITOR OUTPUT' >/dev/null 2>&1
# grep exits 0 if lines are found # grep exits 0 if lines are found
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
echo "Sandbox $type $port doesn't have InnoDB" >&2 echo "Sandbox $type $port doesn't have InnoDB." >&2
debug_sandbox $port debug_sandbox $port
exit 1 exit 1
fi fi
@@ -146,7 +147,7 @@ fi
cd $PERCONA_TOOLKIT_BRANCH/sandbox cd $PERCONA_TOOLKIT_BRANCH/sandbox
# This script is usually called by mk-test-env which discovers and # This script is usually called by test-env which discovers and
# sets PERCONA_TOOLKIT_SANDBOX. If this script is called directly, # sets PERCONA_TOOLKIT_SANDBOX. If this script is called directly,
# then the caller is reponsible for setting PERCONA_TOOLKIT_SANDBOX. # then the caller is reponsible for setting PERCONA_TOOLKIT_SANDBOX.
# PERCONA_TOOLKIT_SANDBOX points to a base directory containing the # PERCONA_TOOLKIT_SANDBOX points to a base directory containing the

View File

@@ -345,7 +345,7 @@ case $opt in
fi fi
;; ;;
kill) kill)
# This is a blunt approach for killing the entire mk test env # This is a blunt approach for killing the entire test env
# when a polite stop fails. It uses kill -9 as a last resort. # when a polite stop fails. It uses kill -9 as a last resort.
for port in 12349 12348 12347 12346 12345 2903 2902 2901 2900; do for port in 12349 12348 12347 12346 12345 2903 2902 2901 2900; do
kill_sandbox $port kill_sandbox $port