-
Notifications
You must be signed in to change notification settings - Fork 20
/
tpch.sh
executable file
·275 lines (256 loc) · 8.64 KB
/
tpch.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
#!/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