#!/bin/bash

# Copyright (c) 2013, 2014 Oracle and/or its affiliates. All rights reserved.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA

if [ "$MYSQL_HOME" = "" ] ; then
  source ../env.properties
  echo "MYSQL_HOME=$MYSQL_HOME"
  PATH="$MYSQL_LIBEXEC:$MYSQL_BIN:$PATH"
fi

#set -x

cwd="$(pwd)"
mylogdir="$cwd/ndblog"
mkdir -p "$mylogdir"
myini="$cwd/../config.ini"

echo
echo start mgmd...
# options:
# --print-defaults         Print the program argument list and exit.
# -P, --print-full-config  Print full config and exit
# -c, --ndb-connectstring=name  Set connect string for connecting to ndb_mgmd
#                          "[nodeid=<id>;][host=]<hostname>[:<port>]"
#                          Overrides entries in NDB_CONNECTSTRING and my.cnf
# --bind-address=name      Local bind address
# -f, --config-file=name   Specify cluster configuration file
# --mycnf                  Read cluster config from my.cnf
# --initial                Delete all binary config files and start from
#                          config.ini or my.cnf.  Only in > 6.3
( cd "$mylogdir" ; "ndb_mgmd" --initial -f "$myini" )
#( cd "$mylogdir" ; "ndb_mgmd" --debug --initial -f "$myini" )
#
# XXX no effect: -c "localhost:1187"
#( cd "$mylogdir" ; "ndb_mgmd" --initial -c "localhost:1187" -f "$myini" )
# see ndb_1_cluster.log
#     [MgmtSrvr] INFO     -- Got initial configuration from '../../config.ini', will try to set it when all ndb_mgmd(s) started
#     [MgmtSrvr] INFO     -- Id: 1, Command port: *:1186
# MgmtSrvr.cpp sets default port:
#   ndb_mgm_set_connectstring(mgm_handle, buf.c_str());
# ConfigManager.cpp likely not called:
#   m_connect_string(connect_string),
#
# port number seems not supported as part of --bind-address="localhost:1187"
#( cd "$mylogdir" ; "ndb_mgmd" --bind-address="localhost:1187" -f "$myini" )

#echo
#ps -efa | grep ndb

#set +x


#!/bin/bash

# Copyright (c) 2010, 2014, Oracle and/or its affiliates. All rights reserved.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA

if [ "$MYSQL_HOME" = "" ] ; then
  source ../env.properties
  echo MYSQL_HOME=$MYSQL_HOME
  PATH="$MYSQL_LIBEXEC:$MYSQL_BIN:$PATH"
fi

#set -x

cwd="$(pwd)"
mylogdir="$cwd/ndblog"
mkdir -p "$mylogdir"
user="$(whoami)"
mycnf="$cwd/../my.cnf"
myerr="$mylogdir/mysqld.log.err"
mysock="/tmp/mysql.sock"
#mysock="$mylogdir/mysql.sock"

echo
echo start mysqld...
( cd $MYSQL_HOME ; "mysqld_safe" --defaults-file="$mycnf" --user="$user" --log-error="$myerr" --socket="$mysock" & )
#
# debug:
#( cd $MYSQL_HOME ; "mysqld_safe" --defaults-file="$mycnf" --user="$user" --log-error="$myerr" -#d & )
# crashes when --debug/-# at beginning:
#( cd $MYSQL_HOME ; "$mysqld" --debug --defaults-file="$mycnf" --user="$user" --log-error="$myerr" & )

# need some extra time
for ((i=0; i<10; i++)) ; do printf "." ; sleep 1 ; done ; echo

#echo
#ps -efa | grep mysqld

./show_cluster.sh

#set +x


#!/bin/bash

# Copyright (c) 2010, 2014, Oracle and/or its affiliates. All rights reserved.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA

if [ "$MYSQL_HOME" = "" ] ; then
  source ../env.properties
  echo MYSQL_HOME=$MYSQL_HOME
  PATH="$MYSQL_LIBEXEC:$MYSQL_BIN:$PATH"
fi

#set -x

./start_mgmd.sh

# need some extra time
for ((i=0; i<10; i++)) ; do printf "." ; sleep 1 ; done ; echo

cwd="$(pwd)"
mylogdir="$cwd/ndblog"
mkdir -p "$mylogdir"
myini="$cwd/../config.ini"
nNodes=$(grep -c '^ *\[ndbd\]' "$myini")

echo
echo "starting $nNodes data nodes..."
for ((i=0; i<nNodes; i++)) ; do
    echo
    echo "start ndbd..."
    # apparently, these options need to come first:
    # --print-defaults        Print the program argument list and exit.
    # --no-defaults           Don't read default options from any option file.
    # --defaults-file=#       Only read default options from the given file #.
    # --defaults-extra-file=# Read this file after the global files are read.
    #( cd "$mylogdir" ; "ndbd" --initial )
    ( cd "$mylogdir" ; "ndbd" -c "$NDB_CONNECT" --initial )
done

#echo
#ps -efa | grep ndb

# need some extra time
for ((i=0; i<3; i++)) ; do printf "." ; sleep 1 ; done ; echo

timeout=60
echo
echo "waiting ($timeout s) for ndbd to start up..."
"ndb_waiter" -c "$NDB_CONNECT" -t $timeout

# need some extra time
for ((i=0; i<3; i++)) ; do printf "." ; sleep 1 ; done ; echo

./show_cluster.sh

#set +x


#!/bin/bash

# Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA

./stop_mysqld.sh

# need some extra time
#for ((i=0; i<1; i++)) ; do printf "." ; sleep 1 ; done

./stop_ndb.sh


#!/bin/bash

# Copyright (c) 2010, 2014, Oracle and/or its affiliates. All rights reserved.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA

if [ "$MYSQL_HOME" = "" ] ; then
  source ../env.properties
  echo MYSQL_HOME=$MYSQL_HOME
  PATH="$MYSQL_LIBEXEC:$MYSQL_BIN:$PATH"
fi

#set -x

cwd="$(pwd)"
mylogdir="$cwd/ndblog"
mysock="/tmp/mysql.sock"
#mysock="$mylogdir/mysql.sock"

echo shut down mysqld...
#"mysqladmin" shutdown
"mysqladmin" --socket="$mysock" shutdown

# need some extra time
for ((i=0; i<5; i++)) ; do printf "." ; sleep 1 ; done ; echo

#echo
#ps -efa | grep mysqld

#set +x


#!/bin/bash

# Copyright (c) 2010, 2014, Oracle and/or its affiliates. All rights reserved.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA

if [ "$MYSQL_HOME" = "" ] ; then
  source ../env.properties
  echo MYSQL_HOME=$MYSQL_HOME
  PATH="$MYSQL_LIBEXEC:$MYSQL_BIN:$PATH"
fi

#set -x

#./show_cluster.sh

echo shut down NDB...
./mgm.sh -e shutdown -t 1

timeout=60
echo
echo "waiting ($timeout s) for ndb to shut down..."
"ndb_waiter" -c "$NDB_CONNECT" -t $timeout --no-contact

# need some extra time for ndb_mgmd to terminate
for ((i=0; i<10; i++)) ; do printf "." ; sleep 1 ; done ; echo

#echo
#ps -efa | grep ndb

#set +x


#!/bin/sh

# Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA

set -e

base="`dirname $0`"
source "$base"/parseargs.sh

ecp="set optimizer_switch = 'engine_condition_pushdown=on';"

if [ "$load" ]
then
    source "$base"/load.sh
fi

if [ "$runtime" -o "$loops" ]
then
    source "$base"/run.sh
fi


#!/bin/sh

# Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA

set -e

base="`dirname $0`"
source "$base"/parseargs.sh

# Create database with a case sensitive collation to ensure a deterministic
# resultset when 'LIMIT' is specified:
charset_spec=""
if [ "$charset" ]
then
    charset_spec="character set $charset"
fi

sprocs="copydb alter_engine analyze_db"
if [ "$oj" ]
then
    sprocs="oj_schema_mod copydb alter_engine oj_schema_mod_ndb analyze_db"
fi

$mysql_exe -e "drop database if exists ${innodb_db};"
$mysql_exe -e "drop database if exists ${ndb_db};"
$mysql_exe -e "create database ${innodb_db} ${charset_spec};"
$mysql_exe -e "create database ${ndb_db} ${charset_spec}"

# Call RANDGEN
${gendata} --dsn="$dsn:database=${innodb_db}" --spec ${data}

for i in $sprocs
do
    $mysql_exe ${ndb_db} < $base/$i.sproc.sql
done

for i in $sprocs
do
    if [ "$i" = "oj_schema_mod" ]
    then
	$mysql_exe ${ndb_db} -e "call $i('${innodb_db}');"
    elif [ "$i" = "copydb" ]
    then
	$mysql_exe ${ndb_db} -e "call copydb('${ndb_db}', '${innodb_db}');"
    elif [ "$i" = "alter_engine" ]
    then
	$mysql_exe ${ndb_db} -e "call $i('${ndb_db}', 'ndb');"
    else
	$mysql_exe ${ndb_db} -e "call $i('${ndb_db}');"
    fi
done

for i in $sprocs
do
    $mysql_exe ${ndb_db} -e "drop procedure $i;"
done


#!/bin/sh

# Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA

set -e

: ${load:=1}
: ${loops:=10}
: ${queries:=500}
: ${host:=127.0.0.1}
: ${port:=3306}
: ${RQG_HOME:=~/randgen-2.2.0}
: ${user:=root}
: ${data:=simple.zz}
: ${grammar:=spj_test.yy}
: ${charset:="latin1 collate latin1_bin"}
: ${EXE_MYSQL:=}
: ${EXE_MYSQLTEST:=}
: ${runtime:=}
: ${seed:=}
: ${mode:=m,nv,np}
: ${oj=}

while getopts ":nom:r:l:h:p:q:d:c:g:u:t:M:s:R:" opt; do
  case $opt in
    M)
      MYSQL_BASE_DIR="${OPTARG}"
      ;;
    R)
      RQG_HOME="${OPTARG}"
      ;;
    s)
      seed="${OPTARG}"
      ;;
    l)
      loops="${OPTARG}"
      ;;
    q)
      queries="${OPTARG}"
      ;;
    d)
      data="${OPTARG}"
      ;;
    c)
      charset="${OPTARG}"
      ;;
    g)
      grammar="${OPTARG}"
      ;;
    h)
      host="${OPTARG}"
      ;;
    p)
      port="${OPTARG}"
      ;;
    u)
      user="${OPTARG}"
      ;;
    t)
      runtime="${OPTARG}"
      ;;
    n)
      load="";
      ;;
    m)
      mode="${OPTARG}"
      ;;
    o)
      oj=1
      ;;
    \?)
      echo "Usage: `basename $0` [options]                        " >&2
      echo "-R <RQH_HOME>         :                               " >&2
      echo "-M <mysql install>    :                               " >&2
      echo "-l <no of loops>      :                               " >&2
      echo "-q <queries per loop> :                               " >&2
      echo "-t <runtime>          : in seconds, overrides loops   " >&2
      echo "-h <host>             :                               " >&2
      echo "-p <port>             :                               " >&2
      echo "-u <user>             :                               " >&2
      echo "-d <data-spec>        :                               " >&2
      echo "-g <grammar-spec>     :                               " >&2
      echo "-n                    : skip creating/loading database" >&2
      echo "-c <charsets>         : charsets                      " >&2
      echo "-m <mode>             :                               " >&2
      echo "-s <seed>             :                               " >&2
      echo "-o                    : oj schema extentions          " >&2

      exit 1
      ;;
    :)
      echo "Option -$OPTARG requires an argument." >&2
      exit 1
      ;;
  esac
