forked from babelfish-for-postgresql/babelfish_extensions
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdev-tools.sh
executable file
·355 lines (316 loc) · 12.1 KB
/
dev-tools.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
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
#!/bin/sh
set -e
if [ ! $1 ]; then
echo "This is a tool helping developers to build and test Babelfish easily."
echo ""
echo "Prerequisites:"
echo " (1) Each workspace should contain postgresql_modified_for_babelfish and babelfish_extensions directories."
echo ""
echo "Commands:"
echo " (if TARGET_WS is not provided, the current workspace will be used)"
echo ""
echo " initpg [TARGET_WS]"
echo " init postgres directory + build pg and contrib + copy ANTLR lib + build pg_hint_plan"
echo ""
echo " initdb [TARGET_WS]"
echo " init data directory + modify postgresql.conf + restart db"
echo ""
echo " initbbf [TARGET_WS]"
echo " execute babelfish_extensions/test/JDBC/init.sh"
echo ""
echo " buildpg [TARGET_WS]"
echo " build postgresql_modified_for_babelfish + restart db"
echo ""
echo " buildbbf [TARGET_WS]"
echo " build babelfish_extensions + restart db"
echo ""
echo " buildall [TARGET_WS]"
echo " build postgresql_modified_for_babelfish + build babelfish_extensions + restart db"
echo ""
echo " pg_upgrade SOURCE_WS [TARGET_WS]"
echo " run pg_upgrade from SOURCE_WS to TARGET_WS"
echo ""
echo " test normal [MIGRATION_MODE] [TEST_BASE_DIR]"
echo " run a normal JDBC test, default migration mode and test dir are single-db and input, respectively"
echo ""
echo " test TEST_MODE MIGRATION_MODE TEST_BASE_DIR"
echo " run a prepare/verify JDBC test using a schedule file in TEST_BASE_DIR"
echo ""
echo " minor_version_upgrade SOURCE_WS [TARGET_WS]"
echo " upgrade minor version using ALTER EXTENSION ... UPDATE"
echo ""
echo " run_pgindent [TARGET_WS]"
echo " run pgindent"
exit 0
fi
SCRIPT_DIR="$( cd -- "$( dirname -- "${BASH_SOURCE[0]:-$0}"; )" &> /dev/null && pwd 2> /dev/null; )";
cd $SCRIPT_DIR
cd ..
CUR_WS=$PWD
echo "Current Workspace: $CUR_WS"
TARGET_WS=$2
if [ "$1" == "pg_upgrade" ] || [ "$1" == "minor_version_upgrade" ]; then
TARGET_WS=$3
elif [ "$1" == "test" ]; then
TARGET_WS=$CUR_WS
TEST_MODE=$2
if [ ! $TEST_MODE ]; then
echo "Error: TEST_MODE should be specified, normal, prepare or verify" 1>&2
exit 1
elif [ "${TEST_MODE}" != "normal" ] && [ "${TEST_MODE}" != "prepare" ] && [ "${TEST_MODE}" != "verify" ]; then
echo "Error: TEST_MODE should be one of: normal, prepare or verify" 1>&2
exit 1
fi
MIGRATION_MODE=$3
if [ ! ${MIGRATION_MODE} ]; then
if [ "${TEST_MODE?}" == "normal" ]; then
MIGRATION_MODE="single-db"
else
echo "Error: MIGRATION_MODE should be specified, single-db or multi-db" 1>&2
exit 1
fi
fi
TEST_BASE_DIR=$4
if [ ! $TEST_BASE_DIR ]; then
if [ "${TEST_MODE?}" == "normal" ]; then
TEST_BASE_DIR="input"
else
echo "Error: TEST_BASE_DIR should be specified" 1>&2
fi
fi
fi
if [ ! $TARGET_WS ]; then
TARGET_WS=$CUR_WS
fi
echo "Target Workspace: $TARGET_WS"
TEST_DB="jdbc_testdb"
cd $TARGET_WS
if [ ! -d "./postgresql_modified_for_babelfish" ]; then
echo "Error: Directory \"postgresql_modified_for_babelfish\" should exist in the target workspace." 1>&2
exit 1
fi
if [ ! -d "./babelfish_extensions" ]; then
echo "Error: Directory \"babelfish_extensions\" should exist in the target workspace." 1>&2
exit 1
fi
restart() {
cd $1/postgres
bin/pg_ctl -D data/ -l logfile restart
}
stop() {
cd $1/postgres
bin/pg_ctl -D data/ -l logfile stop
}
build_pg() {
cd $1/postgresql_modified_for_babelfish
make install
}
build_bbf() {
cd $1/babelfish_extensions
export PG_CONFIG=$2/postgres/bin/pg_config
export PG_SRC=$1/postgresql_modified_for_babelfish
export cmake=$(which cmake)
cd contrib/babelfishpg_money
make clean && make && make install
cd ../babelfishpg_common
make clean && make && make install
cd ../babelfishpg_tds
make clean && make && make install
cd ../babelfishpg_tsql
make clean && make && make install
}
init_db() {
cd $1/postgres
rm -rf data
bin/initdb -D data/
PID=$(ps -ef | grep postgres/bin/postgres | grep -v grep | awk '{print $2}')
if [ $PID ]
then
kill -9 $PID
fi
sleep 1
bin/pg_ctl -D data/ -l logfile start
cd data
sudo sed -i "s/#listen_addresses = 'localhost'/listen_addresses = '*'/g" postgresql.conf
sudo sed -i "s/#shared_preload_libraries = ''/shared_preload_libraries = 'babelfishpg_tds'/g" postgresql.conf
sudo echo "host all all 0.0.0.0/0 trust" >> pg_hba.conf
restart $1
}
init_pghint() {
cd $1
if [ ! -d "./pg_hint_plan" ]; then
git clone --depth 1 --branch REL14_1_4_0 https://github.com/ossc-db/pg_hint_plan.git
fi
cd pg_hint_plan
export PATH=$2/postgres/bin:$PATH
make
make install
}
init_pg() {
cd $1/postgresql_modified_for_babelfish
./configure --prefix=$2/postgres/ --without-readline --without-zlib --enable-debug --enable-cassert CFLAGS="-ggdb" --with-libxml --with-uuid=ossp --with-icu
make -j 4
make install
cd contrib && make && sudo make install
cp "/usr/local/lib/libantlr4-runtime.so.4.9.3" $2/postgres/lib/
init_pghint $1 $2
}
run_pgindent() {
cd $1/postgres/lib
echo "dumping typedefs for babelfishpg_mpney to /tmp/babelfishpg_money.typedefs.."
objdump -W babelfishpg_money.so | egrep -A3 DW_TAG_typedef | perl -e ' while (<>) { chomp; @flds = split;next unless (1 < @flds);\
next if $flds[0] ne "DW_AT_name" && $flds[1] ne "DW_AT_name";\
next if $flds[-1] =~ /^DW_FORM_str/;\
print $flds[-1],"\n"; }' | sort | uniq > /tmp/babelfishpg_money.typedefs
echo "dumping typedefs for babelfishpg_common to /tmp/babelfishpg_common.typedefs.."
objdump -W babelfishpg_common.so | egrep -A3 DW_TAG_typedef | perl -e ' while (<>) { chomp; @flds = split;next unless (1 < @flds);\
next if $flds[0] ne "DW_AT_name" && $flds[1] ne "DW_AT_name";\
next if $flds[-1] =~ /^DW_FORM_str/;\
print $flds[-1],"\n"; }' | sort | uniq > /tmp/babelfishpg_common.typedefs
echo "dumping typedefs for babelfishpg_tds to /tmp/babelfishpg_tds.typedefs.."
objdump -W babelfishpg_tds.so | egrep -A3 DW_TAG_typedef | perl -e ' while (<>) { chomp; @flds = split;next unless (1 < @flds);\
next if $flds[0] ne "DW_AT_name" && $flds[1] ne "DW_AT_name";\
next if $flds[-1] =~ /^DW_FORM_str/;\
print $flds[-1],"\n"; }' | sort | uniq > /tmp/babelfishpg_tds.typedefs
echo "dumping typedefs for babelfishpg_tsql to /tmp/babelfishpg_tsql.typedefs.."
objdump -W babelfishpg_tsql.so | egrep -A3 DW_TAG_typedef | perl -e ' while (<>) { chomp; @flds = split;next unless (1 < @flds);\
next if $flds[0] ne "DW_AT_name" && $flds[1] ne "DW_AT_name";\
next if $flds[-1] =~ /^DW_FORM_str/;\
print $flds[-1],"\n"; }' | sort | uniq > /tmp/babelfishpg_tsql.typedefs
cd $1
echo "Clone and build pg_bsd_indent which is required by pgindent..."
git clone https://git.postgresql.org/git/pg_bsd_indent.git
cd pg_bsd_indent/
make PG_CONFIG=$1/postgres/bin/pg_config
sudo cp pg_bsd_indent /usr/local/bin
cd $1/babelfish_extensions
echo ""
echo "Running pgindent on babelfishpg_money..."
cd contrib/babelfishpg_money
$1/postgresql_modified_for_babelfish/src/tools/pgindent/pgindent --typedefs=/tmp/babelfishpg_money.typedefs
echo ""
echo "Running pgindent on babelfishpg_common..."
cd ../babelfishpg_common
$1/postgresql_modified_for_babelfish/src/tools/pgindent/pgindent --typedefs=/tmp/babelfishpg_common.typedefs
echo ""
echo "Running pgindent on babelfishpg_tds..."
cd ../babelfishpg_tds
$1/postgresql_modified_for_babelfish/src/tools/pgindent/pgindent --typedefs=/tmp/babelfishpg_tds.typedefs
echo ""
echo "Running pgindent on babelfishpg_tsql..."
cd ../babelfishpg_tsql
$1/postgresql_modified_for_babelfish/src/tools/pgindent/pgindent --typedefs=/tmp/babelfishpg_tsql.typedefs --exclude="exclude_file_from_pgindent"
echo ""
echo "pgindent is ran successfully against $1."
echo "Please re-build all the extensions to make sure that there is no compilation error."
echo ""
}
if [ "$1" == "initdb" ]; then
init_db $TARGET_WS
exit 0
elif [ "$1" == "initpg" ]; then
init_pg $TARGET_WS $TARGET_WS
exit 0
elif [ "$1" == "initbbf" ]; then
$TARGET_WS/babelfish_extensions/test/JDBC/init.sh
exit 0
elif [ "$1" == "buildpg" ]; then
build_pg $TARGET_WS
restart $TARGET_WS
exit 0
elif [ "$1" == "buildbbf" ]; then
build_bbf $TARGET_WS $TARGET_WS
restart $TARGET_WS
exit 0
elif [ "$1" == "buildall" ]; then
build_pg $TARGET_WS
build_bbf $TARGET_WS $TARGET_WS
restart $TARGET_WS
exit 0
elif [ "$1" == "pg_upgrade" ]; then
init_db $TARGET_WS
stop $TARGET_WS
echo "Init target workspace ($TARGET_WS) done!"
SOURCE_WS=$2
stop $SOURCE_WS || true
cd $TARGET_WS
if [ ! -d "./upgrade" ]; then
mkdir upgrade
fi
cd upgrade
../postgres/bin/pg_upgrade -U $USER \
-b $SOURCE_WS/postgres/bin -B $TARGET_WS/postgres/bin \
-d $SOURCE_WS/postgres/data -D $TARGET_WS/postgres/data \
-p 5432 -P 5433 -j 4 --link --verbose --retain
echo ""
./delete_old_cluster.sh
cd $TARGET_WS/postgres
bin/pg_ctl -D data/ -l logfile start
echo ""
echo 'Updating babelfish extensions...'
bin/psql -d $TEST_DB -U $USER -c \
"ALTER EXTENSION babelfishpg_common UPDATE; ALTER EXTENSION babelfishpg_tsql UPDATE;"
bin/psql -d $TEST_DB -U $USER -c \
"ALTER SYSTEM SET babelfishpg_tsql.database_name = 'jdbc_testdb';"
bin/psql -d $TEST_DB -U $USER -c \
"SELECT pg_reload_conf();"
exit 0
elif [ "$1" == "test" ]; then
# Set migration_mode
cd $TARGET_WS/postgres
bin/psql -d $TEST_DB -U $USER -c \
"ALTER SYSTEM SET babelfishpg_tsql.migration_mode = '$MIGRATION_MODE';"
bin/psql -d $TEST_DB -U $USER -c \
"SELECT pg_reload_conf();"
# Remove output directory
cd $CUR_WS/babelfish_extensions/test/JDBC
rm -rf output temp_schedule
export inputFilesPath=input
if [ "$TEST_MODE" == "normal" ]; then
export inputFilesPath=${TEST_BASE_DIR?}
elif [ "$TEST_MODE" == "prepare" ]; then
for filename in $(grep -v "^ignore.*\|^#.*\|^cmd.*\|^all.*\|^$" $TEST_BASE_DIR/schedule); do
if [[ ! ($(find input/ -name $filename"-vu-prepare.*") || $(find input/ -name $filename"-vu-verify.*")) ]]; then
printf '%s\n' "ERROR: Cannot find Test file "$filename"-vu-prepare or "$filename"-vu-verify in input directory !!" >&2
exit 1
fi
done
cat $TEST_BASE_DIR/schedule > temp_schedule
for filename in $(grep -v "^ignore.*\|^#.*\|^cmd.*\|^all.*\|^$" temp_schedule); do
sed -i "s/$filename[ ]*$/$filename-vu-prepare/g" temp_schedule
done
export scheduleFile=temp_schedule
elif [ "$TEST_MODE" == "verify" ]; then
for filename in $(grep -v "^ignore.*\|^#.*\|^cmd.*\|^all.*\|^$" $TEST_BASE_DIR/schedule); do
trimmed=$(awk '{$1=$1;print}' <<< "$filename")
echo $trimmed-vu-verify >> temp_schedule;
echo $trimmed-vu-cleanup >> temp_schedule;
done
export scheduleFile=temp_schedule
fi
mvn test
rm -rf temp_schedule
exit 0
elif [ "$1" == "minor_version_upgrade" ]; then
echo "Building from $SOURCE_WS..."
SOURCE_WS=$2
init_pg $SOURCE_WS $TARGET_WS
build_bbf $SOURCE_WS $TARGET_WS
echo "Initializing from $SOURCE_WS..."
init_db $TARGET_WS
$TARGET_WS/babelfish_extensions/test/JDBC/init.sh
echo "Building from $TARGET_WS..."
build_pg $TARGET_WS
build_bbf $TARGET_WS $TARGET_WS
restart $TARGET_WS
echo "Updating Babelfish..."
cd $TARGET_WS/postgres
bin/psql -d $TEST_DB -U $USER -c \
"ALTER EXTENSION babelfishpg_common UPDATE; ALTER EXTENSION babelfishpg_tsql UPDATE;"
exit 0
elif [ "$1" == "run_pgindent" ]; then
init_pg $TARGET_WS $TARGET_WS
build_bbf $TARGET_WS $TARGET_WS
run_pgindent $TARGET_WS
exit 0
fi