## On OL7

rm -rf 88321
scripts/mysql_install_db --basedir=$PWD --datadir=$PWD/88321
bin/mysqld --no-defaults --basedir=$PWD --datadir=$PWD/88321 --core-file --socket=/tmp/mysql_ushastry.sock  --port=3306 --log-error=$PWD/88321/log.err 2>&1 &

[umshastr@hod03]/export/umesh/server/binaries/GABuilds/mysql-5.6.38: ./run_test.sh  5000
100..200..300..400..500..
test1 ran 507 times with 0 Duplicate Errors
100..200..300..400..500..600..
test3 ran 652 times with 196 Duplicate Errors
100..200..300..400..500..600..700..
test4 ran 739 times with 359 Duplicate Errors
100..200..300..400..500..
test5 ran 505 times with 0 Duplicate Errors
100..200..300..400..500..
test6 ran 572 times with 25 Duplicate Errors
100..200..300..400..500..600..
test7 ran 675 times with 250 Duplicate Errors

rm -rf 88321
bin/mysqld --initialize-insecure --basedir=$PWD --datadir=$PWD/88321 
bin/mysqld --no-defaults --basedir=$PWD --datadir=$PWD/88321 --core-file --socket=/tmp/mysql_ushastry.sock --port=3306 --log-error=$PWD/88321/log.err 2>&1 &

[umshastr@hod03]/export/umesh/server/binaries/GABuilds/mysql-5.7.20: ./run_test.sh  5000
100..200..300..400..500..
test1 ran 512 times with 0 Duplicate Errors
100..200..300..400..500..600..700..800..
test3 ran 865 times with 754 Duplicate Errors
100..200..300..400..500..
test4 ran 550 times with 77 Duplicate Errors
100..200..300..400..500..
test5 ran 505 times with 0 Duplicate Errors
100..200..300..400..500..600..
test6 ran 633 times with 0 Duplicate Errors
100..200..300..400..500..600..700..800..
test7 ran 851 times with 815 Duplicate Errors


[umshastr@hod03]/export/umesh/server/binaries/GABuilds/mysql-5.7.20: cat fake_traffic.sh run_test.sh
#!/bin/csh