done

if [ ! -x "${RQG_HOME}/gensql.pl" ]
then
    echo "Failed to locate \"${RQG_HOME}/gensql.pl\", check RQG_HOME"
    exit 1
fi

if [ ! -x "${RQG_HOME}/gendata.pl" ]
then
    echo "Failed to locate \"${RQG_HOME}/gendata.pl\", check RQG_HOME"
    exit 1
fi

if [ -z "$EXE_MYSQL" ]
then
    if [ -z "$MYSQL_BASE_DIR" ]
    then
	EXE_MYSQL=`which mysql`
    else
	EXE_MYSQL="$MYSQL_BASE_DIR/bin/mysql"
    fi
fi

if [ -z "$EXE_MYSQLTEST" ]
then
    if [ -z "$MYSQL_BASE_DIR" ]
    then
	EXE_MYSQLTEST=`which mysqltest`
    else
	EXE_MYSQLTEST="$MYSQL_BASE_DIR/bin/mysqltest"
    fi
fi

if [ ! -x "$EXE_MYSQL" ]
then
    echo "Failed to locate mysql binary"
    exit 1
fi

if [ ! -x "$EXE_MYSQLTEST" ]
then
    echo "Failed to locate mysqltest binary"
    exit 1
fi

if [ ! -f "${data}" ]
then
    if [ -f "`dirname $0`/${data}" ]
    then
	data="`dirname $0`/${data}"
    fi
fi

if [ ! -f "${grammar}" ]
then
    if [ -f "`dirname $0`/${grammar}" ]
    then
	grammar="`dirname $0`/${grammar}"
    fi
fi

dsn="dbi:mysql:host=${host}:port=${port}:user=root"
gensql=${RQG_HOME}/gensql.pl
gendata=${RQG_HOME}/gendata.pl
mysql_exe="$EXE_MYSQL --show-warnings --user=${user} --host=${host} --port=${port}"
mysqltest_exe="$EXE_MYSQLTEST --user=${user} --host=${host} --port=${port}"
export RQG_HOME

getepochtime="date +%s"
if [ `uname` = "SunOS" ]
then
    getepochtime="nawk 'BEGIN{print srand();}'"
fi

md5sum="md5sum"
if [ `uname` = "SunOS" ]
then
    md5sum="digest -a md5"
fi

awk_exe=awk
if [ `uname` = "SunOS" ]
then
    awk_exe=gawk
fi

pre="spj"
opre="$pre.$$"
innodb_db="${pre}_innodb"
ndb_db="${pre}_ndb"


#!/bin/sh

# Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA

set -e

: ${load:=1}
: ${loops:=100}
: ${queries:=1000}
: ${host:=loki43}
: ${port:=4401}
: ${RQG_HOME:=/net/fimafeng09/export/home/tmp/oleja/mysql/randgen/randgen-2.2.0}

while getopts ":nm:r:l:h:p:" opt; do
  case $opt in
    n)
      load=0
      ;;
    m)
      MYSQLINSTALL=${OPTARG}
      ;;
    r)
      RQG_HOME=${OPTARG}
      ;;
    l)
      loops=${OPTARG}
      ;;
    h)
      host=${OPTARG}
      ;;
    p)
      port=${OPTARG}
      ;;
    \?)
      echo "Usage: `basename $0` [options]"  >&2
      echo "-n : Do not create database (assumed to exist already)."  >&2
      echo "-m <mysql install dir>"  >&2
      echo "-r <rqg installation dir>"  >&2
      echo "-l <no of loops>"  >&2
      echo "-h <host>"  >&2
      echo "-p <port>"  >&2
      exit 1
      ;;
    :)
      echo "Option -$OPTARG requires an argument." >&2
      exit 1
      ;;
  esac
done

pre="spj"
opre="$pre.$$"

: ${data:= --spec=simple.zz}
: ${grammar:=spj_test.yy}

##: ${grammar:=$RQG_HOME/conf/optimizer_no_subquery.yy}   ## a pretty sensible grammar:
##: ${grammar:=$RQG_HOME/conf/optimizer_no_subquery_portable.yy}
##: ${grammar:=$RQG_HOME/conf/subquery_drizzle.yy}
##: ${grammar:=$RQG_HOME/conf/subquery_materialization.yy}
##: ${grammar:=$RQG_HOME/conf/subquery_semijoin.yy}
##: ${grammar:=$RQG_HOME/conf/subquery_semijoin_nested.yy}
##: ${grammar:=$RQG_HOME/conf/outer_join.yy}
##: ${grammar:=$RQG_HOME/conf/outer_join_portable.yy}

## Really simple (or: 'stupid') grammars: Have modified these, used to have nondeterministic behaviour
##: ${grammar:=$RQG_HOME/conf/subquery.yy}
##: ${grammar:=$RQG_HOME/conf/subquery-5.1.yy}

##: ${grammar:=$RQG_HOME/conf/optimizer_subquery.yy}

gensql=${RQG_HOME}/gensql.pl
gendata=${RQG_HOME}/gendata.pl
ecp="set optimizer_switch = 'engine_condition_pushdown=on';"

dsn=dbi:mysql:host=${host}:port=${port}:user=root:database=${pre}_innodb
mysqltest="$MYSQLINSTALL/bin/mysqltest -uroot --host=${host} --port=${port}"
mysql="$MYSQLINSTALL/bin/mysql --host=${host} --port=${port}"

# Create database with a case sensitive collation to ensure a deterministic
# resultset when 'LIMIT' is specified:
charset_spec="character set latin1 collate latin1_bin"
#charset_spec="default character set utf8 default collate utf8_bin"

export RQG_HOME
if [ "$load" ]
then
	$mysql -uroot -e "drop database if exists ${pre}_innodb; drop database if exists ${pre}_ndb"
	$mysql -uroot -e "create database ${pre}_innodb ${charset_spec}; create database ${pre}_ndb ${charset_spec}"
	${gendata} --dsn=$dsn ${data}
cat > /tmp/sproc.$$ <<EOF
DROP PROCEDURE IF EXISTS copydb;
delimiter |;
CREATE PROCEDURE copydb(dstdb varchar(64), srcdb varchar(64),
                        dstengine varchar(64))
BEGIN

  declare tabname varchar(255);
  declare indextype varchar(32);
  declare _unique varchar(16);
  declare done integer default 0;
  declare cnt integer default 0;
  declare c cursor for
    SELECT table_name
    FROM INFORMATION_SCHEMA.TABLES where table_schema = srcdb;
  declare continue handler for not found set done = 1;

  open c;

  repeat
    fetch c into tabname;
    if not done then
       set @ddl = CONCAT('CREATE TABLE ', dstdb, '.', tabname,
                         ' LIKE ', srcdb, '.', tabname);
       select @ddl;
       PREPARE stmt from @ddl;
       EXECUTE stmt;
       set @ddl = CONCAT('ALTER TABLE ', dstdb, '.', tabname,
                         ' engine = ', dstengine);
       PREPARE stmt from @ddl;
       EXECUTE stmt;

       ## Drop the original index 'col_int_unique' - recreate a richer set of indexes below
       set @ddl = CONCAT('DROP INDEX col_int_unique ON ', dstdb, '.', tabname);
       PREPARE stmt from @ddl;
       EXECUTE stmt;

       set cnt = cnt+1;

       set _unique = '';
       set indextype = '';
       ## Create a mix if 'CREATE INDEX' | 'CREATE UNIQUE INDEX [USING HASH] '

       if ((cnt%3) <> 0) then
         set _unique = ' UNIQUE';

         if ((cnt%2) = 0) then
           set indextype = ' USING HASH';
         else
           set indextype = '';
         end if;
       end if;

       ## Add some composite, possibly unique, indexes
       if tabname > 'T' then
          set @ddl = CONCAT('DROP INDEX col_varchar_10_unique ON ', dstdb, '.', tabname);
          PREPARE stmt from @ddl;
          EXECUTE stmt;

          set @ddl = CONCAT('CREATE', _unique, ' INDEX ix1 ', indextype,
                            ' ON ', dstdb, '.', tabname,
                            '(col_char_16,col_char_16_unique)');
          PREPARE stmt from @ddl;
          EXECUTE stmt;
          set @ddl = CONCAT('CREATE', _unique, ' INDEX ix2 ', indextype,
                            ' ON ', dstdb, '.', tabname,
                            '(col_varchar_256,col_varchar_10_unique)');
          PREPARE stmt from @ddl;
          EXECUTE stmt;

       elseif tabname > 'O' then
          set @ddl = CONCAT('CREATE', _unique, ' INDEX ix1 ', indextype,
                            ' ON ', dstdb, '.', tabname,
                            '(col_int,col_int_unique)');
          PREPARE stmt from @ddl;
          EXECUTE stmt;
          set @ddl = CONCAT('CREATE', _unique, ' INDEX ix2 ', indextype,
                            ' ON ', dstdb, '.', tabname,
                            '(col_int_key,col_int_unique)');
          PREPARE stmt from @ddl;
          EXECUTE stmt;

       elseif tabname > 'H' then
          set @ddl = CONCAT('CREATE', _unique, ' INDEX ix3 ', indextype,
                            ' ON ', dstdb, '.', tabname,
                            '(col_int,col_int_key,col_int_unique)');
          PREPARE stmt from @ddl;
          EXECUTE stmt;

       else
          set @ddl = CONCAT('CREATE', _unique, ' INDEX ix1', indextype,
                            ' ON ', dstdb, '.', tabname,
                            '(col_int_unique)');
          PREPARE stmt from @ddl;
          EXECUTE stmt;
       end if;

       ## Modify primary key & partition for some tables
       if ((cnt%3) = 0) then
          set @ddl = CONCAT('UPDATE ', srcdb, '.', tabname, ' SET col_int=0 WHERE col_int IS NULL');
          PREPARE stmt from @ddl;
          EXECUTE stmt;
           set @ddl = CONCAT('ALTER TABLE ', dstdb, '.', tabname,
                               '  CHANGE COLUMN pk pk INT(11) NOT NULL',
                               ', DROP PRIMARY KEY',
                               ', ADD PRIMARY KEY ', '(col_int,pk)');
           PREPARE stmt from @ddl;
           EXECUTE stmt;
           set @ddl = CONCAT('ALTER TABLE ', dstdb, '.', tabname, ' PARTITION BY KEY(col_int)');
           PREPARE stmt from @ddl;
           EXECUTE stmt;

        elseif ((cnt%5) = 0) then
           set @ddl = CONCAT('UPDATE ', srcdb, '.', tabname, ' SET col_int=0 WHERE col_int IS NULL');
           PREPARE stmt from @ddl;
           EXECUTE stmt;
           set @ddl = CONCAT('ALTER TABLE ', dstdb, '.', tabname,
                               '  CHANGE COLUMN pk pk INT(11) NOT NULL',
                               ', DROP PRIMARY KEY',
                               ', ADD PRIMARY KEY', indextype, '(col_int,pk)');
           PREPARE stmt from @ddl;
           EXECUTE stmt;
           set @ddl = CONCAT('ALTER TABLE ', dstdb, '.', tabname, ' PARTITION BY KEY(pk)');
           PREPARE stmt from @ddl;
           EXECUTE stmt;

        elseif ((cnt%7) = 0) then
           set @ddl = CONCAT('DELETE FROM ', srcdb, '.', tabname, ' WHERE col_char_16 IS NULL');
           PREPARE stmt from @ddl;
           EXECUTE stmt;
           set @ddl = CONCAT('ALTER TABLE ', dstdb, '.', tabname,
                               '  CHANGE COLUMN pk pk INT(11) NOT NULL',
                               ', DROP PRIMARY KEY',
                               ', ADD PRIMARY KEY', indextype, '(col_char_16,pk)');
           PREPARE stmt from @ddl;
           EXECUTE stmt;
           set @ddl = CONCAT('ALTER TABLE ', dstdb, '.', tabname, ' PARTITION BY KEY(col_char_16)');
           PREPARE stmt from @ddl;
           EXECUTE stmt;

        elseif ((cnt%11) = 0) then
           set @ddl = CONCAT('DELETE FROM ', srcdb, '.', tabname, ' WHERE col_varchar_10 IS NULL');
           PREPARE stmt from @ddl;
           EXECUTE stmt;
           set @ddl = CONCAT('ALTER TABLE ', dstdb, '.', tabname,
                               '  CHANGE COLUMN pk pk INT(11) NOT NULL',
                               ', DROP PRIMARY KEY',
                               ', ADD PRIMARY KEY', indextype, '(pk,col_varchar_256)');
           PREPARE stmt from @ddl;
           EXECUTE stmt;
           set @ddl = CONCAT('ALTER TABLE ', dstdb, '.', tabname, ' PARTITION BY KEY(col_varchar_256)');
           PREPARE stmt from @ddl;
           EXECUTE stmt;
        end if;

       set @ddl = CONCAT('INSERT INTO ', dstdb, '.', tabname,
                         ' SELECT * FROM ', srcdb, '.', tabname);
       PREPARE stmt from @ddl;
       EXECUTE stmt;
    end if;
  until done end repeat;
  close c;
