demo_cluster.sh 15.1 KB
Newer Older
1 2
#!/bin/bash

3 4 5 6 7 8 9
# ======================================================================
# Configuration Variables
# ======================================================================

# Set to zero to force cluster to be created without data checksums
DATACHECKSUMS=1

10 11 12 13
# ======================================================================
# Data Directories
# ======================================================================

14 15 16 17 18 19
if [ -z "${MASTER_DATADIR}" ]; then
  DATADIRS=${DATADIRS:-`pwd`/datadirs}
else
  DATADIRS="${MASTER_DATADIR}/datadirs"
fi

20 21 22 23
QDDIR=$DATADIRS/qddir
SEG_PREFIX=demoDataDir

# ======================================================================
24
# Database Ports
25 26
# ======================================================================

27 28 29 30 31 32 33 34
# Note there are 2 ports per segment (postmaster port + replication_port)
for (( i=0; i<`expr 4 \* $NUM_PRIMARY_MIRROR_PAIRS`; i++ )); do
  PORT_NUM=`expr $DEMO_PORT_BASE + $i`
  DEMO_SEG_PORTS_LIST="$DEMO_SEG_PORTS_LIST $PORT_NUM"
done
DEMO_SEG_PORTS_LIST=${DEMO_SEG_PORTS_LIST#* }

# ======================================================================
35
# Functions
36
# ======================================================================
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56

checkDemoConfig(){
    echo "----------------------------------------------------------------------"
    echo "                   Checking for port availability"
    echo "----------------------------------------------------------------------"
    echo ""
    # Check if Master_DEMO_Port is free
    echo "  Master port check ... : ${MASTER_DEMO_PORT}"
    PORT_FILE="/tmp/.s.PGSQL.${MASTER_DEMO_PORT}"
    if [ -f ${PORT_FILE} -o  -S ${PORT_FILE} ] ; then 
        echo ""
        echo -n " Port ${MASTER_DEMO_PORT} appears to be in use. " 
        echo " This port is needed by the Master Database instance. "
        echo ">>> Edit Makefile to correct the port number (MASTER_PORT). <<<" 
        echo -n " Check to see if the port is free by using : "
        echo " 'netstat -an | grep ${MASTER_DEMO_PORT}"
        echo ""
        return 1
    fi

57 58 59
    for (( i=0; i<`expr 4 \* $NUM_PRIMARY_MIRROR_PAIRS`; i++ )); do
	PORT_NUM=`expr $DEMO_PORT_BASE + $i`

60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
        echo "  Segment port check .. : ${PORT_NUM}"
        PORT_FILE="/tmp/.s.PGSQL.${PORT_NUM}"
        if [ -f ${PORT_FILE} -o -S ${PORT_FILE} ] ; then 
            echo ""
            echo -n "Port ${PORT_NUM} appears to be in use."
            echo " This port is needed for segment database instance."
            echo ">>> Edit Makefile to correct the base ports (PORT_BASE). <<<"
            echo -n " Check to see if the port is free by using : "
            echo " 'netstat -an | grep ${PORT_NUM}"
            echo ""
            return 1
        fi
    done
    return 0
}

USAGE(){
    echo ""
78 79
    echo " `basename $0` {-c | -d | -u} <-K>"
    echo " -c : Check if demo is possible."
80
    echo " -d : Delete the demo."
81
    echo " -K : Create cluster without data checksums."
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
    echo " -u : Usage, prints this message."
    echo ""
}

#
# Clean up the demo
#

cleanDemo(){

    ##
    ## Attempt to bring down using GPDB cluster instance using gpstop
    ##

    (export MASTER_DATA_DIRECTORY=$QDDIR/${SEG_PREFIX}-1;
     source ${GPHOME}/greenplum_path.sh;
     gpstop -a)

    ##
    ## Remove the files and directories created; allow test harnesses
    ## to disable this
    ##

    if [ "${GPDEMO_DESTRUCTIVE_CLEAN}" != "false" ]; then
        if [ -f hostfile ];  then
            echo "Deleting hostfile"
            rm -f hostfile
        fi
        if [ -f clusterConfigFile ];  then
            echo "Deleting clusterConfigFile"
            rm -f clusterConfigFile
        fi
        if [ -d ${DATADIRS} ];  then
            echo "Deleting ${DATADIRS}"
            rm -rf ${DATADIRS}
        fi
        if [ -d logs ];  then
            rm -rf logs
        fi
        rm -f optimizer-state.log gpdemo-env.sh
    fi
}

#*****************************************************************************
# Main Section
#*****************************************************************************

129
while getopts ":cdK'?'" opt
130 131 132 133 134 135 136 137 138 139 140 141 142 143
do
	case $opt in 
		'?' ) USAGE ;;
        c) checkDemoConfig
           RETVAL=$?
           if [ $RETVAL -ne 0 ]; then
               echo "Checking failed "
               exit 1
           fi
           exit 0
           ;;
        d) cleanDemo
           exit 0
           ;;
