You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
nsc_ba_public/tpch/tpch.sh

275 lines
8.6 KiB

#!/bin/bash
set -e
PWD=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
MYCMD="tpch.sh"
MYVAR="tpch_variables.sh"
##################################################################################################################################################
# Functions
##################################################################################################################################################
check_variables()
{
new_variable="0"
### Make sure variables file is available
if [ ! -f "$PWD/$MYVAR" ]; then
touch $PWD/$MYVAR
new_variable=$(($new_variable + 1))
fi
local count=$(grep "REPO=" $MYVAR | wc -l)
if [ "$count" -eq "0" ]; then
echo "REPO=\"TPC-H\"" >> $MYVAR
new_variable=$(($new_variable + 1))
fi
local count=$(grep "REPO_URL=" $MYVAR | wc -l)
if [ "$count" -eq "0" ]; then
echo "REPO_URL=\"https://github.com/pivotalguru/TPC-H\"" >> $MYVAR
new_variable=$(($new_variable + 1))
fi
local count=$(grep "ADMIN_USER=" $MYVAR | wc -l)
if [ "$count" -eq "0" ]; then
echo "ADMIN_USER=\"gpadmin\"" >> $MYVAR
new_variable=$(($new_variable + 1))
fi
local count=$(grep "INSTALL_DIR=" $MYVAR | wc -l)
if [ "$count" -eq "0" ]; then
echo "INSTALL_DIR=\"/pivotalguru\"" >> $MYVAR
new_variable=$(($new_variable + 1))
fi
local count=$(grep "EXPLAIN_ANALYZE=" $MYVAR | wc -l)
if [ "$count" -eq "0" ]; then
echo "EXPLAIN_ANALYZE=\"false\"" >> $MYVAR
new_variable=$(($new_variable + 1))
fi
local count=$(grep "RANDOM_DISTRIBUTION=" $MYVAR | wc -l)
if [ "$count" -eq "0" ]; then
echo "RANDOM_DISTRIBUTION=\"false\"" >> $MYVAR
new_variable=$(($new_variable + 1))
fi
local count=$(grep "MULTI_USER_COUNT" $MYVAR | wc -l)
if [ "$count" -eq "0" ]; then
echo "MULTI_USER_COUNT=\"5\"" >> $MYVAR
new_variable=$(($new_variable + 1))
fi
local count=$(grep "GEN_DATA_SCALE" $MYVAR | wc -l)
if [ "$count" -eq "0" ]; then
echo "GEN_DATA_SCALE=\"3000\"" >> $MYVAR
new_variable=$(($new_variable + 1))
fi
local count=$(grep "SINGLE_USER_ITERATIONS" $MYVAR | wc -l)
if [ "$count" -eq "0" ]; then
echo "SINGLE_USER_ITERATIONS=\"1\"" >> $MYVAR
new_variable=$(($new_variable + 1))
fi
#00
local count=$(grep "RUN_COMPILE_TPCH" $MYVAR | wc -l)
if [ "$count" -eq "0" ]; then
echo "RUN_COMPILE_TPCH=\"false\"" >> $MYVAR
new_variable=$(($new_variable + 1))
fi
#01
local count=$(grep "RUN_GEN_DATA" $MYVAR | wc -l)
if [ "$count" -eq "0" ]; then
echo "RUN_GEN_DATA=\"false\"" >> $MYVAR
new_variable=$(($new_variable + 1))
fi
#02
local count=$(grep "RUN_INIT" $MYVAR | wc -l)
if [ "$count" -eq "0" ]; then
echo "RUN_INIT=\"true\"" >> $MYVAR
new_variable=$(($new_variable + 1))
fi
#03
local count=$(grep "RUN_DDL" $MYVAR | wc -l)
if [ "$count" -eq "0" ]; then
echo "RUN_DDL=\"true\"" >> $MYVAR
new_variable=$(($new_variable + 1))
fi
#04
local count=$(grep "RUN_LOAD" $MYVAR | wc -l)
if [ "$count" -eq "0" ]; then
echo "RUN_LOAD=\"true\"" >> $MYVAR
new_variable=$(($new_variable + 1))
fi
#05
local count=$(grep "RUN_SQL" $MYVAR | wc -l)
if [ "$count" -eq "0" ]; then
echo "RUN_SQL=\"true\"" >> $MYVAR
new_variable=$(($new_variable + 1))
fi
#06
local count=$(grep "RUN_SINGLE_USER_REPORT" $MYVAR | wc -l)
if [ "$count" -eq "0" ]; then
echo "RUN_SINGLE_USER_REPORT=\"true\"" >> $MYVAR
new_variable=$(($new_variable + 1))
fi
#07
local count=$(grep "RUN_MULTI_USER" $MYVAR | wc -l)
if [ "$count" -eq "0" ]; then
echo "RUN_MULTI_USER=\"true\"" >> $MYVAR
new_variable=$(($new_variable + 1))
fi
#08
local count=$(grep "RUN_MULTI_USER_REPORT" $MYVAR | wc -l)
if [ "$count" -eq "0" ]; then
echo "RUN_MULTI_USER_REPORT=\"true\"" >> $MYVAR
new_variable=$(($new_variable + 1))
fi
if [ "$new_variable" -gt "0" ]; then
echo "There are new variables in the tpch_variables.sh file. Please review to ensure the values are correct and then re-run this script."
exit 1
fi
echo "############################################################################"
echo "Sourcing $MYVAR"
echo "############################################################################"
echo ""
source $MYVAR
}
check_user()
{
### Make sure root is executing the script. ###
echo "############################################################################"
echo "Make sure root is executing this script."
echo "############################################################################"
echo ""
local WHOAMI=`whoami`
if [ "$WHOAMI" != "root" ]; then
echo "Script must be executed as root!"
exit 1
fi
}
yum_installs()
{
### Install and Update Demos ###
echo "############################################################################"
echo "Install git and gcc with yum."
echo "############################################################################"
echo ""
# Install git and gcc if not found
local YUM_INSTALLED=$(yum --help 2> /dev/null | wc -l)
local CURL_INSTALLED=$(gcc --help 2> /dev/null | wc -l)
local GIT_INSTALLED=$(git --help 2> /dev/null | wc -l)
if [ "$YUM_INSTALLED" -gt "0" ]; then
if [ "$CURL_INSTALLED" -eq "0" ]; then
yum -y install gcc
fi
if [ "$GIT_INSTALLED" -eq "0" ]; then
yum -y install git
fi
else
if [ "$CURL_INSTALLED" -eq "0" ]; then
echo "gcc not installed and yum not found to install it."
echo "Please install gcc and try again."
exit 1
fi
if [ "$GIT_INSTALLED" -eq "0" ]; then
echo "git not installed and yum not found to install it."
echo "Please install git and try again."
exit 1
fi
fi
echo ""
}
repo_init()
{
### Install repo ###
echo "############################################################################"
echo "Install the github repository."
echo "############################################################################"
echo ""
internet_down="0"
for j in $(curl google.com 2>&1 | grep "Couldn't resolve host"); do
internet_down="1"
done
if [ ! -d $INSTALL_DIR ]; then
if [ "$internet_down" -eq "1" ]; then
echo "Unable to continue because repo hasn't been downloaded and Internet is not available."
exit 1
else
echo ""
echo "Creating install dir"
echo "-------------------------------------------------------------------------"
mkdir $INSTALL_DIR
chown $ADMIN_USER $INSTALL_DIR
fi
fi
if [ ! -d $INSTALL_DIR/$REPO ]; then
if [ "$internet_down" -eq "1" ]; then
echo "Unable to continue because repo hasn't been downloaded and Internet is not available."
exit 1
else
echo ""
echo "Creating $REPO directory"
echo "-------------------------------------------------------------------------"
mkdir $INSTALL_DIR/$REPO
chown $ADMIN_USER $INSTALL_DIR/$REPO
su -c "cd $INSTALL_DIR; GIT_SSL_NO_VERIFY=true; git clone --depth=1 $REPO_URL" $ADMIN_USER
fi
else
chown -R $ADMIN_USER $INSTALL_DIR/$REPO
if [ "$internet_down" -eq "0" ]; then
git config --global user.email "$ADMIN_USER@$HOSTNAME"
git config --global user.name "$ADMIN_USER"
su -c "cd $INSTALL_DIR/$REPO; GIT_SSL_NO_VERIFY=true; git fetch --all; git reset --hard origin/master" $ADMIN_USER
fi
fi
}
script_check()
{
### Make sure the repo doesn't have a newer version of this script. ###
echo "############################################################################"
echo "Make sure this script is up to date."
echo "############################################################################"
echo ""
# Must be executed after the repo has been pulled
local d=`diff $PWD/$MYCMD $INSTALL_DIR/$REPO/$MYCMD | wc -l`
if [ "$d" -eq "0" ]; then
echo "$MYCMD script is up to date so continuing to TPC-H."
echo ""
else
echo "$MYCMD script is NOT up to date."
echo ""
cp $INSTALL_DIR/$REPO/$MYCMD $PWD/$MYCMD
echo "After this script completes, restart the $MYCMD with this command:"
echo "./$MYCMD"
exit 1
fi
}
echo_variables()
{
echo "############################################################################"
echo "REPO: $REPO"
echo "REPO_URL: $REPO_URL"
echo "ADMIN_USER: $ADMIN_USER"
echo "INSTALL_DIR: $INSTALL_DIR"
echo "MULTI_USER_COUNT: $MULTI_USER_COUNT"
echo "############################################################################"
echo ""
}
##################################################################################################################################################
# Body
##################################################################################################################################################
check_user
check_variables
yum_installs
repo_init
script_check
echo_variables
su --session-command="cd \"$INSTALL_DIR/$REPO\"; ./rollout.sh $GEN_DATA_SCALE $EXPLAIN_ANALYZE $RANDOM_DISTRIBUTION $MULTI_USER_COUNT $RUN_COMPILE_TPCH $RUN_GEN_DATA $RUN_INIT $RUN_DDL $RUN_LOAD $RUN_SQL $RUN_SINGLE_USER_REPORT $RUN_MULTI_USER $RUN_MULTI_USER_REPORT $SINGLE_USER_ITERATIONS" $ADMIN_USER