END
\G

DROP PROCEDURE IF EXISTS alterengine\G
CREATE PROCEDURE alterengine (db varchar(64), newengine varchar(64))
BEGIN

  declare tabname varchar(255);
  declare done integer default 0;
  declare c cursor for
  SELECT table_name
  FROM INFORMATION_SCHEMA.TABLES where table_schema = db;
  declare continue handler for not found set done = 1;

  open c;

  repeat
    fetch c into tabname;
    if not done then
       set @ddl = CONCAT('ALTER TABLE ', db, '.', tabname,
                         ' engine = ', newengine);
       select @ddl;
       PREPARE stmt from @ddl;
       EXECUTE stmt;
    end if;
  until done end repeat;
  close c;
END
\G

CREATE PROCEDURE analyzedb(db varchar(64))
BEGIN

  declare tabname varchar(255);
  declare done integer default 0;
  declare cnt integer default 0;
  declare c cursor for
    SELECT table_name
    FROM INFORMATION_SCHEMA.TABLES where table_schema = db;
  declare continue handler for not found set done = 1;

  set @ddl = 'ANALYZE TABLE ';
  open c;

  repeat
    fetch c into tabname;
    if not done then
       set cnt = cnt+1;
       if cnt > 1 then
         set @ddl = CONCAT(@ddl, ', ');
       end if;
       set @ddl = CONCAT(@ddl,  db, '.', tabname);
    end if;
  until done end repeat;
  close c;

  PREPARE stmt from @ddl;
  EXECUTE stmt;
END
\G

CALL copydb('${pre}_ndb', '${pre}_innodb', 'ndb')\G
CALL analyzedb('${pre}_ndb')\G

##CALL alterengine('${pre}_ndb', 'ndb')\G
DROP PROCEDURE copydb\G
DROP PROCEDURE alterengine\G
DROP PROCEDURE analyzedb\G
EOF
	$mysql -uroot test < /tmp/sproc.$$
	rm -f /tmp/sproc.$$
fi

check_query(){
    file=$1
    no=$2
    line=`expr $no \* 3` || true
    line=`expr $line + 3 + 2 + 1 + 1` || true
    sql=`head -n $line $file | tail -n 1`

    tmp=${opre}.$no.sql
    cat > $tmp <<EOF
--disable_warnings
--disable_query_log
--eval set ndb_join_pushdown='\$NDB_JOIN_PUSHDOWN';
$ecp
--echo kalle
--sorted_result
--error 0,233,1242,4006
$sql
--exit
EOF

    NDB_JOIN_PUSHDOWN=off
    export NDB_JOIN_PUSHDOWN
    for t in 1
    do
	$mysqltest ${pre}_innodb < $tmp >> ${opre}.$no.innodb.$i.txt
    done

    for t in 1
    do
	$mysqltest ${pre}_ndb < $tmp >> ${opre}.$no.ndb.$i.txt
    done

    NDB_JOIN_PUSHDOWN=on
    export NDB_JOIN_PUSHDOWN
    for t in 1
    do
	$mysqltest ${pre}_ndb < $tmp >> ${opre}.$no.ndbpush.$i.txt
    done

    cnt=`md5sum ${opre}.$no.*.txt | awk '{ print $1;}' | sort | uniq | wc -l`
    if [ $cnt -ne 1 ]
    then
	echo -n "$no "
	echo $sql >> ${opre}.failing.sql
    fi

    rm $tmp ${opre}.$no.*.txt
}

locate_query (){
    file=$1
    rows=`cat $file | wc -l`
    queries=`expr $rows - 4`
    queries=`expr $queries / 3`
    q=0
    echo -n "checking queries..."
    while [ $q -ne $queries ]
    do
	check_query $file $q
	q=`expr $q + 1`
    done
    echo
}

run_all() {
    file=$1

    NDB_JOIN_PUSHDOWN=off
    export NDB_JOIN_PUSHDOWN
    echo "- run innodb"
    $mysqltest ${pre}_innodb < $file > ${opre}_innodb.out
    md5_innodb=`md5sum ${opre}_innodb.out | awk '{ print $1;}'`

    echo "- run ndb without push"
    NDB_JOIN_PUSHDOWN=off
    export NDB_JOIN_PUSHDOWN
    $mysqltest ${pre}_ndb < $file > ${opre}_ndb.out
    md5_ndb=`md5sum ${opre}_ndb.out | awk '{ print $1;}'`

    echo "- run ndb with push"
    NDB_JOIN_PUSHDOWN=on
    export NDB_JOIN_PUSHDOWN
    $mysqltest ${pre}_ndb < $file > ${opre}_ndbpush.out
    md5_ndbpush=`md5sum ${opre}_ndbpush.out | awk '{ print $1;}'`

    if [ "$md5_innodb" != "$md5_ndb" ] || [ "$md5_innodb" != "$md5_ndbpush" ]
    then
	echo "md5 missmatch: $md5_innodb $md5_ndb $md5_ndbpush"
	echo "locating failing query(s)"
	locate_query $file
    fi

    rm ${opre}_innodb.out ${opre}_ndb.out ${opre}_ndbpush.out
}

i=0
while [ $i -ne $loops ]
do
    i=`expr $i + 1`

    echo "** loop $i"
    us="$seed" || true
    if [ -z "$us" ]
    then
    	us=`date '+%N'`
    fi

    echo "- generating sql seed: $us"

    (
	echo "--disable_warnings"
	echo "--disable_query_log"
	echo "--eval set ndb_join_pushdown='\$NDB_JOIN_PUSHDOWN';"
	echo "$ecp"
	${gensql} --seed=$us --queries=$queries --dsn=$dsn --grammar=$grammar|
        awk '{ print "--sorted_result"; print "--error 0,233,1242,4006"; print; }'
	echo "--exit"
    ) > ${opre}_test.sql

    run_all ${opre}_test.sql
    rm ${opre}_test.sql
    echo
done


#!/bin/sh

# Copyright (c) 2011, 2015, Oracle and/or its affiliates. All rights reserved.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA

set -e

base="`dirname $0`"
source "$base"/parseargs.sh

ecp="set optimizer_switch = 'engine_condition_pushdown=on';"
# Remove ONLY_FULL_GROUP_BY from sql_mode since the
# syntax have been written with non aggregated columns in
# the select list
disable_only_full_group_by="set sql_mode=(select replace(@@sql_mode,'ONLY_FULL_GROUP_BY',''));"

check_query(){
    file=$1
    no=$2
    line=`expr $no \* 3` || true
    line=`expr $line + 3 + 2 + 1 + 1` || true
    sql=`head -n $line $file | tail -1`

    tmp=${opre}.$no.sql
    cat > $tmp <<EOF
--disable_warnings
--disable_query_log
--eval set ndb_join_pushdown='\$NDB_JOIN_PUSHDOWN';
$ecp
$disable_only_full_group_by
--echo kalle
--sorted_result
--error 0,233,1242,4006
$sql
--exit
EOF

    NDB_JOIN_PUSHDOWN=off
    export NDB_JOIN_PUSHDOWN
    for t in 1
    do
	$mysqltest_exe ${innodb_db} < $tmp >> ${opre}.$no.innodb.$i.txt
    done

    for t in 1
    do
	$mysqltest_exe ${ndb_db} < $tmp >> ${opre}.$no.ndb.$i.txt
    done

    NDB_JOIN_PUSHDOWN=on
    export NDB_JOIN_PUSHDOWN
    for t in 1
    do
	$mysqltest_exe ${ndb_db} < $tmp >> ${opre}.$no.ndbpush.$i.txt
    done

    cnt=`$md5sum ${opre}.$no.*.txt | $awk_exe '{ print $1;}' | sort | uniq | wc -l`
    if [ $cnt -ne 1 ]
    then
	echo -n "$no "
	echo $sql >> ${opre}.failing.sql
    fi

    rm $tmp ${opre}.$no.*.txt
}

locate_query (){
    file=$1
    rows=`cat $file | wc -l`
    queries=`expr $rows - 4`
    queries=`expr $queries / 3`
    q=0
    echo -n "checking queries..."
    while [ $q -ne $queries ]
    do
	check_query $file $q
	q=`expr $q + 1`
    done
    echo
}

run_all() {
    file=$1

    tmpfiles=""
    NDB_JOIN_PUSHDOWN=off
    export NDB_JOIN_PUSHDOWN
    if [ `echo $mode | grep -c m` -ne 0 ]
    then
	echo "- run innodb"
	start=`eval $getepochtime`
	$mysqltest_exe ${innodb_db} < $file > ${opre}_innodb.out
	stop=`eval $getepochtime`
	echo "  elapsed: `expr $stop - $start`s"
	tmpfiles="$tmpfiles ${opre}_innodb.out"
    fi

    if [ `echo $mode | grep -c nv` -ne 0 ]
    then
	echo "- run ndb without push"
	NDB_JOIN_PUSHDOWN=off
	export NDB_JOIN_PUSHDOWN
	start=`eval $getepochtime`
	$mysqltest_exe ${ndb_db} < $file > ${opre}_ndb.out
	stop=`eval $getepochtime`
	echo "  elapsed: `expr $stop - $start`s"
	tmpfiles="$tmpfiles ${opre}_ndb.out"
    fi

    if [ `echo $mode | grep -c np` -ne 0 ]
    then
	echo "- run ndb with push"
	NDB_JOIN_PUSHDOWN=on
	export NDB_JOIN_PUSHDOWN
	start=`eval $getepochtime`
	$mysqltest_exe ${ndb_db} < $file > ${opre}_ndbpush.out
	stop=`eval $getepochtime`
	echo "  elapsed: `expr $stop - $start`s"
	tmpfiles="$tmpfiles ${opre}_ndbpush.out"
    fi

    md5s=""
    for f in $tmpfiles
    do
	md5s="$md5s `$md5sum $f | $awk_exe '{ print $1;}'`"
    done

    ###
    # Check that they are all equal
    check=""
    fail=""
    for s in $md5s
    do
	if [ -z "$check" ]
	then
	    check="$s"
	elif [ "$check" != "$s" ]
	then
	    fail="yes"
	fi
    done

    if [ "$fail" ]
    then
	echo "md5 missmatch: $md5s"
	echo "locating failing query(s)"
	locate_query $file
    fi

    rm -f $tmpfiles
}