144 145 146
        K) DATACHECKSUMS=0
           shift
           ;;
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
        *) USAGE
           exit 0
           ;;
	esac
done

if [ -z "${GPHOME}" ]; then
    echo "FATAL: The GPHOME enviroment variable is not set."
    echo ""
    echo "  You can set it by sourcing the greenplum_path.sh"
    echo "  file in your Greenplum installation directory."
    echo ""
    exit 1
else
    GPSEARCH=$GPHOME
fi

cat <<-EOF
	======================================================================
	            ______  _____  ______  _______ _______  _____
	           |  ____ |_____] |     \ |______ |  |  | |     |
	           |_____| |       |_____/ |______ |  |  | |_____|

	----------------------------------------------------------------------

	  This is a demo of the Greenplum Database system.  We will create
173 174
	  a cluster installation with master and `expr 2 \* ${NUM_PRIMARY_MIRROR_PAIRS}` segment instances
	  (${NUM_PRIMARY_MIRROR_PAIRS} primary & ${NUM_PRIMARY_MIRROR_PAIRS} mirror).
175 176

	    GPHOME ................. : ${GPHOME}
177
	    MASTER_DATA_DIRECTORY .. : ${QDDIR}/${SEG_PREFIX}-1
178 179

	    MASTER PORT (PGPORT) ... : ${MASTER_DEMO_PORT}
180
	    SEGMENT PORTS .......... : ${DEMO_SEG_PORTS_LIST}
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

	  NOTE(s):

	    * The DB ports identified above must be available for use.
	    * An environment file gpdemo-env.sh has been created for your use.

	======================================================================

EOF

GPPATH=`find $GPSEARCH -name gp_dump| tail -1`
RETVAL=$?

if [ "$RETVAL" -ne 0 ]; then
    echo "Error attempting to find Greenplum executables in $GPSEARCH"
    exit 1
fi

if [ ! -x "$GPPATH" ]; then
    echo "No executables found for Greenplum installation in $GPSEARCH"
    exit 1
fi
GPPATH=`dirname $GPPATH`
if [ ! -x $GPPATH/gpinitsystem ]; then
    echo "No mgmt executables found for Greenplum installation in $GPPATH"
    exit 1
fi

if [ -d $DATADIRS ]; then
  rm -rf $DATADIRS
fi
mkdir $DATADIRS
mkdir $QDDIR
214
mkdir $DATADIRS/gpAdminLogs
215

216
for (( i=1; i<=$NUM_PRIMARY_MIRROR_PAIRS; i++ ))
217
do
218 219 220 221 222 223 224
  PRIMARY_DIR=$DATADIRS/dbfast$i
  mkdir -p $PRIMARY_DIR
  PRIMARY_DIRS_LIST="$PRIMARY_DIRS_LIST $PRIMARY_DIR"

  MIRROR_DIR=$DATADIRS/dbfast_mirror$i
  mkdir -p $MIRROR_DIR
  MIRROR_DIRS_LIST="$MIRROR_DIRS_LIST $MIRROR_DIR"
