Skip to content
This repository was archived by the owner on Aug 16, 2021. It is now read-only.

Commit 830407a

Browse files
dmiusDmitry
authored andcommitted
ebs-disk-size and before-init-sql-code options added
1 parent a4eeca1 commit 830407a

File tree

4 files changed

+97
-8
lines changed

4 files changed

+97
-8
lines changed

nancy_run.sh

Lines changed: 51 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
DEBUG=0
44
CURRENT_TS=$(date +%Y%m%d_%H%M%S%N_%Z)
5-
DOCKER_MACHINE="${DOCKER_MACHINE:-nancy-$CURRENT_TS}"
5+
DOCKER_MACHINE="nancy-$CURRENT_TS"
66
DOCKER_MACHINE="${DOCKER_MACHINE//_/-}"
77
DEBUG_TIMEOUT=0
88
EBS_SIZE_MULTIPLIER=15
@@ -198,6 +198,9 @@ while true; do
198198
--after-db-init-code )
199199
#s3 url|filename|content
200200
AFTER_DB_INIT_CODE="$2"; shift 2 ;;
201+
--before-db-init-code )
202+
#s3 url|filename|content
203+
BEFORE_DB_INIT_CODE="$2"; shift 2 ;;
201204
--workload-full-path )
202205
#s3 url
203206
WORKLOAD_FULL_PATH="$2"; shift 2 ;;
@@ -236,6 +239,8 @@ while true; do
236239
TMP_PATH="$2"; shift 2 ;;
237240
--debug-timeout )
238241
DEBUG_TIMEOUT="$2"; shift 2 ;;
242+
--ebs-volume-size )
243+
EBS_VOLUME_SIZE="$2"; shift 2 ;;
239244
-- )
240245
>&2 echo "ERROR: Invalid option '$1'"
241246
exit 1;
@@ -271,6 +276,8 @@ then
271276
echo "s3-cfg-path: $S3_CFG_PATH"
272277
echo "tmp-path: $TMP_PATH"
273278
echo "after-db-init-code: $AFTER_DB_INIT_CODE"
279+
echo "before-db-init-code: $BEFORE_DB_INIT_CODE"
280+
echo "ebs-volume-size: $EBS_VOLUME_SIZE"
274281
fi
275282