i=0
stoptime=""
if [ "$runtime" ]
then
    stoptime=`eval $getepochtime`
    stoptime=`expr $stoptime + $runtime`
    loops=1000000
fi

while [ $i -ne $loops ]
do
    i=`expr $i + 1`

    echo "** loop $i"
    us="$seed" || true
    if [ -z "$us" ]
    then
    	us=`eval $getepochtime`
    fi

    echo "- generating sql seed: $us queries: $queries"

    (
	echo "--disable_warnings"
	echo "--disable_query_log"
	echo "--eval set ndb_join_pushdown='\$NDB_JOIN_PUSHDOWN';"
	echo "$ecp"
	echo "$disable_only_full_group_by"
	${gensql} --seed=$us --queries=$queries --dsn="$dsn:database=${innodb_db}" --grammar=$grammar | grep -v "#" |
        $awk_exe '{ print "--sorted_result"; print "--error 0,233,1242,4006"; print; }'
	echo "--exit"
    ) > ${opre}_test.sql

    run_all ${opre}_test.sql
    rm ${opre}_test.sql
    echo

    if [ "$stoptime" ]
    then
	if [ `eval $getepochtime` -ge $stoptime ]
	then
	    break;
	fi
    fi
done

if [ -f "${opre}.failing.sql" ]
then
    echo "*** FAILING QUERIES ***"
    cat "${opre}.failing.sql"
    exit 1
fi


#!/bin/bash

# Copyright (c) 2003, 2014, Oracle and/or its affiliates. All rights reserved.
# Use is subject to license terms
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA

cores=`find result -name 'core*'`
if [ "$cores" ]
then
    for i in "$cores"
    do
	atrt-backtrace.sh $i
    done
fi

# Log files may be left between test runs so we need to keep some
# state about what results we have seen.

STATEFILE=atrt-analyze-result.state
OLDOK=0

# Checksum of beginning of log file is used to determine if log file
# is reused or not.  If it is reused the count of seen OK reports
# are updated.
if [ -f "${STATEFILE}" ] ; then
  while read file oks chars sum ; do
    chk=`dd 2>/dev/null if="$file" bs="${chars}" count=1 | sum`
    if [ "${chk}" = "${sum}" ] ; then
      OLDOK=`expr ${OLDOK} + ${oks}`
    fi
  done < "${STATEFILE}"
fi

# List of log files with result report.
LOGFILES=`find result/ -name log.out -size +0c | xargs grep -l 'NDBT_ProgramExit: ' /dev/null`

# Save the number of OK reports and checksum  per log file
OK=0
for file in ${LOGFILES} ; do
  oks=`grep -c 'NDBT_ProgramExit: .*OK' "${file}"`
  if [ $oks -gt 0 ] ; then
    OK=`expr ${OK} + ${oks}`
    chars=`wc -c < "${file}" | awk '{ print $1 }'`
    sum=`dd 2>/dev/null if="$file" bs="${chars}" count=1 | sum`
    echo "${file}" "${oks}" "${chars}" "${sum}"
  fi
done > "${STATEFILE}"

# Succeed if found a new OK
[ ${OK} -gt ${OLDOK} ]


#!/bin/sh

# Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA

# Does not work on Windows (gcc only)
if [ `uname | grep -ic cygwin || true` -ne 0 ]
then
    exit
fi

core=$1
out=$2

if [ ! -f "$core" ]
then
    exit
fi

if [ -f `dirname $core`/env.sh ]
then
    . `dirname $core`/env.sh
fi

#
# gdb command file
#
bt=`dirname $core`/bt.gdb
echo "thread apply all bt" > $bt
echo "quit" >> $bt

#
# Fix output
#
if [ -z "$out" ]
then
    out=`dirname $core`/bt.txt
fi
outarg=">> $out 2>&1"
if [ "$out" = "-" ]
then
    outarg=""
fi

#
# get binary
#
tmp=`echo ${core}.tmp`
gdb -c $core -x $bt -q 2>&1 | grep "Core was generated" | awk '{ print $5;}' | sed 's!`!!' | sed `echo "s/'\.//"` > $tmp
exe=`cat $tmp`
rm -f $tmp

if [ -x "$exe" ]
then
    echo "*** $exe - $core" >> $out
    gdb -q -batch -x $bt -c $core $exe >> $out 2>&1
elif [ -x "`which $exe 2> /dev/null`" ]
then
    exe=`which $exe`
    echo "*** $exe - $core" >> $out
    gdb -q -batch -x $bt -c $core $exe >> $out 2>&1
else
    echo "*** $core : cant find exe: $exe" >> $out
fi
rm -f $bt


#!/bin/sh

# Copyright (c) 2003, 2015, Oracle and/or its affiliates. All rights reserved.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA

set -e

mkdir -p result
cd result
rm -rf *

if [ `uname | grep -ic cygwin || true` -ne 0 ]
then
  while [ $# -gt 0 ]
  do
    SAVE_IFS=$IFS
    IFS=":"
    declare -a ARR="($1)"
    IFS=$SAVE_IFS
    DIR=`dirname "${ARR[1]}"`
    REMOTE_DIR=`cygpath -u $DIR`
    HOST="${ARR[0]}"
    rsync -a --exclude='BACKUP' --exclude='ndb_*_fs' "$HOST:$REMOTE_DIR" .
    shift
  done
else
  while [ $# -gt 0 ]
  do
#
# The below commented out lines can be used if we want to keep the file
# as part of the result from a faulty test in autotest. The first line
# also keeps the BACKUP files as part of a faulty test case. These lines
# can be used in special autotest runs when a the file contents are
# needed to debug issues in test cases.
#
#    rsync -a "$1" .
#    rsync -a --exclude='BACKUP' "$1" .
    rsync -a --exclude='BACKUP' --exclude='ndb_*_fs' "$1" .
    shift
  done

  #
  # clean tables...not to make results too large
  #
  lst=`find . -name '*.frm'`
  if [ "$lst" ]
  then
 	  basename=`echo $i | sed 's!\.frm!!'`
	  if [ "$basename" ]
	  then
	    rm -f $basename.*
	  fi
  fi

fi


#!/bin/sh

# Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA

MACHINE=$1
LOCAL_DIR=$2
REMOTE_DIR=$3
verbose=

if [ `uname | grep -ic cygwin || true` -ne 0 ]
then
    verbose=1
fi

name="`uname -n | sed 's!\..*!!g'`"

# Local copy
if [ "$MACHINE" = "$name" -o "$MACHINE" = "localhost" ]
then
    if [ "$REMOTE_DIR" = "$LOCAL_DIR" -o "$REMOTE_DIR/" = "$LOCAL_DIR" ]
    then
	if [ "$verbose" ]
	then
	    echo "$0: Same directory on localhost. Skipping setup..."
	fi
    else
	if [ "$verbose" ]
	then
	    echo "$0: Local machine setup from '$REMOTE_DIR' to '$LOCAL_DIR'..."
	fi
	cp -r "$REMOTE_DIR" "$LOCAL_DIR"
    fi
    exit 0;
fi

if [ `uname | grep -ic cygwin || true` -ne 0 ]
then
    LOCAL_DIR=`cygpath -u $LOCAL_DIR`
    REMOTE_DIR=`cygpath -u $REMOTE_DIR`
fi

set -e
ssh $MACHINE rm -rf $REMOTE_DIR
ssh $MACHINE mkdir -p $REMOTE_DIR
rsync -a --delete --force --ignore-errors $LOCAL_DIR $MACHINE:$REMOTE_DIR


#!/bin/bash

# Copyright (c) 2007, 2015, Oracle and/or its affiliates. All rights reserved.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA

#############################################################
# This script created by Jonas does the following	    #
# Cleans up clones and pevious builds, pulls new clones,    #
# builds, deploys, configures the tests and launches ATRT   #
#############################################################

###############
#Script setup #
##############

save_args=$*
VERSION="autotest-boot.sh version 1.01"

DATE=`date '+%Y-%m-%d'`
if [ `uname -s` != "SunOS" ]
then
  if [ `uname | grep -ic cygwin || true` -ne 0 ]
  then
    HOST=`hostname`
  else
    HOST=`hostname -s`
  fi
else
  HOST=`hostname`
fi
export DATE HOST

set -e

echo "`date` starting: $*"

verbose=0
do_clone=yes
build=yes

patch0=
patch1=
tag0=
tag1=
conf=
clonename=
extra_args=
extra_clone0=
extra_clone1=
install_dir0=
install_dir1=
RUN=

LOCK=$HOME/.autotest-lock

############################
# Read command line entries#
############################

while [ "$1" ]
do
        case "$1" in
                --no-clone) do_clone="";;
                --no-build) build="";;
                --verbose) verbose=`expr $verbose + 1`;;
                --clone=*) clone0=`echo $1 | sed s/--clone=//`;;
                --clone0=*) clone0=`echo $1 | sed s/--clone0=//`;;
                --clone1=*) clone1=`echo $1 | sed s/--clone1=//`;;
                --version) echo $VERSION; exit;;
                --conf=*) conf=`echo $1 | sed s/--conf=//`;;
	        --tag=*) tag0=`echo $1 | sed s/--tag=//`;;
	        --tag0=*) tag0=`echo $1 | sed s/--tag0=//`;;
	        --tag1=*) tag1=`echo $1 | sed s/--tag1=//`;;
	        --clonename=*) clonename=`echo $1 | sed s/--clonename=//`;;
	        --patch=*) patch=`echo $1 | sed s/--patch=//` ; patch0="$patch0$patch " ; patch1="$patch1$patch " ;;
	        --patch0=*) patch=`echo $1 | sed s/--patch0=//` ; patch0="$patch0$patch " ;;
	        --patch1=*) patch=`echo $1 | sed s/--patch1=//` ; patch1="$patch1$patch " ;;
	        --*) echo "Unknown arg: $1";;
                *) RUN="$RUN $1";;
        esac
        shift
done

#################################
#Make sure the configfile exists#
#if it does not exit. if it does#
# (.) load it			#
#################################
if [ -z "$conf" ]
then
	if [ -f "`pwd`/autotest.conf" ]
	then
		conf="`pwd`/autotest.conf"
	elif [ -f "$HOME/autotest.conf" ]
	then
		conf="$HOME/autotest.conf"
	fi
fi

if [ -f $conf ]
then
	. $conf
else
	echo "Can't find config file: >$conf<"
	exit
fi

###############################
# Validate that all interesting
#   variables where set in conf
###############################
vars="install_dir build_dir git_remote_repo git_local_repo"
for i in $vars
do
  t=`echo echo \\$$i`
  if [ -z "`eval $t`" ]
  then
      echo "Invalid config: $conf, variable $i is not set"
      exit
  fi
done

###############################
#Print out the enviroment vars#
###############################

