forked from MonetDBSolutions/tpch-scripts
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtpch_build.sh
executable file
·162 lines (139 loc) · 3.98 KB
/
tpch_build.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
#!/usr/bin/env bash
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#
# Copyright 2017-2018 MonetDB Solutions B.V.
# The path to the database farm
farm_path=
# The TPC-H scale factor
scale_factor=
# The daemon port
port=50000
# Should we actually run?
dry_run=
# show commands as they are executed
verbose=
usage() {
echo "Usage: $0 --sf <scale factor> --farm <farm path> [--port <port>] [--dry-run]"
echo "Generate and load TPC-H data to MonetDB"
echo ""
echo "Options:"
echo " -s, --sf <scale factor> The scale factor for TPC-H data."
echo " Scale factor 1 is 1GB of data."
echo " Scale factor 0.1 is 100MB of data."
echo " -f, --farm <farm path> The absolute path to the MonetDB"
echo " data farm."
echo " -p, --port <port> The MonetDB daemon listen port"
echo " (default 50000)."
echo " -d, --dry-run Do not generate or load data,"
echo " just print the start up command."
}
server_startup_command() {
echo "Use the command"
echo ""
echo " mserver5 --dbpath=$farm_path/SF-$scale_factor --set monet_vault_key=$farm_path/SF-$scale_factor/.vaultkey"
echo ""
echo "to start the server."
}
while [ "$#" -gt 0 ]; do
case "$1" in
-s|--sf)
if [ "$2" != "${2//[,]/}" ]; then
echo -e "ERROR: invalid scale factor \"$2\". Use '.' as decimal separator instead\n"
usage
exit 1
fi
# For scale factor smaller than 1, replace the '.' with '_' for the dbname
scale_factor=${2//[.]/_}
shift
shift
;;
-f|--farm)
farm_path=${2%/}
shift
shift
;;
-p|--port)
port=$2
shift
shift
;;
-d|--dry-run)
dry_run="true"
shift
;;
-v|--verbose)
verbose="true"
shift
;;
-h|--help)
usage
exit 0
;;
*)
echo "$0: Unknown parameter $1"
usage
exit 1
;;
esac
done
if [ -z "$scale_factor" -o -z "$farm_path" ]; then
usage
exit 1
fi
# Make sure the farm path given is absolute
if [ "$farm_path" = "${farm_path#/}" ]; then
usage
exit 1
fi
if [ ! -z "$dry_run" ]; then
server_startup_command
exit 0
fi
if [ ! -z "$verbose" ]; then
set -x
fi
# Find the root directory of the TPC-H scripts
root_directory=$(readlink -f $0)
root_directory=${root_directory%${0:1}}
echo "Root directory = $root_directory"
# Go to the scripts root directory
pushd $root_directory
# Add dot monetdb file for permissions
test -f $HOME/.monetdb || cat << EOF > $HOME/.monetdb
user=monetdb
password=monetdb
save_history=true
EOF
# Generate the data if the following directory does not exist.
# TODO: Add a condition about the actual files we need.
if [ ! -e "$root_directory/02_load/SF-$scale_factor/data" ]; then
pushd 01_build/dbgen
make
# Create the data for the scale factor
./dbgen -vf -s "$scale_factor"
mkdir -p "$root_directory/02_load/SF-$scale_factor/data"
mv *.tbl "$root_directory/02_load/SF-$scale_factor/data"
popd
fi
pushd 02_load
# Create the database farm
if [ ! -e "$farm_path" ]; then
monetdbd create "$farm_path"
fi
# Start the daemon
monetdbd set port="$port" "$farm_path"
monetdbd start "$farm_path"
# Load the data
./sf_build.sh SF-"$scale_factor" "$port"
if [ $? != 0 ]; then
echo "Data not loaded correctly"
exit 1
fi
# Stop the daemon
monetdbd stop "$farm_path"
echo "SF-$scale_factor loaded."
server_startup_command
# Go back to the original directory
popd