#!/bin/sh
if [ "$#" -ne 1 ]; then
echo "USAGE: $0 warehouses"
exit 1
fi
warehouses=$1
path=$(
cd "$(dirname "$0")"
pwd
)
echo "install mariadb"
yum install mariadb mariadb-server mariadb-devel -y
mv /etc/my.cnf /etc/my-tmp.cnf
cp my.cnf /etc/
systemctl restart mariadb
echo "update the mariadb client"
sed -i "s#sh .*/mariadb_benchmark.sh#sh $path/mariadb_benchmark.sh#g" "$path"/mariadb_client.yaml
sed -i "s#warehouses#$warehouses#g" "$path"/mariadb_benchmark.sh
echo "install mariadb benchmark"
rm -rf tpcc-mysql
git clone https://github.com/Percona-Lab/tpcc-mysql.git
cd tpcc-mysql/src
sed -i 's#$(CC) $(OBJS) $(LIBS) -o ../tpcc_start#$(CC) $(OBJS) $(LIBS) -o ../tpcc_start -lm#' Makefile
make
cd ..
cp tpcc_start /usr/bin
echo "create database and tables"
mysqladmin -u root -f drop tpcctest 2 &>/dev/null
mysql -u root -e "create database tpcctest"
mysql -u root tpcctest <create_table.sql
mysql -u root tpcctest <add_fkey_idx.sql
sed -i "s/STEP=.*/STEP=10/g" load.sh
sh load.sh tpcctest "$warehouses"
ret=0
while (($ret == 0)); do
echo "loading data, please waiting ..."
sleep 5
ps -ef | grep tpcc_load | grep -v grep >/dev/null
ret=$?
done
echo "loading data end"
echo "cp mariadb_server.yaml to /etc/atuned/tuning"
mkdir -p /etc/atuned/tuning
cp $path/mariadb_server.yaml /etc/atuned/tuning
echo "finish prepare"