if [ $verbose -gt 0 ]
then
	env
fi

####################################
# Setup the lock file name and path#
# Setup the clone source location  #
####################################

if [ -z "$clone1" ]
then
    install_dir0=$install_dir
else
    install_dir0=$install_dir/0
    install_dir1=$install_dir/1
fi

#######################################
# Check to see if the lock file exists#
# If it does exit. 		      #
#######################################

if [ -f $LOCK ]
then
	echo "Lock file exists: $LOCK"
	exit 1
fi

#######################################
# If the lock file does not exist then#
# create it with date and run info    #
#######################################

echo "$DATE $RUN" > $LOCK

#############################
#If any errors here down, we#
# trap them, and remove the #
# Lock file before exit     #
#############################
trap "rm -f $LOCK" EXIT

# You can add more to this path#
################################

if [ -z "$tag0" ]
then
    dst_place0=${build_dir}/clone-$clone0-$DATE.$$
else
    dst_place0=${build_dir}/clone-$tag0-$DATE.$$
    extra_args="$extra_args --clone0=$tag0"
    extra_clone0=""
fi

if [ -z "$tag1" ]
then
    dst_place1=${build_dir}/clone1-$clone1-$DATE.$$
else
    dst_place1=${build_dir}/clone1-$tag1-$DATE.$$
    extra_args="$extra_args --clone1=$tag1"
    extra_clone1=""
fi

if [ "$clonename" ]
then
    extra_args="$extra_args --clonename=$clonename"
fi

#########################################
# Delete source and pull down the latest#
#########################################

if [ "$do_clone" ]
then
	rm -rf $dst_place0
	mkdir -p ${build_dir}

	# Can use local copy if clone_dir is set, to speed up
	if [ ! -z "$clone_dir" ]
	then
		if [ -d "$clone_dir/$clone0" ]
		then
			echo "Copying $clone_dir/$clone0 to $dst_place0"
			cp -r $clone_dir/$clone0 $dst_place0
		fi
		if [ -d "$clone_dir/$clone1" ]
		then
			echo "Copying $clone_dir/$clone1 to $dst_place1"
			cp -r $clone_dir/$clone1 $dst_place1
		fi
	else
# Comment out the next line if using git of version < 2.0
# and ensure that the local repo is up to date.
                git -C ${git_local_repo} fetch ${git_remote_repo}

                git clone -b${clone0} ${git_local_repo} ${dst_place0}
                [ ! -n "${tag0}" ] || git -C ${dst_place0} reset --hard ${tag0}
		for patch in $patch0 ; do
			( cd $dst_place0 && patch -p0 ) < $patch
		done
                {
# Comment out the next line if using git of version < 2.0 and replace with:
#                 cd ${dst_place0}
#                 git log -1
                  git -C ${dst_place0} log -1
	          if [ $patch0 ] ; then echo patches: $patch0 ; cat $patch0 ; fi
                } > $dst_place0/code0.txt

                if [ "$clone1" ]
	       	then
	                rm -rf $dst_place1
                        git clone -b${clone1} ${git_local_repo} ${dst_place1}
                        [ ! -n "${tag1}" ] || git -C ${dst_place1} reset --hard ${tag1}
	                for patch in $patch1 ; do
		                ( cd $dst_place1 && patch -p0 ) < $patch
	                done
                        {
                          git -C ${dst_place1} log -1
	                  if [ $patch1 ] ; then echo patches: $patch1 ; cat $patch1 ; fi
                        } > $dst_place1/code1.txt
                fi
	fi
fi

##########################################
# Build the source, make installs, and   #
# create the database to be rsynced	 #
##########################################

function build_cluster()
{
    if grep -qc autotest storage/ndb/compile-cluster 2>/dev/null
    then
        storage/ndb/compile-cluster --autotest $*
    else
        BUILD/compile-ndb-autotest $*
    fi
}

if [ "$build" ]
then
    rm -rf $install_dir
    p=`pwd`
    if [ -z "$clone1" ]
    then
        cd $dst_place0
        if [ `uname | grep -ic cygwin || true` -ne 0 ]
        then
            install_dir_dos=`cygpath -w $install_dir`
            cmd /c cscript win/configure.js WITH_NDBCLUSTER_STORAGE_ENGINE --without-plugins=archive,blackhole,example,federated
            cmd /c cmake -G "Visual Studio 9 2008" -DWITH_ERROR_INSERT=1 -DWITH_NDB_TEST=1 -DCMAKE_INSTALL_PREFIX=$install_dir_dos
            cmd /c devenv.com MySql.sln /Build RelWithDebInfo
            cmd /c devenv.com MySql.sln /Project INSTALL /Build
        else
	    build_cluster --prefix=$install_dir0
	    make install
	    [ ! -f code0.txt ] || cp code0.txt $install_dir0/
        fi
    else
	cd $dst_place0
	build_cluster --prefix=$install_dir0
	make install
	[ ! -f code0.txt ] || cp code0.txt $install_dir0/

	cd $dst_place1
	build_cluster --prefix=$install_dir1
	make install
	[ ! -f code1.txt ] || cp code1.txt $install_dir1/
    fi
    cd $p
fi

################################
# Start run script             #
################################

script=$install_dir0/mysql-test/ndb/autotest-run.sh
for R in $RUN
do
    sh -x $script $save_args --conf=$conf --run-dir=$install_dir --install-dir0=$install_dir0 --install-dir1=$install_dir1 --suite=$R --nolock $extra_args
done

if [ "$build" ]
then
    rm -rf $dst_place0

    if [ "$dst_place1" ]
    then
	rm -rf $dst_place1
    fi
fi


#!/bin/bash

# Copyright (c) 2007, 2017, Oracle and/or its affiliates. All rights reserved.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA

#############################################################
# This script created by Jonas does the following	    #
# Cleans up clones and pevious builds, pulls new clones,    #
# builds, deploys, configures the tests and launches ATRT   #
#############################################################

###############
#Script setup #
##############

save_args=$*
VERSION="autotest-run.sh version 1.07"

DATE=`date '+%Y-%m-%d'`
if [ `uname -s` != "SunOS" ]
then
  if [ `uname | grep -ic cygwin || true` -ne 0 ]
  then
    HOST=`hostname`
    # Returns windows CRLF
    HOST=`echo $HOST | tr -d "\015"`
    echo "Host: '$HOST'"
  else
    HOST=`hostname -s`
  fi
else
  HOST=`hostname`
fi
export DATE HOST

set -e
ulimit -Sc unlimited

echo "`date` starting: $*"

RSYNC_RSH=ssh
export RSYNC_RSH

verbose=0
report=yes
nolock=
clonename=
RUN="daily-basic"
conf=autotest.conf
LOCK=$HOME/.autotest-lock

############################
# Read command line entries#
############################

while [ "$1" ]
do
        case "$1" in
                --verbose=*) verbose=`echo $1 | sed s/--verbose=//`;;
                --verbose) verbose=`expr $verbose + 1`;;
                --conf=*) conf=`echo $1 | sed s/--conf=//`;;
                --version) echo $VERSION; exit;;
	        --suite=*) RUN=`echo $1 | sed s/--suite=//`;;
	        --run-dir=*) run_dir=`echo $1 | sed s/--run-dir=//`;;
	        --install-dir=*) install_dir=`echo $1 | sed s/--install-dir=//`;;
	        --install-dir0=*) install_dir0=`echo $1 | sed s/--install-dir0=//`;;
	        --install-dir1=*) install_dir1=`echo $1 | sed s/--install-dir1=//`;;
	        --clone=*) clone0=`echo $1 | sed s/--clone=//`;;
	        --clone0=*) clone0=`echo $1 | sed s/--clone0=//`;;
	        --clone1=*) clone1=`echo $1 | sed s/--clone1=//`;;
	        --nolock) nolock=true;;
	        --clonename=*) clonename=`echo $1 | sed s/--clonename=//`;;
                --baseport=*) baseport_arg="$1";;
                --base-dir=*) base_dir=`echo $1 | sed s/--base-dir=//`;;
                --clusters=*) clusters_arg="$1";;
                --site=*) site_arg="$1";;
        esac
        shift
done

#################################
#Make sure the configfile exists#
#if it does not exit. if it does#
# (.) load it			#
#################################

install_dir=${install_dir:-$install_dir0}
install_dir0=${install_dir0:-$install_dir}

install_dir_save=$install_dir0
if [ -f $conf ]
then
	. $conf
else
	echo "Can't find config file: $conf"
	exit
fi
install_dir0=$install_dir_save

if [ -z "$run_dir" ]
then
    if [ "$install_dir1" ]
    then
	echo "--run-dir not specified but install_dir1 specified"
	echo "giving up"
	exit
    fi
    run_dir=$install_dir0
fi

###############################
# Validate that all interesting
#   variables where set in conf
###############################
vars="target base_dir install_dir0 hosts"
if [ "$report" ]
then
	vars="$vars result_host result_path"
fi
for i in $vars
do
  t=`echo echo \\$$i`
  if [ -z "`eval $t`" ]
  then
      echo "Invalid config: $conf, variable $i is not set"
      exit
  fi
done

###############################
#Print out the enviroment vars#
###############################

if [ $verbose -gt 0 ]
then
	env
fi

#######################################
# Check to see if the lock file exists#
# If it does exit. 		      #
#######################################

if [ -z "$nolock" ]
then
    if [ -f $LOCK ]
    then
	echo "Lock file exists: $LOCK"
	exit 1
    fi
    echo "$DATE $RUN" > $LOCK
fi

####################################
# Remove the lock file before exit #
####################################
if [ -z "${nolock}" ]
then
    trap "rm -f $LOCK" EXIT
fi

###############################################
# Check that all interesting files are present#
###############################################

test_dir=$install_dir/mysql-test/ndb

# Check if executables in $install_dir0 is executable at current
# platform, they could be built for another kind of platform
unset NDB_CPCC_HOSTS
if ${install_dir}/bin/ndb_cpcc 2>/dev/null ; then
  # Use atrt and ndb_cpcc from test build
  atrt="${test_dir}/atrt"
  ndb_cpcc="${install_dir}/bin/ndb_cpcc"
else
  echo "Note: Cross platform testing, atrt and ndb_cpcc is not used from test build" >&2
  atrt=`which atrt`
  ndb_cpcc=`which ndb_cpcc`
fi

test_file=$test_dir/$RUN-tests.txt

if [ ! -f "$test_file" ]
then
    echo "Cant find testfile: $test_file"
    exit 1
fi

if [ ! -x "$atrt" ]
then
    echo "Cant find atrt binary at $atrt"
    exit 1
fi

############################
# check ndb_cpcc fail hosts#
############################
failed=`$ndb_cpcc $hosts | awk '{ if($1=="Failed"){ print;}}'`
if [ "$failed" ]
then
  echo "Cant contact cpcd on $failed, exiting"
  exit 1
fi