276283
function checkPath() {
@@ -462,6 +469,17 @@ function checkParams() {
462469
fi
463470
fi
464471

472+
if [ ! -z ${BEFORE_DB_INIT_CODE+x} ]; then
473+
checkPath BEFORE_DB_INIT_CODE
474+
if [ "$?" -ne "0" ]; then
475+
#>&2 echo "WARNING: Value given as after_db_init_code: '$AFTER_DB_INIT_CODE' not found as file will use as content"
476+
echo "$BEFORE_DB_INIT_CODE" > $TMP_PATH/before_db_init_code_tmp.sql
477+
BEFORE_DB_INIT_CODE="$TMP_PATH/before_db_init_code_tmp.sql"
478+
else
479+
[ "$DEBUG" -eq "1" ] && echo "DEBUG: Value given as before_db_init_code will use as filename"
480+
fi
481+
fi
482+
465483
if [ ! -z ${TARGET_DDL_DO+x} ]; then
466484
checkPath TARGET_DDL_DO
467485
if [ "$?" -ne "0" ]; then
@@ -494,12 +512,28 @@ function checkParams() {
494512
[ "$DEBUG" -eq "1" ] && echo "DEBUG: Value given as target_config will use as filename"
495513
fi
496514
fi
515+
516+
if [ ! -z ${EBS_VOLUME_SIZE+x} ]; then
517+
if [ "$RUN_ON" == "localhost" ] || [ ${AWS_EC2_TYPE:0:2} == 'i3' ]; then
518+
>&2 echo "WARNING: ebs-volume-size is not required for aws i3 aws instances and local execution."
519+
fi;
520+
re='^[0-9]+$'
521+
if ! [[ $EBS_VOLUME_SIZE =~ $re ]] ; then
522+
>&2 echo "ERROR: ebs-volume-size must be numeric integer value."
523+
exit 1;
524+
fi
525+
else
526+
if [ ! ${AWS_EC2_TYPE:0:2} == 'i3' ]; then
527+
>&2 echo "WARNING: ebs-volume-size is not given, will be calculate on base of dump size."
528+
fi
529+
fi
497530
}
498531

499532
checkParams;
500533

501534
# Determine dump file size
502-
if [ ! -z ${DB_DUMP_PATH+x} ]; then
535+
if ([ "$RUN_ON" == "aws" ] && [ ! ${AWS_EC2_TYPE:0:2} == "i3" ] && [ -z ${EBS_VOLUME_SIZE+x} ] && [ ! -z ${DB_DUMP_PATH+x} ]); then
536+
echo "Calculate EBS volume size."
503537
dumpFileSize=0
504538
if [[ $DB_DUMP_PATH =~ "s3://" ]]; then
505539
dumpFileSize=$(s3cmd info $DB_DUMP_PATH | grep "File size:" )
@@ -510,16 +544,17 @@ if [ ! -z ${DB_DUMP_PATH+x} ]; then
510544
else
511545
dumpFileSize=$(stat -c%s "$DB_DUMP_PATH")
512546
fi
513-
[ $DEBUG -eq 1 ] && echo "Dump filesize: $dumpFileSize bytes"
514547
KB=1024
515548
let minSize=300*$KB*$KB*$KB
516549
ebsSize=$minSize # 300 GB
517550
if [ "$dumpFileSize" -gt "$minSize" ]; then
518551
let ebsSize=$dumpFileSize
519552
let ebsSize=$ebsSize*$EBS_SIZE_MULTIPLIER
520553
ebsSize=$(numfmt --to-unit=G $ebsSize)
521-
EBS_SIZE=$ebsSize
522-
[ $DEBUG -eq 1 ] && echo "EBS Size: $EBS_SIZE Gb"
554+
EBS_VOLUME_SIZE=$ebsSize
555+
[ $DEBUG -eq 1 ] && echo "EBS volume size: $EBS_VOLUME_SIZE Gb"
556+
else
557+
echo "EBS volume is not require."
523558
fi
524559
fi
525560

@@ -589,6 +624,7 @@ function cleanupAndExit {
589624
echo "Remove temp files..." # if exists
590625
docker $dockerConfig exec -i ${containerHash} sh -c "sudo rm -rf $MACHINE_HOME"
591626
rm -f "$TMP_PATH/after_db_init_code_tmp.sql"
627+
rm -f "$TMP_PATH/before_db_init_code_tmp.sql"
592628
rm -f "$TMP_PATH/workload_custom_sql_tmp.sql"
593629
rm -f "$TMP_PATH/target_ddl_do_tmp.sql"
594630
rm -f "$TMP_PATH/target_ddl_undo_tmp.sql"
@@ -711,10 +747,10 @@ elif [[ "$RUN_ON" = "aws" ]]; then
711747
else
712748
echo "Attempt use external disk"
713749
# Create new volume and attach them for non i3 instances if needed
714-
if [ ! -z ${EBS_SIZE+x} ]; then
750+
if [ ! -z ${EBS_VOLUME_SIZE+x} ]; then
715751
echo "Create and attach EBS volume"
716-
[ $DEBUG -eq 1 ] && echo "Create volume with size: $EBS_SIZE Gb"
717-
VOLUME_ID=$(aws ec2 create-volume --size $EBS_SIZE --region us-east-1 --availability-zone us-east-1a --volume-type gp2 | jq -r .VolumeId)
752+
[ $DEBUG -eq 1 ] && echo "Create volume with size: $EBS_VOLUME_SIZE Gb"
753+
VOLUME_ID=$(aws ec2 create-volume --size $EBS_VOLUME_SIZE --region us-east-1 --availability-zone us-east-1a --volume-type gp2 | jq -r .VolumeId)
718754
INSTANCE_ID=$(docker-machine ssh $DOCKER_MACHINE curl -s http://169.254.169.254/latest/meta-data/instance-id)
719755
sleep 10 # wait to volume will ready
720756
attachResult=$(aws ec2 attach-volume --device /dev/xvdf --volume-id $VOLUME_ID --instance-id $INSTANCE_ID --region us-east-1)
@@ -787,6 +823,13 @@ function copyFile() {
787823
# Dump
788824
sleep 2 # wait for postgres up&running
789825

826+
echo "Apply sql code before db init"
827+
if ([ ! -z ${BEFORE_DB_INIT_CODE+x} ] && [ "$BEFORE_DB_INIT_CODE" != "" ])
828+
then
829+
BEFORE_DB_INIT_CODE_FILENAME=$(basename $BEFORE_DB_INIT_CODE)
830+
copyFile $BEFORE_DB_INIT_CODE
831+
docker_exec bash -c "psql --set ON_ERROR_STOP=on -U postgres test -b -f $MACHINE_HOME/$BEFORE_DB_INIT_CODE_FILENAME"
832+
fi
790833
echo "Restore database dump"
791834
case "$DB_DUMP_EXT" in
792835
sql)

tests/nancy_run_before_init_code.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/bin/bash
2+
3+
output=$(${BASH_SOURCE%/*}/../nancy run \
4+
--before-db-init-code "select abs from beforeinittable;" \
5+
--workload-custom-sql "file://$srcDir/custom.sql" \
6+
--db-dump-path "file://$srcDir/test.dump.bz2" \
7+
--tmp-path $srcDir/tmp \
8+
2>&1)
9+
10+
if [[ $output =~ "ERROR: relation \"beforeinittable\" does not exist" ]]; then
11+
echo -e "\e[36mOK\e[39m"
12+
else
13+
>&2 echo -e "\e[31mFAILED\e[39m"
14+
>&2 echo -e "Output: $output"
15+
exit 1
16+
fi

tests/nancy_run_ebs_disk_size.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/bin/bash
2+
3+
output=$(${BASH_SOURCE%/*}/../nancy run \
4+
--debug \
5+
--ebs-volume-size 37 \
6+
2>&1)
7+
8+
if [[ $output =~ "ebs-volume-size: 37" ]]; then
9+
echo -e "\e[36mOK\e[39m"
10+
else
11+
>&2 echo -e "\e[31mFAILED\e[39m"
12+
>&2 echo -e "Output: $output"
13+
exit 1
14+
fi
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/bin/bash
2+
3+
output=$(${BASH_SOURCE%/*}/../nancy run \
4+
--ebs-volume-size sa \
5+
--workload-custom-sql "file://$srcDir/custom.sql" \
6+
--db-dump-path "file://$srcDir/test.dump.bz2" \
7+
--tmp-path $srcDir/tmp \
8+
2>&1)
9+
10+
if [[ $output =~ "WARNING: ebs-volume-size is not required for aws i3 aws instances and local execution." ]]; then
11+
echo -e "\e[36mOK\e[39m"
12+
else
13+
>&2 echo -e "\e[31mFAILED\e[39m"
14+
>&2 echo -e "Output: $output"
15+
exit 1
16+
fi

0 commit comments

Comments
 (0)