225
done
226 227
PRIMARY_DIRS_LIST=${PRIMARY_DIRS_LIST#* }
MIRROR_DIRS_LIST=${MIRROR_DIRS_LIST#* }
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

#*****************************************************************************************
# Host configuration
#*****************************************************************************************

LOCALHOST=`hostname`
echo $LOCALHOST > hostfile

#*****************************************************************************************
# Name of the system configuration file.
#*****************************************************************************************

CLUSTER_CONFIG=clusterConfigFile
CLUSTER_CONFIG_POSTGRES_ADDONS=clusterConfigPostgresAddonsFile

rm -f ${CLUSTER_CONFIG}
rm -f ${CLUSTER_CONFIG_POSTGRES_ADDONS}

#*****************************************************************************************
# Create the system configuration file
#*****************************************************************************************

cat >> $CLUSTER_CONFIG <<-EOF
	# Set this to anything you like
	ARRAY_NAME="Demo $HOSTNAME Cluster"
	CLUSTER_NAME="Demo $HOSTNAME Cluster"
	
	# This file must exist in the same directory that you execute gpinitsystem in
256
	MACHINE_LIST_FILE=`pwd`/hostfile
257 258 259 260 261 262 263 264 265 266 267 268 269
	
	# This names the data directories for the Segment Instances and the Entry Postmaster
	SEG_PREFIX=$SEG_PREFIX
	
	# This is the port at which to contact the resulting Greenplum database, e.g.
	#   psql -p \$PORT_BASE -d template1
	PORT_BASE=${DEMO_PORT_BASE}
	
	# Prefix for script created database
	DATABASE_PREFIX=demoDatabase
	
	# Array of data locations for each hosts Segment Instances, the number of directories in this array will
	# set the number of segment instances per host
270
	declare -a DATA_DIRECTORY=(${PRIMARY_DIRS_LIST})
271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291
	
	# Name of host on which to setup the QD
	MASTER_HOSTNAME=$LOCALHOST
	
	# Name of directory on that host in which to setup the QD
	MASTER_DIRECTORY=$QDDIR
	
	MASTER_PORT=${MASTER_DEMO_PORT}
	
	# Hosts to allow to connect to the QD (and Segment Instances)
	# By default, allow everyone to connect (0.0.0.0/0)
	IP_ALLOW=0.0.0.0/0
	
	# Shell to use to execute commands on all hosts
	TRUSTED_SHELL="`pwd`/lalshell"
	
	CHECK_POINT_SEGMENTS=8
	
	ENCODING=UNICODE
EOF

292 293 294 295 296 297 298
if [ "${DATACHECKSUMS}" == "0" ]; then
    cat >> $CLUSTER_CONFIG <<-EOF
	# Turn off data checksums
	HEAP_CHECKSUM=off
EOF
fi

299 300
if [ "${WITH_MIRRORS}" == "true" ]; then
    cat >> $CLUSTER_CONFIG <<-EOF
301

302 303 304
		# Array of mirror data locations for each hosts Segment Instances, the number of directories in this array will
		# set the number of segment instances per host
		declare -a MIRROR_DATA_DIRECTORY=(${MIRROR_DIRS_LIST})
305

306 307 308 309 310 311
		MIRROR_PORT_BASE=`expr $DEMO_PORT_BASE + $NUM_PRIMARY_MIRROR_PAIRS`

		REPLICATION_PORT_BASE=`expr $DEMO_PORT_BASE + 2 \* $NUM_PRIMARY_MIRROR_PAIRS`
		MIRROR_REPLICATION_PORT_BASE=`expr $DEMO_PORT_BASE + 3 \* $NUM_PRIMARY_MIRROR_PAIRS`
	EOF
fi
312

313 314 315 316
if [ ! -z "${EXTRA_CONFIG}" ]; then
  echo ${EXTRA_CONFIG} >> $CLUSTER_CONFIG
fi

317 318 319 320 321 322 323 324 325 326 327
cat >> $CLUSTER_CONFIG <<-EOF

	# Path for Greenplum mgmt utils and Greenplum binaries
	PATH=$GPHOME/bin:$PATH
	LD_LIBRARY_PATH=$GPHOME/lib:$LD_LIBRARY_PATH
	export PATH
	export LD_LIBRARY_PATH
	export MASTER_DATA_DIRECTORY
	export TRUSTED_SHELL
EOF

328 329 330 331
if [ -z "${DEFAULT_QD_MAX_CONNECT}" ]; then
   DEFAULT_QD_MAX_CONNECT=25
fi

332 333 334 335 336
cat >> $CLUSTER_CONFIG <<-EOF

	# Keep max_connection settings to reasonable values for
	# installcheck good execution.

337
	DEFAULT_QD_MAX_CONNECT=$DEFAULT_QD_MAX_CONNECT
338 339 340 341
	QE_CONNECT_FACTOR=5

EOF

342 343 344 345 346 347
if [ -n "${STATEMENT_MEM}" ]; then
	cat >> $CLUSTER_CONFIG_POSTGRES_ADDONS<<-EOF
		statement_mem = ${STATEMENT_MEM}
	EOF
fi

348 349 350 351 352
if [ "${ONLY_PREPARE_CLUSTER_ENV}" == "true" ]; then
    echo "ONLY_PREPARE_CLUSTER_ENV set, generated clusterConf file: $CLUSTER_CONFIG, exiting"
    exit 0
fi

353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370
## ======================================================================
## Create cluster
## ======================================================================

##
## Provide support to pass dynamic values to ${CLUSTER_CONFIG_POSTGRES_ADDONS}
## which is used during gpinitsystems.
##

if [ "${BLDWRAP_POSTGRES_CONF_ADDONS}" != "__none__" ]  && \
   [ "${BLDWRAP_POSTGRES_CONF_ADDONS}" != "__unset__" ] && \
   [ -n "${BLDWRAP_POSTGRES_CONF_ADDONS}" ]; then

    [ -f ${CLUSTER_CONFIG_POSTGRES_ADDONS} ] && chmod a+w ${CLUSTER_CONFIG_POSTGRES_ADDONS}

    for addon in $( echo ${BLDWRAP_POSTGRES_CONF_ADDONS} | sed -e "s/|/ /g" ); do
        echo "" >> ${CLUSTER_CONFIG_POSTGRES_ADDONS}
        echo $addon >> ${CLUSTER_CONFIG_POSTGRES_ADDONS}
371 372 373
	if [ "$addon" == "fsync=off" ]; then
		echo "WARNING: fsync is off, database consistency is not guaranteed."
	fi
374 375 376 377 378 379 380 381 382 383 384 385 386 387 388
        echo "" >> ${CLUSTER_CONFIG_POSTGRES_ADDONS}
    done

    echo ""
    echo "======================================================================"
    echo "CLUSTER_CONFIG_POSTGRES_ADDONS: ${CLUSTER_CONFIG_POSTGRES_ADDONS}"
    echo "----------------------------------------------------------------------"
    cat ${CLUSTER_CONFIG_POSTGRES_ADDONS}
    echo "======================================================================"
    echo ""
fi

if [ -f "${CLUSTER_CONFIG_POSTGRES_ADDONS}" ]; then
    echo "=========================================================================================="
    echo "executing:"
389
    echo "  $GPPATH/gpinitsystem -a -c $CLUSTER_CONFIG -l $DATADIRS/gpAdminLogs -p ${CLUSTER_CONFIG_POSTGRES_ADDONS} \"$@\""
390 391
    echo "=========================================================================================="
    echo ""
392
    $GPPATH/gpinitsystem -a -c $CLUSTER_CONFIG -l $DATADIRS/gpAdminLogs -p ${CLUSTER_CONFIG_POSTGRES_ADDONS} "$@"
393 394 395
else
    echo "=========================================================================================="
    echo "executing:"
396
    echo "  $GPPATH/gpinitsystem -a -c $CLUSTER_CONFIG -l $DATADIRS/gpAdminLogs \"$@\""
397 398
    echo "=========================================================================================="
    echo ""
399
    $GPPATH/gpinitsystem -a -c $CLUSTER_CONFIG -l $DATADIRS/gpAdminLogs "$@"
400 401 402 403 404 405 406 407
fi
RETURN=$?

echo "========================================"
echo "gpinitsystem returned: ${RETURN}"
echo "========================================"
echo ""

A
Adam Lee 已提交
408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425
if [ "$enable_gpfdist" = "yes" ] && [ "$with_openssl" = "yes" ]; then
	echo "======================================================================"
	echo "Generating SSL certificates for gpfdists:"
	echo "======================================================================"
	echo ""

	./generate_certs.sh >> generate_certs.log

	cp -r certificate/gpfdists $QDDIR/$SEG_PREFIX-1/

	for (( i=1; i<=$NUM_PRIMARY_MIRROR_PAIRS; i++ ))
	do
		cp -r certificate/gpfdists $DATADIRS/dbfast$i/${SEG_PREFIX}$((i-1))/
		cp -r certificate/gpfdists $DATADIRS/dbfast_mirror$i/${SEG_PREFIX}$((i-1))/
	done
	echo ""
fi

426 427 428 429 430
OPTIMIZER=$(psql -t -p ${MASTER_DEMO_PORT} -d template1 -c "show optimizer"   2>&1)

echo "======================================================================" 2>&1 | tee -a optimizer-state.log
echo "                           OPTIMIZER STATE"                             2>&1 | tee -a optimizer-state.log
echo "----------------------------------------------------------------------" 2>&1 | tee -a optimizer-state.log
J
Jason Champion 已提交
431
echo "  Optimizer state .. : ${OPTIMIZER}"                                    2>&1 | tee -a optimizer-state.log
432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460
echo "======================================================================" 2>&1 | tee -a optimizer-state.log
echo ""                                                                       2>&1 | tee -a optimizer-state.log

psql -p ${MASTER_DEMO_PORT} -d template1 -c "select version();"               2>&1 | tee -a optimizer-state.log

psql -p ${MASTER_DEMO_PORT} -d template1 -c "show optimizer;" > /dev/null     2>&1
if [ $? = 0 ]; then
    psql -p ${MASTER_DEMO_PORT} -d template1 -c "show optimizer;"             2>&1 | tee -a optimizer-state.log
fi

psql -p ${MASTER_DEMO_PORT} -d template1 -c "select gp_opt_version();" > /dev/null 2>&1
if [ $? = 0 ]; then
    psql -p ${MASTER_DEMO_PORT} -d template1 -c "select gp_opt_version();"    2>&1 | tee -a optimizer-state.log
fi

echo "======================================================================" 2>&1 | tee -a optimizer-state.log
echo ""                                                                       2>&1 | tee -a optimizer-state.log

cat > gpdemo-env.sh <<-EOF
	## ======================================================================
	##                                gpdemo
	## ----------------------------------------------------------------------
	## timestamp: $( date )
	## ======================================================================

	export PGPORT=${MASTER_DEMO_PORT}
	export MASTER_DATA_DIRECTORY=$QDDIR/${SEG_PREFIX}-1
EOF

461 462 463 464 465 466 467
if [ "${RETURN}" -gt 1 ];
then
    # gpinitsystem will return warnings as exit code 1
    exit ${RETURN}
else
    exit 0
fi