#############################
# Function for replacing the#
# choose host with real host#
# names. Note $$ = PID	    #
#############################
choose(){
        SRC=$1
        TMP1=/tmp/choose.$$
        TMP2=/tmp/choose.$$.$$
        shift

        cp $SRC $TMP1
        i=1
        while [ $# -gt 0 ]
        do
                sed -e s,"CHOOSE_host$i",$1,g < $TMP1 > $TMP2
                mv $TMP2 $TMP1
                shift
                i=`expr $i + 1`
        done
        cat $TMP1
        rm -f $TMP1
}

choose_conf(){
    if [ -f $test_dir/conf-$1-$HOST.cnf ]
	then
	echo "$test_dir/conf-$1-$HOST.cnf"
    elif [ -f $test_dir/conf-$1.cnf ]
    then
	echo "$test_dir/conf-$1.cnf"
    elif [ -f $test_dir/conf-$HOST.cnf ]
    then
	echo "$test_dir/conf-$HOST.cnf"
    else
	echo "Unable to find conf file looked for" 1>&2
	echo "$test_dir/conf-$1-$HOST.cnf and" 1>&2
	echo "$test_dir/conf-$HOST.cnf" 1>&2
	echo "$test_dir/conf-$1.cnf" 1>&2
	exit
    fi
}

#########################################
# Count how many computers we have ready#
#########################################

count_hosts(){
    ch="CHOOSE_host"
    list=`grep $ch $1 | sed 's!,! !g'`
    cnt=`for i in $list; do echo $i; done | grep $ch | sort | uniq | wc -l`
    echo $cnt
}

conf=`choose_conf $RUN`
count=`count_hosts $conf`
avail=`echo $hosts | wc -w`
if  [ $count -gt $avail ]
    then
    echo "Not enough hosts"
    echo "Needs: $count available: $avail ($avail_hosts)"
    exit 1
fi

###
# Make directories needed

p=`pwd`
run_dir=$run_dir/run-$RUN-$clone0-$target
res_dir=$base_dir/result-$RUN-$clone0-$target/$DATE
tar_dir=$base_dir/saved-results

mkdir -p $run_dir $res_dir $tar_dir
rm -rf $res_dir/* $run_dir/*

###
#
# Do sed substitiutions
#
cd $run_dir
mkdir run

if [ `uname | grep -ic cygwin || true` -ne 0 ]
then
  run_dir=`cygpath -m $run_dir`
  install_dir0=`cygpath -u $install_dir0`
  if [ "$install_dir1" ]
  then
    install_dir1=`cygpath -u $install_dir1`
  fi
  test_dir=`cygpath -m $test_dir`
fi

choose $conf $hosts > d.tmp.$$
sed -e s,CHOOSE_dir,"$run_dir/run",g < d.tmp.$$ > my.cnf

prefix="--prefix=$install_dir --prefix0=$install_dir0"
if [ -n "$install_dir1" ]
then
    prefix="$prefix --prefix1=$install_dir1"
fi

# If verbose level 0, use default verbose mode (1) for atrt anyway
# otherwise it will not write test progress to log file
if [ ${verbose} -gt 0 ] ; then
  verbose_arg=--verbose=${verbose}
fi

# Setup configuration
$atrt Cdq ${site_arg} ${clusters_arg} ${verbose_arg} $prefix my.cnf

# Start...
args=""
args="--report-file=report.txt"
args="$args --log-file=log.txt"
args="$args --testcase-file=$test_dir/$RUN-tests.txt"
args="$args ${baseport_arg}"
args="$args ${site_arg} ${clusters_arg}"
args="$args $prefix"
args="$args ${verbose_arg}"
$atrt $args my.cnf || echo "ERROR: $?: $atrt $args my.cnf"

# Make tar-ball
[ -f log.txt ] && mv log.txt $res_dir
[ -f report.txt ] && mv report.txt $res_dir
[ "`find . -name 'result*'`" ] && mv result* $res_dir
cd $res_dir

echo "date=$DATE" > info.txt
echo "suite=$RUN" >> info.txt
echo "clone=$clone0" >> info.txt
echo "arch=$target" >> info.txt
echo "host=$HOST" >> info.txt
[ -z "${clusters_arg}" ] || echo "clusters=${clusters_arg/--clusters=/}" >> info.txt
echo "test_hosts='$hosts'" >> info.txt
echo "test_atrt_command='$atrt $args my.cnf'" >> info.txt
if [ "$clone1" ]
then
    echo "clone1=$clone1" >> info.txt
    [ ! -f $install_dir1/code1.txt ] || cp $install_dir1/code1.txt .
fi
[ ! -f $install_dir0/code0.txt ] || cp $install_dir0/code0.txt .
if [ "$clonename" ]
then
    echo "clonename=$clonename" >> info.txt
else
    echo "clonename=$clone0" >> info.txt
fi
for f in INFO_BIN INFO_SRC ; do
  [ ! -f "${install_dir0}/docs/${f}" ] || cp "${install_dir0}/docs/${f}" "${f}.0"
  [ ! -f "${install_dir1}/docs/${f}" ] || cp "${install_dir1}/docs/${f}" "${f}.1"
done
find . | xargs chmod ugo+r

# Try to pack and transfer as much as possible
set +e

cd ..
p2=`pwd`
cd ..
tarfile=res.$RUN.$clone0.$target.$DATE.$HOST.$$.tgz
if [ `uname -s` != "SunOS" ]
then
    tar cfz $tar_dir/$tarfile `basename $p2`/$DATE
else
    tarfile2=res.$RUN.$clone0.$target.$DATE.$HOST.$$.tar
    tar cf $tar_dir/$tarfile2 `basename $p2`/$DATE
    gzip -c $tar_dir/$tarfile2 > $tar_dir/$tarfile
    rm -f $tar_dir/$tarfile2
fi

if [ "$report" ]
then
    scp $tar_dir/$tarfile $result_host:$result_path/${tarfile}.upload
    ssh $result_host mv $result_path/${tarfile}.upload $result_path/${tarfile}
fi

cd $p
rm -rf $res_dir $run_dir


#!/bin/sh

# Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA

set -e

files="daily-basic-tests.txt daily-devel-tests.txt upgrade-tests.txt"

die(){
    echo "error at $1 : $2"
    exit 1
}

check_state(){
    if  [ $1 != $2 ]
    then
	die $3 $4
    fi
}

check_file(){
    file=$1
    lineno=0
    testcase=0

    echo -n "-- checking $file..."
    cat $file | awk '{ print "^" $0 "$";}' > /tmp/ct.$$
    while read line
    do
	lineno=$(expr $lineno + 1)
	if [ $(echo $line | grep -c "^^#") -ne 0 ]
	then
	    continue
	fi

	case "$line" in
	    ^max-time:*)
		testcase=$(expr $testcase + 1);;
	    ^cmd:*)
		if [ $(echo $line | wc -w) -ne 2 ]
		then
		    die $file $lineno
		fi
		testcase=$(expr $testcase + 2);;
	    ^args:*)
		testcase=$(expr $testcase + 4);;
	    ^type:*)
		;;
	    ^$)
                if [ $testcase -ne 7 ]
		then
		    die $file $lineno
		else
		    testcase=0
		    cnt=$(expr $cnt + 1)
		fi;;
	    *)
	        die $file $lineno
	esac
   done < /tmp/ct.$$
   rm -f /tmp/ct.$$
   if [ $testcase -ne 0 ]
   then
   	echo "Missing newline in end-of-file"
	die $file $lineno
   fi

   echo "ok"
}

for file in $files
do
    check_file $file
done


#!/bin/sh

# Copyright (C) 2003, 2005 MySQL AB
# Use is subject to license terms
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA

baseport=""
basedir=""
proc_no=1
node_id=1

d_file=/tmp/d.$$
dir_file=/tmp/dirs.$$
config_file=/tmp/config.$$
cluster_file=/tmp/cluster.$$

add_procs(){
	type=$1; shift
	while [ $# -ne 0 ]
	do
		add_proc $type $1
		shift
	done
}

add_proc (){
	case $type in
	mgm)
		echo "$proc_no.ndb_mgmd" >> $dir_file
		echo "[ndb_mgmd]"        >> $config_file
		echo "Id: $node_id"      >> $config_file
		echo "HostName: $2"      >> $config_file
		node_id=`expr $node_id + 1`
		;;
	api)
		echo "$proc_no.ndb_api" >> $dir_file
                echo "[api]"            >> $config_file
                echo "Id: $node_id"     >> $config_file
                echo "HostName: $2"     >> $config_file
		node_id=`expr $node_id + 1`
		;;
	ndb)
		echo "$proc_no.ndbd" >> $dir_file
                echo "[ndbd]"        >> $config_file
                echo "Id: $node_id"  >> $config_file
                echo "HostName: $2"  >> $config_file
		node_id=`expr $node_id + 1`
		;;
	mysqld)
		echo "$proc_no.mysqld" >> $dir_file
                echo "[mysqld]"      >> $config_file
                echo "Id: $node_id"    >> $config_file
                echo "HostName: $2"    >> $config_file
		node_id=`expr $node_id + 1`
		;;
	mysql)
		echo "$proc_no.mysql" >> $dir_file
		;;
	esac
	proc_no=`expr $proc_no + 1`
}

cnf=/dev/null
cat $1 | while read line
do
	case $line in
	baseport:*) baseport=`echo $line | sed 's/baseport[ ]*:[ ]*//g'`;;
	basedir:*) basedir=`echo $line | sed 's/basedir[ ]*:[ ]*//g'`;;
	mgm:*) add_procs mgm `echo $line | sed 's/mgm[ ]*:[ ]*//g'`;;
	api:*) add_procs api `echo $line | sed 's/api[ ]*:[ ]*//g'`;;
	ndb:*) add_procs ndb `echo $line | sed 's/ndb[ ]*:[ ]*//g'`;;
	mysqld:*) add_procs mysqld `echo $line | sed 's/mysqld[ ]*:[ ]*//g'`;;
	mysql:*) add_procs mysql `echo $line | sed 's/mysql[ ]*:[ ]*//g'`;;
	"-- cluster config")
		if [ "$cnf" = "/dev/null" ]
		    then
		    cnf=$cluster_file
		else
		    cnf=/dev/null
		fi
		line="";;
	    *) echo $line >> $cnf; line="";;
	esac
	if [ "$line" ]
	then
	    echo $line >> $d_file
	fi
done

cat $dir_file | xargs mkdir -p

if [ -f $cluster_file ]
    then
    cat $cluster_file $config_file >> /tmp/config2.$$
    mv /tmp/config2.$$ $config_file
fi

for i in `find . -type d -name '*.ndb_mgmd'`
  do
  cp $config_file $i/config.ini
done

mv $d_file d.txt
rm -f $config_file $dir_file $cluster_file


#!/bin/sh

# Copyright (C) 2003, 2005 MySQL AB
# Use is subject to license terms
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA

src_dir=$1
run=$2
date=$3
src_file=$src_dir/report.txt

if [ ! -f $src_dir/report.txt ]
then
	echo "$src_dir/report.txt is missing"
	exit 1
fi

###
#
# General html functions
trim(){
	echo $*
}

header(){
    cat <<EOF
<title>$*</title>

EOF
}

footer(){
    cat <<EOF

EOF
}

heading(){
    h=$1; shift
    cat <<EOF
<h$h>$*</h$h>
EOF
}

table(){
    echo "
"
}

end_table(){
    echo "
"
}

row(){
    echo "
"
}

end_row(){
    echo "
"
}

c_column(){
    cat <<EOF
$*
EOF
}

bold(){
    cat <<EOF
$*
EOF
}
column(){
    cat <<EOF
$*
EOF
}

para(){
    cat <<EOF

EOF
}

hr(){
    cat <<EOF

EOF
}

