@@ -23,7 +23,7 @@ while true; do
23
23
--db-dump-path )
24
24
DB_DUMP_PATH=" $2 " ; shift 2 ;;
25
25
--after-db-init-code )
26
- # s3 url|filename +
26
+ # s3 url|filename|content
27
27
AFTER_DB_INIT_CODE=" $2 " ; shift 2 ;;
28
28
--workload-full-path )
29
29
# s3 url
@@ -32,18 +32,18 @@ while true; do
32
32
# Still unsuported
33
33
WORKLOAD_BASIS_PATH=" $2 " ; shift 2 ;;
34
34
--workload-custom-sql )
35
- # s3 url|filename +
35
+ # s3 url|filename|content
36
36
WORKLOAD_CUSTOM_SQL=" $2 " ; shift 2 ;;
37
37
--workload-replay-speed )
38
38
WORKLOAD_REPLAY_SPEED=" $2 " ; shift 2 ;;
39
39
--target-ddl-do )
40
- # s3 url|filename +
40
+ # s3 url|filename|content
41
41
TARGET_DDL_DO=" $2 " ; shift 2 ;;
42
42
--target-ddl-undo )
43
- # s3 url|filename +
43
+ # s3 url|filename|content
44
44
TARGET_DDL_UNDO=" $2 " ; shift 2 ;;
45
45
--target-config )
46
- # s3 url|filename +
46
+ # s3 url|filename|content
47
47
TARGET_CONFIG=" $2 " ; shift 2 ;;
48
48
--artifacts-destination )
49
49
ARTIFACTS_DESTINATION=" $2 " ; shift 2 ;;
96
96
fi
97
97
98
98
function checkPath() {
99
- if [ ! -v $1 ]
99
+ if [ -z $1 ]
100
100
then
101
101
return 1
102
102
fi
@@ -108,6 +108,7 @@ function checkPath() {
108
108
if [[ $path =~ " file:///" ]]
109
109
then
110
110
path=${path/ file: \/\/ / }
111
+ echo " CHECK $path "
111
112
if [ -f $path ]
112
113
then
113
114
eval " $1 =\" $path \" " # update original variable
@@ -125,13 +126,9 @@ function checkPath() {
125
126
eval " $1 =\" $path \" " # update original variable
126
127
return 0 # file found
127
128
else
128
- return 3 # file not found
129
+ return 2 # file not found
129
130
fi
130
131
fi
131
- if [ -f $path ]
132
- then
133
- return 0;
134
- fi
135
132
return -1 # incorrect path
136
133
}
137
134
@@ -142,43 +139,43 @@ function checkParams() {
142
139
exit 1
143
140
fi
144
141
if [ " $RUN_ON " = " aws" ]; then
145
- if [ ! -v AWS_KEY_PAIR ] || [ ! -v AWS_KEY_PATH ]
142
+ if [ -z ${ AWS_KEY_PAIR+x} ] || [ -z ${ AWS_KEY_PATH+x} ]
146
143
then
147
144
>&2 echo " ERROR: AWS keys not given."
148
145
exit 1
149
146
fi
150
147
151
- if [ ! -v AWS_EC2_TYPE ]
148
+ if [ -z ${ AWS_EC2_TYPE+x} ]
152
149
then
153
150
>&2 echo " ERROR: AWS EC2 Instance type not given."
154
151
exit 1
155
152
fi
156
153
fi
157
154
158
- if [ ! -v PG_VERSION ]
155
+ if [ -z ${ PG_VERSION+x} ]
159
156
then
160
157
>&2 echo " WARNING: Postgres version not given. Will use 9.6."
161
158
PG_VERSION=" 9.6"
162
159
fi
163
160
164
- if [ ! -v TMP_PATH ]
161
+ if [ -z ${ TMP_PATH+x} ]
165
162
then
166
163
TMP_PATH=" /var/tmp/nancy_run"
167
164
>&2 echo " WARNING: Temp path not given. Will use $TMP_PATH "
168
165
fi
169
166
# make tmp path if not found
170
167
[ ! -d $TMP_PATH ] && mkdir $TMP_PATH
171
168
172
- if [ ! -v S3_CFG_PATH ]
169
+ if [ -z ${ S3_CFG_PATH+x} ]
173
170
then
174
171
>&2 echo " WARNING: S3 config file path not given. Will use ~/.s3cfg"
175
172
S3_CFG_PATH=$( echo ~ ) " /.s3cfg"
176
173
fi
177
174
178
175
workloads_count=0
179
- [ -v WORKLOAD_BASIS_PATH ] && let workloads_count=$workloads_count +1
180
- [ -v WORKLOAD_FULL_PATH ] && let workloads_count=$workloads_count +1
181
- [ -v WORKLOAD_CUSTOM_SQL ] && let workloads_count=$workloads_count +1
176
+ [ ! -z ${ WORKLOAD_BASIS_PATH+x} ] && let workloads_count=$workloads_count +1
177
+ [ ! -z ${ WORKLOAD_FULL_PATH+x} ] && let workloads_count=$workloads_count +1
178
+ [ ! -z ${ WORKLOAD_CUSTOM_SQL+x} ] && let workloads_count=$workloads_count +1
182
179
183
180
# --workload-full-path or --workload-basis-path or --workload-custom-sql
184
181
if [ " $workloads_count " -eq " 0" ]
@@ -194,51 +191,115 @@ function checkParams() {
194
191
fi
195
192
196
193
# --db-prepared-snapshot or --db-dump-path
197
- if ([ ! -v DB_PREPARED_SNAPSHOT ] && [ ! -v DB_DUMP_PATH ])
194
+ if ([ -z ${ DB_PREPARED_SNAPSHOT+x} ] && [ -z ${ DB_DUMP_PATH+x} ])
198
195
then
199
196
>&2 echo " ERROR: Snapshot or dump not given."
200
197
exit 1;
201
198
fi
202
199
203
- if ([ -v DB_PREPARED_SNAPSHOT ] && [ -v DB_DUMP_PATH ])
200
+ if ([ ! -z ${ DB_PREPARED_SNAPSHOT+x} ] && [ ! -z ${ DB_DUMP_PATH+x} ])
204
201
then
205
202
>&2 echo " ERROR: Both snapshot and dump sources given."
206
203
exit 1
207
204
fi
208
205
209
- if (( [ ! - v TARGET_DDL_UNDO ] && [ - v TARGET_DDL_DO ]) || ([ ! - v TARGET_DDL_DO ] && [ - v TARGET_DDL_UNDO ]))
206
+ if [ ! -z ${DB_DUMP_PATH+x} ]
207
+ then
208
+ echo " DB_DUMP_PATH found"
209
+ else
210
+ echo " DB_DUMP_PATH NOT found"
211
+ fi
212
+
213
+ [ ! -z ${DB_DUMP_PATH+x} ] && ! checkPath DB_DUMP_PATH && >&2 echo " ERROR: file $DB_DUMP_PATH given by db_dump_path not found" && exit 1
214
+
215
+ if (( [ - z ${TARGET_DDL_UNDO+x} ] && [ ! - z ${TARGET_DDL_DO+x} ]) || ([ - z ${TARGET_DDL_DO+x} ] && [ ! - z ${TARGET_DDL_UNDO+x} ]))
210
216
then
211
217
>&2 echo " ERROR: DDL code must have do and undo part."
212
218
exit 1;
213
219
fi
214
220
215
- if [ ! -v ARTIFACTS_DESTINATION ]
221
+ if [ -z ${ ARTIFACTS_DESTINATION+x} ]
216
222
then
217
223
>&2 echo " WARNING: Artifacts destination not given. Will use ./"
218
224
ARTIFACTS_DESTINATION=" ."
219
225
fi
220
226
221
- if [ ! -v ARTIFACTS_FILENAME ]
227
+ if [ -z ${ ARTIFACTS_FILENAME+x} ]
222
228
then
223
229
>&2 echo " WARNING: Artifacts destination not given. Will use $DOCKER_MACHINE "
224
230
ARTIFACTS_FILENAME=$DOCKER_MACHINE
225
231
fi
226
232
227
- [ -v WORKLOAD_FULL_PATH ] && ! checkPath WORKLOAD_FULL_PATH && >&2 echo " WARNING : file $AFTER_DB_INIT_CODE not found"
233
+ [ ! -z ${ WORKLOAD_FULL_PATH+x} ] && ! checkPath WORKLOAD_FULL_PATH && >&2 echo " ERROR : file $WORKLOAD_FULL_PATH given by workload_full_path not found" && exit 1
228
234
229
- [ -v WORKLOAD_BASIS_PATH ] && ! checkPath WORKLOAD_BASIS_PATH && >&2 echo " WARNING: file $WORKLOAD_BASIS_PATH not found "
235
+ echo " WORKLOAD_FULL_PATH: $WORKLOAD_FULL_PATH "
230
236
231
- [ -v WORKLOAD_CUSTOM_SQL ] && ! checkPath WORKLOAD_CUSTOM_SQL && >&2 echo " WARNING: file $WORKLOAD_CUSTOM_SQL not found"
237
+ [ ! -z ${WORKLOAD_BASIS_PATH+x} ] && ! checkPath WORKLOAD_BASIS_PATH && >&2 echo " WARNING: file $WORKLOAD_BASIS_PATH given by workload_basis_path not found"
232
238
233
- [ -v DB_DUMP_PATH ] && ! checkPath DB_DUMP_PATH && >&2 echo " WARNING: file $DB_DUMP_PATH not found"
239
+ if [ ! -z ${WORKLOAD_CUSTOM_SQL+x} ]
240
+ then
241
+ checkPath WORKLOAD_CUSTOM_SQL
242
+ if [ " $? " -ne " 0" ]
243
+ then
244
+ >&2 echo " WARNING: Value given as workload-custom-sql: '$WORKLOAD_CUSTOM_SQL ' not found as file will use as content"
245
+ echo " $WORKLOAD_CUSTOM_SQL " > $TMP_PATH /workload_custom_sql_tmp.sql
246
+ WORKLOAD_CUSTOM_SQL=" $TMP_PATH /workload_custom_sql_tmp.sql"
247
+ else
248
+ [ " $DEBUG " -eq " 1" ] && echo " DEBUG: Value given as workload-custom-sql will use as filename"
249
+ fi
250
+ fi
234
251
235
- [ -v AFTER_DB_INIT_CODE ] && ! checkPath AFTER_DB_INIT_CODE && >&2 echo " WARNING: file $AFTER_DB_INIT_CODE not found"
252
+ if [ ! -z ${AFTER_DB_INIT_CODE+x} ]
253
+ then
254
+ checkPath AFTER_DB_INIT_CODE
255
+ if [ " $? " -ne " 0" ]
256
+ then
257
+ >&2 echo " WARNING: Value given as after_db_init_code: '$AFTER_DB_INIT_CODE ' not found as file will use as content"
258
+ echo " $AFTER_DB_INIT_CODE " > $TMP_PATH /after_db_init_code_tmp.sql
259
+ AFTER_DB_INIT_CODE=" $TMP_PATH /after_db_init_code_tmp.sql"
260
+ else
261
+ [ " $DEBUG " -eq " 1" ] && echo " DEBUG: Value given as after_db_init_code will use as filename"
262
+ fi
263
+ fi
236
264
237
- [ -v TARGET_DDL_DO ] && ! checkPath TARGET_DDL_DO && >&2 echo " WARNING: file $TARGET_DDL_DO not found"
265
+ if [ ! -z ${TARGET_DDL_DO+x} ]
266
+ then
267
+ checkPath TARGET_DDL_DO
268
+ if [ " $? " -ne " 0" ]
269
+ then
270
+ >&2 echo " WARNING: Value given as target_ddl_do: '$TARGET_DDL_DO ' not found as file will use as content"
271
+ echo " $TARGET_DDL_DO " > $TMP_PATH /target_ddl_do_tmp.sql
272
+ TARGET_DDL_DO=" $TMP_PATH /target_ddl_do_tmp.sql"
273
+ else
274
+ [ " $DEBUG " -eq " 1" ] && echo " DEBUG: Value given as target_ddl_do will use as filename"
275
+ fi
276
+ fi
238
277
239
- [ -v TARGET_DDL_UNDO ] && ! checkPath TARGET_DDL_UNDO && >&2 echo " WARNING: file $TARGET_DDL_UNDO not found"
278
+ if [ ! -z ${TARGET_DDL_UNDO} ]
279
+ then
280
+ checkPath TARGET_DDL_UNDO
281
+ if [ " $? " -ne " 0" ]
282
+ then
283
+ >&2 echo " WARNING: Value given as target_ddl_undo: '$TARGET_DDL_UNDO ' not found as file will use as content"
284
+ echo " $TARGET_DDL_UNDO " > $TMP_PATH /target_ddl_undo_tmp.sql
285
+ TARGET_DDL_UNDO=" $TMP_PATH /target_ddl_undo_tmp.sql"
286
+ else
287
+ [ " $DEBUG " -eq " 1" ] && echo " DEBUG: Value given as target_ddl_undo will use as filename"
288
+ fi
289
+ fi
240
290
241
- [ -v TARGET_CONFIG ] && ! checkPath TARGET_CONFIG && >&2 echo " WARNING: file $TARGET_CONFIG not found"
291
+ if [ ! -z ${TARGET_CONFIG+x} ]
292
+ then
293
+ checkPath TARGET_CONFIG
294
+ if [ " $? " -ne " 0" ]
295
+ then
296
+ >&2 echo " WARNING: Value given as target_config: '$TARGET_CONFIG ' not found as file will use as content"
297
+ echo " $TARGET_CONFIG " > $TMP_PATH /target_config_tmp.conf
298
+ TARGET_CONFIG=" $TMP_PATH /target_config_tmp.conf"
299
+ else
300
+ [ " $DEBUG " -eq " 1" ] && echo " DEBUG: Value given as target_config will use as filename"
301
+ fi
302
+ fi
242
303
}
243
304
244
305
checkParams;
@@ -258,7 +319,6 @@ function waitEC2Ready() {
258
319
(( STOP== 1 )) && return 0
259
320
if [ $checkPrice -eq 1 ]
260
321
then
261
- # status=$(aws ec2 describe-spot-instance-requests --filters="Name=launch.instance-type,Values=$AWS_EC2_TYPE" | jq '.SpotInstanceRequests[] | .Status.Code' | tail -n 1 )
262
322
status=$( aws ec2 describe-spot-instance-requests --filters=" Name=launch.instance-type,Values=$AWS_EC2_TYPE " | jq ' .SpotInstanceRequests | sort_by(.CreateTime) | .[] | .Status.Code' | tail -n 1)
263
323
if [ " $status " == " \" price-too-low\" " ]
264
324
then
@@ -337,11 +397,13 @@ else
337
397
fi
338
398
339
399
function cleanup {
340
- echo " Remove temp files..."
341
- rm -f " $TMP_PATH /conf_$DOCKER_MACHINE .tmp"
342
- rm -f " $TMP_PATH /ddl_do_$DOCKER_MACHINE .sql"
343
- rm -f " $TMP_PATH /ddl_undo_$DOCKER_MACHINE .sql"
344
- rm -f " $TMP_PATH /queries_custom_$DOCKER_MACHINE .sql"
400
+ echo " Remove temp files..." # if exists
401
+ rm -f " $TMP_PATH /after_db_init_code_tmp.sql"
402
+ rm -f " $TMP_PATH /workload_custom_sql_tmp.sql"
403
+ rm -f " $TMP_PATH /target_ddl_do_tmp.sql"
404
+ rm -f " $TMP_PATH /target_ddl_undo_tmp.sql"
405
+ rm -f " $TMP_PATH /target_config_tmp.conf"
406
+
345
407
if [ " $RUN_ON " = " localhost" ]; then
346
408
rm -rf " $TMP_PATH /pg_nancy_home_${CURRENT_TS} "
347
409
echo " Remove docker container"
@@ -375,22 +437,23 @@ function copyFile() {
375
437
fi
376
438
}
377
439
378
- [ -v S3_CFG_PATH ] && copyFile $S3_CFG_PATH && docker_exec cp /machine_home/.s3cfg /root/.s3cfg
440
+ [ ! -z ${ S3_CFG_PATH+x} ] && copyFile $S3_CFG_PATH && docker_exec cp /machine_home/.s3cfg /root/.s3cfg
379
441
380
- [ -v DB_DUMP_PATH ] && copyFile $DB_DUMP_PATH
381
- [ -v TARGET_CONFIG ] && copyFile $TARGET_CONFIG
382
- [ -v TARGET_DDL_DO ] && copyFile $TARGET_DDL_DO
383
- [ -v TARGET_DDL_UNDO ] && copyFile $TARGET_DDL_UNDO
384
- [ -v WORKLOAD_CUSTOM_SQL ] && copyFile $WORKLOAD_CUSTOM_SQL
385
- [ -v WORKLOAD_FULL_PATH ] && copyFile $WORKLOAD_FULL_PATH
442
+ [ ! -z ${ DB_DUMP_PATH+x} ] && copyFile $DB_DUMP_PATH
443
+ [ ! -z ${ TARGET_CONFIG+x} ] && copyFile $TARGET_CONFIG
444
+ [ ! -z ${ TARGET_DDL_DO+x} ] && copyFile $TARGET_DDL_DO
445
+ [ ! -z ${ TARGET_DDL_UNDO+x} ] && copyFile $TARGET_DDL_UNDO
446
+ [ ! -z ${ WORKLOAD_CUSTOM_SQL+x} ] && copyFile $WORKLOAD_CUSTOM_SQL
447
+ [ ! -z ${ WORKLOAD_FULL_PATH+x} ] && copyFile $WORKLOAD_FULL_PATH
386
448
387
449
# # Apply machine features
388
450
# Dump
389
451
sleep 1 # wait for postgres up&running
390
452
DB_DUMP_FILENAME=$( basename $DB_DUMP_PATH )
391
453
docker_exec bash -c " bzcat /machine_home/$DB_DUMP_FILENAME | psql --set ON_ERROR_STOP=on -U postgres test"
392
454
# After init database sql code apply
393
- if ([ -v AFTER_DB_INIT_CODE ] && [ " $AFTER_DB_INIT_CODE " != " " ])
455
+ echo " Apply sql code after db init"
456
+ if ([ ! -z ${AFTER_DB_INIT_CODE+x} ] && [ " $AFTER_DB_INIT_CODE " != " " ])
394
457
then
395
458
AFTER_DB_INIT_CODE_FILENAME=$( basename $AFTER_DB_INIT_CODE )
396
459
if [[ $AFTER_DB_INIT_CODE =~ " s3://" ]]; then
@@ -402,13 +465,13 @@ then
402
465
fi
403
466
# Apply DDL code
404
467
echo " Apply DDL SQL code"
405
- if ([ -v TARGET_DDL_DO ] && [ " $TARGET_DDL_DO " != " " ]); then
468
+ if ([ ! -z ${ TARGET_DDL_DO+x} ] && [ " $TARGET_DDL_DO " != " " ]); then
406
469
TARGET_DDL_DO_FILENAME=$( basename $TARGET_DDL_DO )
407
470
docker_exec bash -c " psql -U postgres test -E -f /machine_home/$TARGET_DDL_DO_FILENAME "
408
471
fi
409
472
# Apply postgres configuration
410
- echo " Apply postgres conf from /machine_home/conf_ $DOCKER_MACHINE .tmp "
411
- if ([ -v TARGET_CONFIG ] && [ " $TARGET_CONFIG " != " " ]); then
473
+ echo " Apply postgres conf"
474
+ if ([ ! -z ${ TARGET_CONFIG+x} ] && [ " $TARGET_CONFIG " != " " ]); then
412
475
TARGET_CONFIG_FILENAME=$( basename $TARGET_CONFIG )
413
476
docker_exec bash -c " cat /machine_home/$TARGET_CONFIG_FILENAME >> /etc/postgresql/$PG_VERSION /main/postgresql.conf"
414
477
docker_exec bash -c " sudo /etc/init.d/postgresql restart"
@@ -419,13 +482,13 @@ docker_exec vacuumdb -U postgres test -j $(cat /proc/cpuinfo | grep processor |
419
482
docker_exec bash -c " echo '' > /var/log/postgresql/postgresql-$PG_VERSION -main.log"
420
483
# Execute workload
421
484
echo " Execute workload..."
422
- if [ -v WORKLOAD_FULL_PATH ] && [ " $WORKLOAD_FULL_PATH " != ' ' ]; then
485
+ if [ ! -z ${ WORKLOAD_FULL_PATH+x} ] && [ " $WORKLOAD_FULL_PATH " != ' ' ]; then
423
486
echo " Execute pgreplay queries..."
424
487
docker_exec psql -U postgres test -c ' create role testuser superuser login;'
425
488
WORKLOAD_FILE_NAME=$( basename $WORKLOAD_FULL_PATH )
426
- docker_exec bash -c " pgreplay -r -j . /$WORKLOAD_FILE_NAME "
489
+ docker_exec bash -c " pgreplay -r -j /machine_home /$WORKLOAD_FILE_NAME "
427
490
else
428
- if ([ -v WORKLOAD_CUSTOM_SQL ] && [ " $WORKLOAD_CUSTOM_SQL " != " " ]); then
491
+ if ([ ! -z ${ WORKLOAD_CUSTOM_SQL+x} ] && [ " $WORKLOAD_CUSTOM_SQL " != " " ]); then
429
492
WORKLOAD_CUSTOM_FILENAME=$( basename $WORKLOAD_CUSTOM_SQL )
430
493
echo " Execute custom sql queries..."
431
494
docker_exec bash -c " psql -U postgres test -E -f /machine_home/$WORKLOAD_CUSTOM_FILENAME "
435
498
# # Get statistics
436
499
echo " Prepare JSON log..."
437
500
docker_exec bash -c " /root/pgbadger/pgbadger -j $( cat /proc/cpuinfo | grep processor | wc -l) --prefix '%t [%p]: [%l-1] db=%d,user=%u (%a,%h)' /var/log/postgresql/* -f stderr -o /machine_home/$ARTIFACTS_FILENAME .json"
438
- echo " Upload JSON log..."
439
501
502
+ echo " Save JSON log..."
440
503
if [[ $ARTIFACTS_DESTINATION =~ " s3://" ]]; then
441
504
docker_exec s3cmd put /machine_home/$ARTIFACTS_FILENAME .json $ARTIFACTS_DESTINATION /
442
505
else
506
+ logpath=$( docker_exec bash -c " psql -XtU postgres \
507
+ -c \" select string_agg(setting, '/' order by name) from pg_settings where name in ('log_directory', 'log_filename');\" \
508
+ | grep / | sed -e 's/^[ \t]*//'" )
509
+ docker_exec bash -c " gzip -c $logpath > /machine_home/$ARTIFACTS_FILENAME .log.gz"
443
510
if [ " $RUN_ON " = " localhost" ]; then
444
511
cp " $TMP_PATH /pg_nancy_home_${CURRENT_TS} /" $ARTIFACTS_FILENAME .json $ARTIFACTS_DESTINATION /
512
+ cp " $TMP_PATH /pg_nancy_home_${CURRENT_TS} /" $ARTIFACTS_FILENAME .log.gz $ARTIFACTS_DESTINATION /
445
513
elif [ " $RUN_ON " = " aws" ]; then
446
- docker-machine scp /machine_home/$ARTIFACTS_FILENAME .json $DOCKER_MACHINE :/home/ubuntu
514
+ docker-machine scp $DOCKER_MACHINE :/home/ubuntu/$ARTIFACTS_FILENAME .json $ARTIFACTS_DESTINATION /
515
+ docker-machine scp $DOCKER_MACHINE :/home/ubuntu/$ARTIFACTS_FILENAME .log.gz $ARTIFACTS_DESTINATION /
447
516
else
448
517
>&2 echo " ASSERT: must not reach this point"
449
518
exit 1
450
519
fi
451
520
fi
452
521
453
- echo " Apply DDL undo SQL code from /machine_home/ddl_undo_ $DOCKER_MACHINE .sql "
454
- if ([ -v TARGET_DDL_UNDO ] && [ " $TARGET_DDL_UNDO " != " " ]); then
522
+ echo " Apply DDL undo SQL code"
523
+ if ([ ! -z ${ TARGET_DDL_UNDO+x} ] && [ " $TARGET_DDL_UNDO " != " " ]); then
455
524
TARGET_DDL_UNDO_FILENAME=$( basename $TARGET_DDL_UNDO )
456
525
docker_exec bash -c " psql -U postgres test -E -f /machine_home/$TARGET_DDL_UNDO_FILENAME "
457
526
fi
0 commit comments