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

Commit d9779dd

Browse files
authored
Merge branch 'master' into dmius-ebs-vol
2 parents 1061a30 + 2d828b1 commit d9779dd

File tree

3 files changed

+81
-46
lines changed

3 files changed

+81
-46
lines changed

nancy

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,15 @@ esac
4343

4444
while [ -n "$1" ]
4545
do
46+
if [ ${1%"${1#??}"} = '--' ]; then
4647
cmd="$cmd $1"
47-
shift
48+
else
49+
cmd="$cmd \"$1\""
50+
fi
51+
shift
4852
done
4953

5054
echo "CMD: $cmd"
5155

52-
${cmd}
56+
eval $cmd
5357

nancy_run.sh

Lines changed: 73 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -384,8 +384,8 @@ function checkParams() {
384384
checkPath PG_CONFIG
385385
if [ "$?" -ne "0" ]; then
386386
#>&2 echo "WARNING: Value given as pg_config: '$PG_CONFIG' not found as file will use as content"
387-
echo "$PG_CONFIG" > $TMP_PATH/pg_congif_tmp.sql
388-
WORKLOAD_CUSTOM_SQL="$TMP_PATH/pg_congif_tmp.sql"
387+
echo "$PG_CONFIG" > $TMP_PATH/pg_config_tmp.sql
388+
WORKLOAD_CUSTOM_SQL="$TMP_PATH/pg_config_tmp.sql"
389389
fi
390390
fi
391391

@@ -529,18 +529,65 @@ function waitEC2Ready() {
529529
done
530530
}
531531

532+
# Params:
533+
# 1) machine name
534+
# 2) AWS EC2 instance type
535+
# 3) price
536+
# 4) duration (minutes)
537+
# 5) key pair name
538+
# 6) key path
532539
function createDockerMachine() {
533540
echo "Attempt to create a docker machine..."
534541
docker-machine create --driver=amazonec2 \
535542
--amazonec2-request-spot-instance \
536-
--amazonec2-keypair-name="$AWS_KEY_PAIR" \
537-
--amazonec2-ssh-keypath="$AWS_KEY_PATH" \
538-
--amazonec2-block-duration-minutes=60 \
539-
--amazonec2-instance-type=$AWS_EC2_TYPE \
540-
--amazonec2-spot-price=$EC2_PRICE \
541-
$DOCKER_MACHINE &
543+
--amazonec2-keypair-name="$5" \
544+
--amazonec2-ssh-keypath="$6" \
545+
--amazonec2-block-duration-minutes=$4 \
546+
--amazonec2-instance-type=$2 \
547+
--amazonec2-spot-price=$3 \
548+
$1 2> >(grep -v "failed waiting for successful resource state" >&2) &
542549
}
543550

551+
function destroyDockerMachine() {
552+
# If spot request wasn't fulfilled, there is no associated instance,
553+
# so "docker-machine rm" will show an error, which is safe to ignore.
554+
# We better filter it out to avoid any confusions.
555+
# What is used here is called "process substitution",
556+
# see https://www.gnu.org/software/bash/manual/bash.html#Process-Substitution
557+
# The same trick is used in createDockerMachine to filter out errors
558+
# when we have "price-too-low" attempts, such errors come in few minutes
559+
# after an attempt and are generally unexpected by user.
560+
cmdout=$(docker-machine rm --force $1 2> >(grep -v "unknown instance" >&2) )
561+
echo "Termination requested for machine '$1', current status: $cmdout"
562+
}
563+
564+
function cleanupAndExit {
565+
echo "Remove temp files..." # if exists
566+
rm -f "$TMP_PATH/after_db_init_code_tmp.sql"
567+
rm -f "$TMP_PATH/workload_custom_sql_tmp.sql"
568+
rm -f "$TMP_PATH/target_ddl_do_tmp.sql"
569+
rm -f "$TMP_PATH/target_ddl_undo_tmp.sql"
570+
rm -f "$TMP_PATH/target_config_tmp.conf"
571+
rm -f "$TMP_PATH/pg_config_tmp.conf"
572+
if [ "$RUN_ON" = "localhost" ]; then
573+
rm -rf "$TMP_PATH/nancy_${containerHash}"
574+
echo "Remove docker container"
575+
docker container rm -f $containerHash
576+
elif [ "$RUN_ON" = "aws" ]; then
577+
destroyDockerMachine $DOCKER_MACHINE
578+
if [ ! -z ${VOLUME_ID+x} ]; then
579+
echo "Wait and delete volume $VOLUME_ID"
580+
sleep 60 # wait to machine removed
581+
delvolout=$(aws ec2 delete-volume --volume-id $VOLUME_ID)
582+
echo "Volume $VOLUME_ID deleted"
583+
fi
584+
else
585+
>&2 echo "ASSERT: must not reach this point"
586+
exit 1
587+
fi
588+
}
589+
trap cleanupAndExit EXIT
590+
544591
if [[ "$RUN_ON" = "localhost" ]]; then
545592
if [ -z ${CONTAINER_ID+x} ]; then
546593
containerHash=$(docker run --name="pg_nancy_${CURRENT_TS}" \
@@ -569,11 +616,22 @@ elif [[ "$RUN_ON" = "aws" ]]; then
569616
echo "Increased price: $price"
570617
EC2_PRICE=$price
571618

572-
createDockerMachine;
619+
createDockerMachine $DOCKER_MACHINE $AWS_EC2_TYPE $EC2_PRICE \
620+
60 $AWS_KEY_PAIR $AWS_KEY_PATH;
573621
status=$(waitEC2Ready "docker-machine create" "$DOCKER_MACHINE" 1)
574622
if [ "$status" == "price-too-low" ]
575623
then
576-
echo "Price $price is too low for $AWS_EC2_TYPE instance. Try detect actual."
624+
echo "Price $price is too low for $AWS_EC2_TYPE instance. Getting the up-to-date value from the error message..."
625+
626+
#destroyDockerMachine $DOCKER_MACHINE
627+
# "docker-machine rm" doesn't work for "price-too-low" spot requests,
628+
# so we need to clean up them via aws cli interface directly
629+
aws ec2 describe-spot-instance-requests \
630+
--filters 'Name=status-code,Values=price-too-low' \
631+
| grep SpotInstanceRequestId | awk '{gsub(/[,"]/, "", $2); print $2}' \
632+
| xargs --no-run-if-empty aws ec2 cancel-spot-instance-requests \
633+
--spot-instance-request-ids
634+
577635
corrrectPriceForLastFailedRequest=$( \
578636
aws ec2 describe-spot-instance-requests \
579637
--filters="Name=launch.instance-type,Values=$AWS_EC2_TYPE" \
@@ -588,7 +646,8 @@ elif [[ "$RUN_ON" = "aws" ]]; then
588646
DOCKER_MACHINE="${DOCKER_MACHINE//_/-}"
589647
#try start docker machine name with new price
590648
echo "Attempt to create a new docker machine: $DOCKER_MACHINE with price: $EC2_PRICE."
591-
createDockerMachine;
649+
createDockerMachine $DOCKER_MACHINE $AWS_EC2_TYPE $EC2_PRICE \
650+
60 $AWS_KEY_PAIR $AWS_KEY_PATH;
592651
waitEC2Ready "docker-machine create" "$DOCKER_MACHINE" 0;
593652
else
594653
>&2 echo "ERROR: Cannot determine actual price for the instance $AWS_EC2_TYPE."
@@ -657,35 +716,6 @@ else
657716
exit 1
658717
fi
659718

660-
function cleanup {
661-
echo "Remove temp files..." # if exists
662-
rm -f "$TMP_PATH/after_db_init_code_tmp.sql"
663-
rm -f "$TMP_PATH/workload_custom_sql_tmp.sql"
664-
rm -f "$TMP_PATH/target_ddl_do_tmp.sql"
665-
rm -f "$TMP_PATH/target_ddl_undo_tmp.sql"
666-
rm -f "$TMP_PATH/target_config_tmp.conf"
667-
rm -f "$TMP_PATH/pg_config_tmp.conf"
668-
if [ "$RUN_ON" = "localhost" ]; then
669-
rm -rf "$TMP_PATH/nancy_${containerHash}"
670-
echo "Remove docker container"
671-
docker container rm -f $containerHash
672-
elif [ "$RUN_ON" = "aws" ]; then
673-
cmdout=$(docker-machine rm --force $DOCKER_MACHINE)
674-
echo "Finished working with machine $DOCKER_MACHINE, termination requested, current status: $cmdout"
675-
if [ ! -z ${VOLUME_ID+x} ]; then
676-
echo "Wait and delete volume $VOLUME_ID"
677-
sleep 60 # wait to machine removed
678-
delvolout=$(aws ec2 delete-volume --volume-id $VOLUME_ID)
679-
echo "Volume $VOLUME_ID deleted"
680-
fi
681-
else
682-
>&2 echo "ASSERT: must not reach this point"
683-
exit 1
684-
fi
685-
}
686-
trap cleanup EXIT
687-
688-
689719
alias docker_exec='docker $dockerConfig exec -i ${containerHash} '
690720

691721
MACHINE_HOME="/machine_home/nancy_${containerHash}"
@@ -825,9 +855,10 @@ echo -e "Report: $ARTIFACTS_DESTINATION/$ARTIFACTS_FILENAME.json"
825855
echo -e "Query log: $ARTIFACTS_DESTINATION/$ARTIFACTS_FILENAME.log.gz"
826856
echo -e "-------------------------------------------"
827857
echo -e "Summary:"
828-
echo -e " Queries number:\t\t" $(cat $ARTIFACTS_DESTINATION/$ARTIFACTS_FILENAME.json | jq '.overall_stat.queries_number')
829858
echo -e " Queries duration:\t\t" $(cat $ARTIFACTS_DESTINATION/$ARTIFACTS_FILENAME.json | jq '.overall_stat.queries_duration') " ms"
830-
echo -e " Errors number:\t\t" $(cat $ARTIFACTS_DESTINATION/$ARTIFACTS_FILENAME.json | jq '.overall_stat.errors_number')
859+
echo -e " Queries count:\t\t" $(cat $ARTIFACTS_DESTINATION/$ARTIFACTS_FILENAME.json | jq '.overall_stat.queries_number')
860+
echo -e " Normalized queries count:\t" $(cat $ARTIFACTS_DESTINATION/$ARTIFACTS_FILENAME.json | jq '.normalyzed_info| length')
861+
echo -e " Errors count:\t\t\t" $(cat $ARTIFACTS_DESTINATION/$ARTIFACTS_FILENAME.json | jq '.overall_stat.errors_number')
831862
echo -e "-------------------------------------------"
832863

833864
sleep $DEBUG_TIMEOUT

tests/nancy_run_localhost_simple_dump_with_index.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ output=$(
1212
$nancyRun --workload-custom-sql "file://$srcDir/custom.sql" \
1313
--tmp-path ${srcDir}/tmp \
1414
--db-dump-path "file://$srcDir/test.dump.bz2" \
15-
--target-ddl-do "file://$srcDir/ddl_create_index.sql" \
16-
--target-ddl-undo "file://$srcDir/ddl_drop_index.sql" 2>&1
15+
--target-ddl-do "create index i_speedup on t1 using btree(val);" \
16+
--target-ddl-undo "drop index i_speedup;" 2>&1
1717
)
1818

1919
if [[ $output =~ "Queries duration:" ]]; then

0 commit comments

Comments
 (0)