# -- Verify
time_spec(){
    # $1 - secs
    _ts_tmp=$1

    _ts_s=`expr $_ts_tmp % 60`
    _ts_tmp=`expr $_ts_tmp / 60`

    _ts_m=`expr $_ts_tmp % 60`
    if [ $_ts_tmp -ge 60 ]
    then
	_ts_tmp=`expr $_ts_tmp / 60`
    else
	_ts_tmp=0
    fi

    a=3
    _ts_h=$_ts_tmp

    if [ $_ts_h -gt 0 ]
    then
	ret="${_ts_h}h"
    fi

    [ $_ts_m -gt 0 ] || [ $_ts_h -gt 0 ] && ret="$ret${_ts_m}m"

    ret="$ret${_ts_s}s"
    echo $ret
}

### Main

report_file=$src_dir/report.html
summary_file=$src_dir/summary.html

passed=0
failed=0
total=0

pass(){
	passed=`expr $passed + 1`
}

fail(){
	failed=`expr $failed + 1`
}

(
	header Report $run $date
	table "border=1"
	row
	column `bold Test case`
	column `bold Result`
	column `bold Elapsed`
	column `bold Log`
	end_row
) > $report_file

cat $src_file | while read line
do
    	eval `echo $line | awk -F";" '{ printf("prg=\"%s\"; no=\"%s\"; res=\"%s\"; time=\"%s\"", $1, $2, $3, $4); }'`

	prg=`trim $prg`
	no=`trim $no`
	res=`trim $res`
	time=`trim $time`
	res_dir="log"

	ts=`time_spec $time`
	res_txt=""
	case $res in
	0) pass; res_txt="PASSED";;
	*) fail; res_txt="FAILED";;
	esac

	if [ ! -d "$src_dir/result.$no" ]; then res_dir=" "; fi

	total=`expr $total + $time`

	(
		row
		column $prg
		column $res_txt
		column $ts
		column $res_dir
		end_row
	) >> $report_file

	(
        	row
        	column $run
        	column $date
        	column $passed
        	column $failed
        	column `time_spec $total`
        	column "report"
        	column "log.txt"
        	end_row
	) > $summary_file
done

(
	end_table
	footer
) >> $report_file

exit 0


#!/bin/sh

# Copyright (C) 2003, 2005 MySQL AB
# Use is subject to license terms
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA

# NAME
#   make-index.sh
#
# SYNOPSIS
#   make-index.sh [ -d <dir> ]
#
# DESCRIPTION
#
# OPTIONS
#
# EXAMPLES
#
#
# ENVIRONMENT
#   NDB_PROJ_HOME       Home dir for ndb
#
# FILES
#   $NDB_PROJ_HOME/lib/funcs.sh  general shell script functions
#
#
# SEE ALSO
#
# DIAGNOSTICTS
#
# VERSION
#   1.0
#
# AUTHOR
#   Jonas Oreland
#

progname=`basename $0`
synopsis="make-index.sh [ -d <dir> ]"

: ${NDB_PROJ_HOME:?}		 # If undefined, exit with error message

: ${NDB_LOCAL_BUILD_OPTIONS:=--} # If undef, set to --. Keeps getopts happy.
			         # You may have to experiment a bit
                                 # to get quoting right (if you need it).

. $NDB_PROJ_HOME/lib/funcs.sh    # Load some good stuff

# defaults for options related variables
#

dst_dir=/home/autotest/html
report_date=`date '+%Y-%m-%d'`
uniq_id=$$.$$
verbose=yes

# used if error when parsing the options environment variable
#
env_opterr="options environment variable: <<$options>>"

# Option parsing, for the options variable as well as the command line.
#
# We want to be able to set options in an environment variable,
# as well as on the command line. In order not to have to repeat
# the same getopts information twice, we loop two times over the
# getopts while loop. The first time, we process options from
# the options environment variable, the second time we process
# options from the command line.
#
# The things to change are the actual options and what they do.
#
#

for optstring in "$options"  ""	     # 1. options variable  2. cmd line
do

    while getopts q:s:R:d: i $optstring  # optstring empty => no arg => cmd line
    do
	case $i in

	q)	verbose="";;		# echo important things
	d)      dst_dir=$OPTARG;;       # Destination directory
	\?)	syndie $env_opterr;;    # print synopsis and exit

	esac
    done

    [ -n "$optstring" ]  &&  OPTIND=1 	# Reset for round 2, cmdline options

    env_opterr= 			# Round 2 should not use the value

done
shift `expr $OPTIND - 1`

dst_dir=`abspath $dst_dir`

###
#
# General html functions
header(){
    cat <<EOF
<title>$*</title>

EOF
}

footer(){
    cat <<EOF

EOF
}

heading(){
    h=$1; shift
    cat <<EOF
<h$h>$*</h$h>
EOF
}

table(){
    echo "
"
}

end_table(){
    echo "
"
}

row(){
    echo "
"
}

end_row(){
    echo "
"
}

c_column(){
    cat <<EOF
$*
EOF
}

bold(){
    cat <<EOF
$*
EOF
}
column(){
    cat <<EOF
$*
EOF
}

para(){
    cat <<EOF

EOF
}

hr(){
    cat <<EOF

EOF
}

inc_summary() {
	grep -v 'html>' $2 | grep -v body |  sed 's/href="/href="'$1'\//g'
}

# --- option parsing done ---

# -- Verify
trace "Verifying arguments"

# --- option verifying done ---

### Main

# Re creating index
trace "Creating index"
(
    header "Autotest super-duper index"
    heading 1 "Autotest super-duper index"
    cat -E README.autotest | sed 's/\$/
/g'
    echo "
"
    echo "Current crontab installed on mc01 running [" `uname -a` "]"
    hr

    dirs=`find $dst_dir -name 'summary.*.html' -type f -maxdepth 2 -exec dirname {} \; | sort -u`

    dates=`find $dst_dir -name 'summary.*.html' -type f -maxdepth 2 -exec basename {} \; | sed 's/summary\.\(.*\)\.html/\1/g' | sort -u | sort -r`

    echo "
"

#inline 5 latest reports
    r_count=5
    for d in $dates
    do
	for o in $dirs
	do
            o=`basename $o`
            if [ -r $dst_dir/$o/summary.$d.html ]
            then
                inc_summary $o $dst_dir/$o/summary.$d.html
		hr

		r_count=`expr $r_count - 1`
		if [ $r_count -eq 0 ]
		then
			break 2
		fi
            fi
        done
    done

    table "border=1"
    row
    for i in $dirs
    do
	i=`basename $i`
	column `bold $i`
    done
    end_row

    for d in $dates
    do
	row
	for o in $dirs
	do
	    o=`basename $o`
	    if [ -r $dst_dir/$o/summary.$d.html ]
	    then
		column "$d"
	    else
		column ""
	    fi
	done
	end_row
    done
    end_table
    footer
) > $dst_dir/index.html

exit 0


#!/bin/sh

# Copyright (C) 2005, 2006 MySQL AB
# Use is subject to license terms
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA

#############################################################
# This script created by Jonas does the following	    #
# Cleans up clones and pevious builds, pulls new clones,    #
# builds, deploys, configures the tests and launches ATRT   #
#############################################################

###############
#Script setup #
##############

save_args=$*
VERSION="ndb-autotest.sh version 1.04"

DATE=`date '+%Y-%m-%d'`
HOST=`hostname -s`
export DATE HOST

set -e
ulimit -Sc unlimited

echo "`date` starting: $*"

RSYNC_RSH=ssh
export RSYNC_RSH

verbose=0
do_clone=yes
build=yes
deploy=yes
run_test=yes
config=yes
report=yes

clone=5.0-ndb
RUN="daily-basic daily-devel"
conf=autotest.conf
LOCK=$HOME/.autotest-lock

############################
# Read command line entries#
############################

while [ "$1" ]
do
        case "$1" in
                --no-clone) do_clone="";;
                --no-build) build="";;
                --no-deploy) deploy="";;
                --no-test) run_test="";;
                --no-config) config="";;
                --no-report) report="";;
                --verbose) verbose=`expr $verbose + 1`;;
                --clone=*) clone=`echo $1 | sed s/--clone=//`;;
                --conf=*) conf=`echo $1 | sed s/--conf=//`;;
                --version) echo $VERSION; exit;;
                *) RUN=$*;;
        esac
        shift
done

#################################
#Make sure the configfile exists#
#if it does not exit. if it does#
# (.) load it			#
#################################

if [ -f $conf ]
then
	. $conf
else
	echo "Can't find config file: $conf"
	exit
fi

###############################
# Validate that all interesting
#   variables where set in conf
###############################
vars="target base_dir src_clone_base install_dir build_dir hosts configure"
if [ "$report" ]
then
	vars="$vars result_host result_path"
fi
for i in $vars
do
  t=`echo echo \\$$i`
  if [ -z "`eval $t`" ]
  then
      echo "Invalid config: $conf, variable $i is not set"
      exit
  fi
done

###############################
#Print out the enviroment vars#
###############################

if [ $verbose -gt 0 ]
then
	env
fi

####################################
# Setup the lock file name and path#
# Setup the clone source location  #
####################################

src_clone=$src_clone_base-$clone

#######################################
# Check to see if the lock file exists#
# If it does exit. 		      #
#######################################

if [ -f $LOCK ]
then
	echo "Lock file exists: $LOCK"
	exit 1
fi

#######################################
# If the lock file does not exist then#
# create it with date and run info    #
#######################################

echo "$DATE $RUN" > $LOCK

#############################
#If any errors here down, we#
# trap them, and remove the #
# Lock file before exit     #
#############################
if [ `uname -s` != "SunOS" ]
then
	trap "rm -f $LOCK" ERR
fi

# You can add more to this path#
################################

dst_place=${build_dir}/clone-mysql-$clone-$DATE

#########################################
# Delete source and pull down the latest#
#########################################

if [ "$do_clone" ]
then
	rm -rf $dst_place
	bk clone  $src_clone $dst_place
fi

##########################################
# Build the source, make installs, and   #
# create the database to be rsynced	 #
##########################################

