Introduce main function and use local variables to avoid global state.
@@ -263,12 +263,13 @@ print_delta_seconds()
contextString=$2
endSeconds=`date +%s`
deltaSeconds=`expr $endSeconds - $startSeconds`
+
echo "$contextString: $deltaSeconds"
}
-# Main
-temp_root=`pwd`/tmp_check
-base_dir=`pwd`
+main() {
+ local temp_root=`pwd`/tmp_check
+ local base_dir=`pwd`
while getopts ":o:b:sCkKmrp" opt; do
case ${opt} in
@@ -393,7 +394,7 @@ MASTER_DATA_DIRECTORY=""; unset MASTER_DATA_DIRECTORY
PGPORT=""; unset PGPORT
PGOPTIONS=""; unset PGOPTIONS
-epoch_for_perf_start=`date +%s`
+ local epoch_for_perf_start=`date +%s`
# Start by upgrading the master
upgrade_qd "${temp_root}/upgrade/qd" "${OLD_DATADIR}/qddir/demoDataDir-1/" "${NEW_DATADIR}/qddir/demoDataDir-1/"
@@ -429,7 +430,7 @@ do
rm -rf "${NEW_DATADIR}/dbfast$i/demoDataDir$j/gpperfmon"
# Upgrade the segment data files without dump/restore of the schema
- epoch_for_perf_QEstart=`date +%s`
+ local epoch_for_perf_QEstart=`date +%s`
upgrade_segment "${temp_root}/upgrade/dbfast$i" "${OLD_DATADIR}/dbfast$i/demoDataDir$j/" "${NEW_DATADIR}/dbfast$i/demoDataDir$j/"
print_delta_seconds $epoch_for_perf_QEstart 'number_of_seconds_for_upgrade_qe'
@@ -444,7 +445,9 @@ print_delta_seconds $epoch_for_perf_start 'number_of_seconds_for_upgrade'
. ${NEW_BINDIR}/../greenplum_path.sh
-
if (( !$perf_test )) ; then
diff_and_exit
fi
+}
+
+main "$@"