if($#argv == 0) then
  echo No args - Manual Testing
  set file=/tmp/rb.log
else
   echo Running $argv[1]
   set file=/tmp/$argv[1].log
 echo "file $file"
fi
set conns=(`seq 1 5`)

foreach i ($conns)
  echo "INSERT INTO test (testcol) VALUES ('test123')" | bin/mysql -uroot -S /tmp/mysql_ushastry.sock test >>& $file &
  echo "SELECT * from test limit 10000" | bin/mysql -uroot -S /tmp/mysql_ushastry.sock test >>& $file &
end

#!/bin/sh

setup()
{
  echo "truncate test" |  bin/mysql -uroot -S /tmp/mysql_ushastry.sock test > /dev/null 2>&1
  echo "INSERT INTO test (testcol) VALUES ('test123')" | bin/mysql -uroot -S /tmp/mysql_ushastry.sock test > /dev/null 2>&1
  echo "SET @@GLOBAL.auto_increment_offset=1, @@GLOBAL.auto_increment_increment=1" | bin/mysql -uroot -S /tmp/mysql_ushastry.sock test > /dev/null 2>&1
}

test1()
{
  echo "FLUSH TABLES WITH READ LOCK;SET @@GLOBAL.auto_increment_offset=1, @@GLOBAL.auto_increment_increment=1;UNLOCK TABLES" | mysql -uroot test > /dev/null 2>&1
  echo "SET @@GLOBAL.auto_increment_offset=1, @@GLOBAL.auto_increment_increment=2" | bin/mysql -uroot -S /tmp/mysql_ushastry.sock test > /dev/null 2>&1
}

test2()
{
  echo "FLUSH TABLES WITH READ LOCK;SET @@GLOBAL.auto_increment_offset=1, @@GLOBAL.auto_increment_increment=1;select sleep(1);UNLOCK TABLES" | bin/mysql -uroot -S /tmp/mysql_ushastry.sock test > /dev/null 2>&1
  echo "SET @@GLOBAL.auto_increment_offset=1, @@GLOBAL.auto_increment_increment=2" | bin/mysql -uroot -S /tmp/mysql_ushastry.sock test > /dev/null 2>&1
}

test3()
{
  echo "FLUSH TABLES WITH READ LOCK" | mysql -uroot test > /dev/null 2>&1
  echo "SET @@GLOBAL.auto_increment_offset=1, @@GLOBAL.auto_increment_increment=1" | bin/mysql -uroot -S /tmp/mysql_ushastry.sock test > /dev/null 2>&1
  echo "UNLOCK TABLES" | mysql -uroot test > /dev/null 2>&1
  echo "SET @@GLOBAL.auto_increment_offset=1, @@GLOBAL.auto_increment_increment=2" | bin/mysql -uroot -S /tmp/mysql_ushastry.sock test > /dev/null 2>&1
}

test4()
{
  echo "SET @@GLOBAL.auto_increment_offset=1, @@GLOBAL.auto_increment_increment=1" | bin/mysql -uroot -S /tmp/mysql_ushastry.sock test > /dev/null 2>&1
  echo "SET @@GLOBAL.auto_increment_offset=1, @@GLOBAL.auto_increment_increment=2" | bin/mysql -uroot -S /tmp/mysql_ushastry.sock test > /dev/null 2>&1
}

test5()
{
  echo "FLUSH TABLES WITH READ LOCK;select "HI";SET @@GLOBAL.auto_increment_offset=1, @@GLOBAL.auto_increment_increment=1;UNLOCK TABLES" | bin/mysql -uroot -S /tmp/mysql_ushastry.sock test > /dev/null 2>&1
  echo "SET @@GLOBAL.auto_increment_offset=1, @@GLOBAL.auto_increment_increment=2" | bin/mysql -uroot -S /tmp/mysql_ushastry.sock test > /dev/null 2>&1
}

test6()
{
  echo "FLUSH TABLES WITH READ LOCK;SET @@GLOBAL.auto_increment_increment=1;UNLOCK TABLES" | bin/mysql -uroot -S /tmp/mysql_ushastry.sock test > /dev/null 2>&1
  echo "SET @@GLOBAL.auto_increment_offset=1, @@GLOBAL.auto_increment_increment=2" | bin/mysql -uroot -S /tmp/mysql_ushastry.sock test > /dev/null 2>&1
}

test7()
{
  echo "SET @@GLOBAL.auto_increment_increment=1" | bin/mysql -uroot -S /tmp/mysql_ushastry.sock test > /dev/null 2>&1
  echo "SET @@GLOBAL.auto_increment_offset=1, @@GLOBAL.auto_increment_increment=2" | bin/mysql -uroot -S /tmp/mysql_ushastry.sock test > /dev/null 2>&1
}

# Run tests above
#run="1 5"
#run="3 5"
run="1 3 4 5 6 7"

loop=$1
rm -rf /tmp/test*.log

for i in $run
do
attempt=1
maxid=0
setup

while [[ $maxid -lt $loop ]]
do
  ./fake_traffic.sh test$i > /dev/null 2>&1 &
  maxid=`echo "select max(test_id) from test" | bin/mysql -N -uroot -S /tmp/mysql_ushastry.sock test 2> /dev/null`
  status=$(($attempt%100))
  if [ "$status" -eq "0" ]; then
    echo -n "$attempt.."
  fi
  test$i
  attempt=$((attempt+1))
done
echo ""
found=`grep Duplicate /tmp/test$i.log | wc -l`
# remove leading whitespace characters
found="${found#"${found%%[![:space:]]*}"}"
# remove trailing whitespace characters
found="${found%"${found##*[![:space:]]}"}"
echo "test$i ran $attempt times with $found Duplicate Errors"
done