if [ "$build" ]
then
	cd $dst_place
        rm -rf $install_dir/*
	if [ -x BUILD/autorun.sh ]
	then
	    ./BUILD/autorun.sh
	else
	    aclocal; autoheader; autoconf; automake
	    if [ -d storage ]
	    then
		(cd storage/innobase; aclocal; autoheader; autoconf; automake)
	    else
		(cd innobase; aclocal; autoheader; autoconf; automake)
	    fi
	fi
	eval $configure --prefix=$install_dir
	make
	make install
	(cd $install_dir; ./bin/mysql_install_db) # This will be rsynced to all
fi

################################
# check script version. If the #
# version is old, replace it   #
# and restart		       #
################################

script=$install_dir/mysql-test/ndb/ndb-autotest.sh
if [ -x $script ]
then
	$script --version > /tmp/version.$$
else
	echo $VERSION > /tmp/version.$$
fi
match=`grep -c "$VERSION" /tmp/version.$$ | xargs echo`
rm -f /tmp/version.$$
if [ $match -eq 0 ]
then
	echo "Incorrect script version...restarting"
	cp $install_dir/mysql-test/ndb/ndb-autotest.sh /tmp/at.$$.sh
	rm -rf $install_dir $dst_place
	sh /tmp/at.$$.sh $save_args
	exit
fi

###############################################
# Check that all interesting files are present#
###############################################

test_dir=$install_dir/mysql-test/ndb
atrt=$test_dir/atrt
html=$test_dir/make-html-reports.sh
mkconfig=$install_dir/mysql-test/ndb/make-config.sh

##########################
#Setup bin and test paths#
##########################

PATH=$install_dir/bin:$test_dir:$PATH
export PATH

###########################
# This will filter out all#
# the host that did not   #
# respond. Called below   #
###########################

filter(){
	neg=$1
	shift
	while [ $# -gt 0 ]
	do
		if [ `grep -c $1 $neg | xargs echo` -eq 0 ] ; then echo $1; fi
		shift
	done
}

############################
# check ndb_cpcc fail hosts#
############################
ndb_cpcc $hosts | awk '{ if($1=="Failed"){ print;}}' > /tmp/failed.$DATE
filter /tmp/failed.$DATE $hosts > /tmp/hosts.$DATE
hosts=`cat /tmp/hosts.$DATE`

#############################
# Push bin and test to hosts#
#############################

if [ "$deploy" ]
then
    for i in $hosts
    do
      rsync -a --delete --force --ignore-errors $install_dir/ $i:$install_dir
      ok=$?
      if [ $ok -ne 0 ]
	  then
	  echo "$i failed during rsync, excluding"
	  echo $i >> /tmp/failed.$DATE
      fi
    done
fi

###
# handle scp failed hosts
#
filter /tmp/failed.$DATE $hosts > /tmp/hosts.$DATE
hosts=`cat /tmp/hosts.$DATE`
cat /tmp/failed.$DATE > /tmp/filter_hosts.$$

#############################
# Function for replacing the#
# choose host with real host#
# names. Note $$ = PID	    #
#############################
choose(){
        SRC=$1
        TMP1=/tmp/choose.$$
        TMP2=/tmp/choose.$$.$$
        shift

        cp $SRC $TMP1
        i=1
        while [ $# -gt 0 ]
        do
                sed -e s,"CHOOSE_host$i",$1,g < $TMP1 > $TMP2
                mv $TMP2 $TMP1
                shift
                i=`expr $i + 1`
        done
        cat $TMP1
        rm -f $TMP1
}

choose_conf(){
    if [ -f $test_dir/conf-$1-$HOST.txt ]
	then
	echo "$test_dir/conf-$1-$HOST.txt"
    elif [ -f $test_dir/conf-$1.txt ]
    then
	echo "$test_dir/conf-$1.txt"
    elif [ -f $test_dir/conf-$HOST.txt ]
	echo "$test_dir/conf-$HOST.txt"
    else
	echo "Unable to find conf file looked for" 1>&2
	echo "$test_dir/conf-$1-$HOST.txt and" 1>&2
	echo "$test_dir/conf-$HOST.txt" 1>&2
	echo "$test_dir/conf-$1.txt" 1>&2
	exit
    fi
}
######################################
# Starts ATRT and gives it the right #
# command line options. after it     #
# Gathers results and moves them     #
######################################
start(){
	rm -rf report.txt result* log.txt
	$atrt -v -v -r -R --log-file=log.txt --testcase-file=$test_dir/$2-tests.txt &
	pid=$!
	echo $pid > run.pid
	wait $pid
	rm run.pid
	[ -f log.txt ] && mv log.txt $3
	[ -f report.txt ] && mv report.txt $3
	[ "`find . -name 'result*'`" ] && mv result* $3
	cd $3
	sh $html . $1 $DATE
	cd ..
	p2=`pwd`
	cd ..
	if [ "$report" ]
	then
		tar cfz /tmp/res.$2.$$.tgz `basename $p2`/$DATE
		scp /tmp/res.$2.$$.tgz \
		    $result_host:$result_path/res.$DATE.$HOST.$2.$$.tgz
		if [ $? -eq 0 ]
		then
		    rm -f /tmp/res.$2.$$.tgz
		fi
	fi
}

#########################################
# Count how many computers we have ready#
#########################################

count_hosts(){
    cnt=`grep "CHOOSE_host" $1 | awk '{for(i=1; i<=NF;i++) \
    if(index($i, "CHOOSE_host") > 0) print $i;}' | sort | uniq | wc -l`
    echo $cnt
}
#######################################################
# Calls: Choose                                       #
#	 Choose_host                                  #
#        Count_host                                   #
#	 start                                        #
# for each directory in the $RUN variable	      #
#######################################################

p=`pwd`
for dir in $RUN
do
	echo "Fixing hosts for $dir"

	run_dir=$base_dir/run-$dir-mysql-$clone-$target
	res_dir=$base_dir/result-$dir-mysql-$clone-$target/$DATE

	mkdir -p $run_dir $res_dir
	rm -rf $res_dir/*
	cd $run_dir

	if [ "$config" ]
	then
	    rm -rf $run_dir/*

	    conf=`choose_conf $dir`
	    count=`count_hosts $conf`
	    avail_hosts=`filter /tmp/filter_hosts.$$ $hosts`
	    avail=`echo $avail_hosts | wc -w`
	    if  [ $count -gt $avail ]
	    then
		echo "Not enough hosts"
		echo "Needs: $count available: $avail ($avail_hosts)"
		break;
	    fi

	    run_hosts=`echo $avail_hosts| \
                       awk '{for(i=1;i<='$count';i++)print $i;}'`
	    echo $run_hosts >> /tmp/filter_hosts.$$

	    choose $conf $run_hosts > d.tmp.$$
            sed -e s,CHOOSE_dir,"$install_dir",g < d.tmp.$$ > d.tmp
	    $mkconfig d.tmp
	fi

	if [ "$run_test" ]
	then
	    start $dir-mysql-$clone-$target $dir $res_dir &
	fi
done
cd $p
rm /tmp/filter_hosts.$$

wait

rm -f $LOCK


#!/bin/bash

# Copyright (c) 2007, 2015, Oracle and/or its affiliates. All rights reserved.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA

#############################################################
# This script created by Jonas does the following	    #
# Cleans up clones and pevious builds, pulls new clones,    #
# builds, deploys, configures the tests and launches ATRT   #
#############################################################

###############
#Script setup #
##############

save_args=$*
VERSION="upgrade-boot.sh version 1.00"

DATE=`date '+%Y-%m-%d'`
HOST=`hostname -s`
export DATE HOST

set -e

echo "`date` starting: $*"

verbose=0
do_clone=yes
build=yes

tag0=
tag1=
conf=
extra_args=
extra_clone=
LOCK=$HOME/.autotest-lock

############################
# Read command line entries#
############################

while [ "$1" ]
do
        case "$1" in
                --no-clone) do_clone="";;
                --no-build) build="";;
                --verbose) verbose=`expr $verbose + 1`;;
                --clone=*) clone0=`echo $1 | sed s/--clone=//`;;
                --clone0=*) clone0=`echo $1 | sed s/--clone0=//`;;
                --clone1=*) clone1=`echo $1 | sed s/--clone1=//`;;
                --version) echo $VERSION; exit;;
                --conf=*) conf=`echo $1 | sed s/--conf=//`;;
	        --tag=*) tag0=`echo $1 | sed s/--tag=//`;;
	        --tag0=*) tag0=`echo $1 | sed s/--tag0=//`;;
	        --tag1=*) tag1=`echo $1 | sed s/--tag1=//`;;
	        --*) echo "Unknown arg: $1";;
                *) RUN=$*;;
        esac
        shift
done

if [ -z "$clone1" ]
then
	clone1=$clone0
fi

if [ -z "$tag0" ]
then
	echo "No tag0 specified"
	exit
fi

if [ -z "$tag1" ]
then
        echo "No tag1 specified"
        exit
fi

#################################
#Make sure the configfile exists#
#if it does not exit. if it does#
# (.) load it			#
#################################
if [ -z "$conf" ]
then
	if [ -f "`pwd`/autotest.conf" ]
	then
		conf="`pwd`/autotest.conf"
	elif [ -f "$HOME/autotest.conf" ]
	then
		conf="$HOME/autotest.conf"
	fi
fi

if [ -f $conf ]
then
	. $conf
else
	echo "Can't find config file: >$conf<"
	exit
fi

###############################
# Validate that all interesting
#   variables where set in conf
###############################
vars="src_clone_base install_dir build_dir"
for i in $vars
do
  t=`echo echo \\$$i`
  if [ -z "`eval $t`" ]
  then
      echo "Invalid config: $conf, variable $i is not set"
      exit
  fi
done

###############################
#Print out the enviroment vars#
###############################

if [ $verbose -gt 0 ]
then
	env
fi

####################################
# Setup the lock file name and path#
# Setup the clone source location  #
####################################

src_clone0=${src_clone_base}${clone0}
src_clone1=${src_clone_base}${clone1}

#######################################
# Check to see if the lock file exists#
# If it does exit. 		      #
#######################################

if [ -f $LOCK ]
then
	echo "Lock file exists: $LOCK"
	exit 1
fi

#######################################
# If the lock file does not exist then#
# create it with date and run info    #
#######################################

echo "$DATE $RUN" > $LOCK

#############################
#If any errors here down, we#
# trap them, and remove the #
# Lock file before exit     #
#############################
trap "rm -f $LOCK" EXIT

# You can add more to this path#
################################

dst_place0=${build_dir}/clone-$tag0-$DATE.$$
dst_place1=${build_dir}/clone-$tag1-$DATE.$$

#########################################
# Delete source and pull down the latest#
#########################################

if [ "$do_clone" ]
then
	rm -rf $dst_place0 $dst_place1
	if [ `echo $src_clone0 | grep -c 'file:\/\/'` = 1 ]
	then
		bk clone -l -r$tag0 $src_clone0 $dst_place0
	else
		bk clone -r$tag0 $src_clone0 $dst_place0
	fi

        if [ `echo $src_clone1 | grep -c 'file:\/\/'` = 1 ]
        then
                bk clone -l -r$tag1 $src_clone1 $dst_place1
        else
                bk clone -r$tag1 $src_clone1 $dst_place1
        fi
fi

##########################################
# Build the source, make installs, and   #
# create the database to be rsynced	 #
##########################################
function build_cluster()
{
    if [ -x storage/ndb/compile-cluster ]
    then
        storage/ndb/compile-cluster --autotest $*
    else
        BUILD/compile-ndb-autotest $*
    fi
}

install_dir0=$install_dir/$tag0
install_dir1=$install_dir/$tag1
if [ "$build" ]
then
	cd $dst_place0
        rm -rf $install_dir0
        build_cluster --prefix=$install_dir0
	make install

	cd $dst_place1
	rm -rf $install_dir1
        build_cluster --prefix=$install_dir1
	make install
        fi
fi

################################
# Start run script             #
################################

script=$install_dir1/mysql-test/ndb/upgrade-run.sh
$script $save_args --conf=$conf --install-dir=$install_dir --suite=$RUN --nolock $extra_args

if [ "$build" ]
then
    rm -rf $dst_place0 $dst_place1
fi


# The log file name and location can be set in
# /etc/my.cnf by setting the "log-error" option
# in either [mysqld] or [mysqld_safe] section as
# follows:
#
# [mysqld]
# log-error=@localstatedir@/mysqld.log
#
# In case the root user has a password, then you
# have to create a /root/.my.cnf configuration file
# with the following content:
#
# [mysqladmin]
# password = <secret>
# user= root
#
# where "<secret>" is the password.
#
# ATTENTION: The /root/.my.cnf file should be readable
# _ONLY_ by root !

@localstatedir@/mysqld.log {
        # create 600 mysql mysql
        notifempty
        daily
        rotate 5
        missingok
        compress
    postrotate
	# just if mysqld is really running
	if test -x @bindir@/mysqladmin && \
	   @bindir@/mysqladmin ping &>/dev/null
	then
	   @bindir@/mysqladmin flush-logs
	fi
    endscript
}