Added support to specify the FDB Cluster Text

Added support fo specify the number of ports from which to choose
Swapped tabs for spaces to make Marcus happy 😃
This commit is contained in:
Alvin Moore 2020-09-23 17:58:47 -04:00
parent 5d60663bbf
commit 40b51cbdbb
2 changed files with 300 additions and 297 deletions

View File

@ -7,7 +7,7 @@ SCRIPTID="${$}"
SAVEONERROR="${SAVEONERROR:-1}" SAVEONERROR="${SAVEONERROR:-1}"
PYTHONDIR="${BINDIR}/tests/python" PYTHONDIR="${BINDIR}/tests/python"
testScript="${BINDIR}/tests/bindingtester/run_binding_tester.sh" testScript="${BINDIR}/tests/bindingtester/run_binding_tester.sh"
VERSION="1.8" VERSION="1.9"
source ${SCRIPTDIR}/localClusterStart.sh source ${SCRIPTDIR}/localClusterStart.sh
@ -28,7 +28,7 @@ then
echo "Log dir: ${LOGDIR}" echo "Log dir: ${LOGDIR}"
echo "Python path: ${PYTHONDIR}" echo "Python path: ${PYTHONDIR}"
echo "Lib dir: ${LIBDIR}" echo "Lib dir: ${LIBDIR}"
echo "Cluster String: ${CLUSTERSTRING}" echo "Cluster String: ${FDBCLUSTERTEXT}"
echo "Script Id: ${SCRIPTID}" echo "Script Id: ${SCRIPTID}"
echo "Version: ${VERSION}" echo "Version: ${VERSION}"
fi fi

View File

@ -6,6 +6,7 @@ LOGDIR="${WORKDIR}/log"
ETCDIR="${WORKDIR}/etc" ETCDIR="${WORKDIR}/etc"
BINDIR="${BINDIR:-${SCRIPTDIR}}" BINDIR="${BINDIR:-${SCRIPTDIR}}"
FDBPORTSTART="${FDBPORTSTART:-4000}" FDBPORTSTART="${FDBPORTSTART:-4000}"
FDBPORTTOTAL="${FDBPORTTOTAL:-1000}"
SERVERCHECKS="${SERVERCHECKS:-10}" SERVERCHECKS="${SERVERCHECKS:-10}"
CONFIGUREWAIT="${CONFIGUREWAIT:-240}" CONFIGUREWAIT="${CONFIGUREWAIT:-240}"
FDBCONF="${ETCDIR}/fdb.cluster" FDBCONF="${ETCDIR}/fdb.cluster"
@ -18,382 +19,384 @@ status=0
messagetime=0 messagetime=0
messagecount=0 messagecount=0
# Define a random ip address and port on localhost # Do nothing, if cluster string is already defined
if [ -z ${IPADDRESS} ]; then if [ -n "${FDBCLUSTERTEXT}" ]
let index2="${RANDOM} % 256" then
let index3="${RANDOM} % 256" :
let index4="(${RANDOM} % 255) + 1" # Otherwise, define the cluster text
IPADDRESS="127.${index2}.${index3}.${index4}" else
# Define a random ip address and port on localhost
if [ -z "${IPADDRESS}" ]; then
let index2="${RANDOM} % 256"
let index3="${RANDOM} % 256"
let index4="(${RANDOM} % 255) + 1"
IPADDRESS="127.${index2}.${index3}.${index4}"
fi
if [ -z "${FDBPORT}" ]; then
let FDBPORT="(${RANDOM} % ${FDBPORTTOTAL}) + ${FDBPORTSTART}"
fi
FDBCLUSTERTEXT="${IPADDRESS}:${FDBPORT}"
fi fi
if [ -z ${FDBPORT} ]; then
let FDBPORT="(${RANDOM} % 1000) + ${FDBPORTSTART}"
fi
CLUSTERSTRING="${IPADDRESS}:${FDBPORT}"
function log function log
{ {
local status=0 local status=0
if [ "$#" -lt 1 ] if [ "$#" -lt 1 ]
then then
echo "Usage: log <message> [echo]" echo "Usage: log <message> [echo]"
echo echo
echo "Logs the message and timestamp to LOGFILE (${LOGFILE}) and, if the" echo "Logs the message and timestamp to LOGFILE (${LOGFILE}) and, if the"
echo "second argument is either not present or is set to 1, stdout." echo "second argument is either not present or is set to 1, stdout."
let status="${status} + 1" let status="${status} + 1"
else else
# Log to stdout. # Log to stdout.
if [ "$#" -lt 2 ] || [ "${2}" -ge 1 ] if [ "$#" -lt 2 ] || [ "${2}" -ge 1 ]
then then
echo "${1}" echo "${1}"
fi fi
# Log to file. # Log to file.
datestr=$(date +"%Y-%m-%d %H:%M:%S (%s)") datestr=$(date +"%Y-%m-%d %H:%M:%S (%s)")
dir=$(dirname "${LOGFILE}") dir=$(dirname "${LOGFILE}")
if ! [ -d "${dir}" ] && ! mkdir -p "${dir}" if ! [ -d "${dir}" ] && ! mkdir -p "${dir}"
then then
echo "Could not create directory to log output." echo "Could not create directory to log output."
let status="${status} + 1" let status="${status} + 1"
elif ! [ -f "${LOGFILE}" ] && ! touch "${LOGFILE}" elif ! [ -f "${LOGFILE}" ] && ! touch "${LOGFILE}"
then then
echo "Could not create file ${LOGFILE} to log output." echo "Could not create file ${LOGFILE} to log output."
let status="${status} + 1" let status="${status} + 1"
elif ! echo "[ ${datestr} ] ${1}" >> "${LOGFILE}" elif ! echo "[ ${datestr} ] ${1}" >> "${LOGFILE}"
then then
echo "Could not log output to ${LOGFILE}." echo "Could not log output to ${LOGFILE}."
let status="${status} + 1" let status="${status} + 1"
fi fi
fi fi
return "${status}" return "${status}"
} }
# Display a message for the user. # Display a message for the user.
function displayMessage function displayMessage
{ {
local status=0 local status=0
if [ "$#" -lt 1 ] if [ "$#" -lt 1 ]
then then
echo "displayMessage <message>" echo "displayMessage <message>"
let status="${status} + 1" let status="${status} + 1"
elif ! log "${1}" 0 elif ! log "${1}" 0
then then
log "Could not write message to file." log "Could not write message to file."
else else
# Increment the message counter # Increment the message counter
let messagecount="${messagecount} + 1" let messagecount="${messagecount} + 1"
# Display successful message, if previous message # Display successful message, if previous message
if [ "${messagecount}" -gt 1 ] if [ "${messagecount}" -gt 1 ]
then then
# Determine the amount of transpired time # Determine the amount of transpired time
let timespent="${SECONDS}-${messagetime}" let timespent="${SECONDS}-${messagetime}"
if [ "${DEBUGLEVEL}" -gt 0 ]; then if [ "${DEBUGLEVEL}" -gt 0 ]; then
printf "... done in %3d seconds\n" "${timespent}" printf "... done in %3d seconds\n" "${timespent}"
fi fi
fi fi
# Display message # Display message
if [ "${DEBUGLEVEL}" -gt 0 ]; then if [ "${DEBUGLEVEL}" -gt 0 ]; then
printf "%-16s %-35s " "$(date "+%F %H-%M-%S")" "$1" printf "%-16s %-35s " "$(date "+%F %H-%M-%S")" "$1"
fi fi
# Update the variables # Update the variables
messagetime="${SECONDS}" messagetime="${SECONDS}"
fi fi
return "${status}" return "${status}"
} }
# Create the directories used by the server. # Create the directories used by the server.
function createDirectories function createDirectories
{ {
local status=0 local status=0
# Display user message # Display user message
if ! displayMessage "Creating directories" if ! displayMessage "Creating directories"
then then
echo 'Failed to display user message' echo 'Failed to display user message'
let status="${status} + 1" let status="${status} + 1"
elif ! mkdir -p "${LOGDIR}" "${ETCDIR}" elif ! mkdir -p "${LOGDIR}" "${ETCDIR}"
then then
log "Failed to create directories" log "Failed to create directories"
let status="${status} + 1" let status="${status} + 1"
# Display user message # Display user message
elif ! displayMessage "Setting file permissions" elif ! displayMessage "Setting file permissions"
then then
log 'Failed to display user message' log 'Failed to display user message'
let status="${status} + 1" let status="${status} + 1"
elif ! chmod 755 "${BINDIR}/fdbserver" "${BINDIR}/fdbcli" elif ! chmod 755 "${BINDIR}/fdbserver" "${BINDIR}/fdbcli"
then then
log "Failed to set file permissions" log "Failed to set file permissions"
let status="${status} + 1" let status="${status} + 1"
else else
while read filepath while read filepath
do do
if [ -f "${filepath}" ] && [ ! -x "${filepath}" ] if [ -f "${filepath}" ] && [ ! -x "${filepath}" ]
then then
# if [ "${DEBUGLEVEL}" -gt 1 ]; then # if [ "${DEBUGLEVEL}" -gt 1 ]; then
# log " Enable executable: ${filepath}" # log " Enable executable: ${filepath}"
# fi # fi
log " Enable executable: ${filepath}" "${DEBUGLEVEL}" log " Enable executable: ${filepath}" "${DEBUGLEVEL}"
if ! chmod 755 "${filepath}" if ! chmod 755 "${filepath}"
then then
log "Failed to set executable for file: ${filepath}" log "Failed to set executable for file: ${filepath}"
let status="${status} + 1" let status="${status} + 1"
fi fi
fi fi
done < <(find "${BINDIR}" -iname '*.py' -o -iname '*.rb' -o -iname 'fdb_flow_tester' -o -iname '_stacktester' -o -iname '*.js' -o -iname '*.sh' -o -iname '*.ksh') done < <(find "${BINDIR}" -iname '*.py' -o -iname '*.rb' -o -iname 'fdb_flow_tester' -o -iname '_stacktester' -o -iname '*.js' -o -iname '*.sh' -o -iname '*.ksh')
fi fi
return ${status} return ${status}
} }
# Create a cluster file for the local cluster. # Create a cluster file for the local cluster.
function createClusterFile function createClusterFile
{ {
local status=0 local status=0
if [ "${status}" -ne 0 ]; then if [ "${status}" -ne 0 ]; then
: :
# Display user message # Display user message
elif ! displayMessage "Creating Fdb Cluster file" elif ! displayMessage "Creating Fdb Cluster file"
then then
log 'Failed to display user message' log 'Failed to display user message'
let status="${status} + 1" let status="${status} + 1"
else else
description=$(LC_CTYPE=C tr -dc A-Za-z0-9 < /dev/urandom 2> /dev/null | head -c 8) description=$(LC_CTYPE=C tr -dc A-Za-z0-9 < /dev/urandom 2> /dev/null | head -c 8)
random_str=$(LC_CTYPE=C tr -dc A-Za-z0-9 < /dev/urandom 2> /dev/null | head -c 8) random_str=$(LC_CTYPE=C tr -dc A-Za-z0-9 < /dev/urandom 2> /dev/null | head -c 8)
echo "${description}:${random_str}@${CLUSTERSTRING}" > "${FDBCONF}" echo "${description}:${random_str}@${FDBCLUSTERTEXT}" > "${FDBCONF}"
fi fi
if [ "${status}" -ne 0 ]; then if [ "${status}" -ne 0 ]; then
: :
elif ! chmod 0664 "${FDBCONF}"; then elif ! chmod 0664 "${FDBCONF}"; then
log "Failed to set permissions on fdbconf: ${FDBCONF}" log "Failed to set permissions on fdbconf: ${FDBCONF}"
let status="${status} + 1" let status="${status} + 1"
fi fi
return ${status} return ${status}
} }
# Stop the Cluster from running. # Stop the Cluster from running.
function stopCluster function stopCluster
{ {
local status=0 local status=0
# Add an audit entry, if enabled # Add an audit entry, if enabled
if [ "${AUDITCLUSTER}" -gt 0 ]; then if [ "${AUDITCLUSTER}" -gt 0 ]; then
printf '%-15s (%6s) Stopping cluster %-20s (%6s): %s\n' "$(date +'%Y-%m-%d %H:%M:%S')" "${$}" "${CLUSTERSTRING}" "${FDBSERVERID}" >> "${AUDITLOG}" printf '%-15s (%6s) Stopping cluster %-20s (%6s): %s\n' "$(date +'%Y-%m-%d %H:%M:%S')" "${$}" "${FDBCLUSTERTEXT}" "${FDBSERVERID}" >> "${AUDITLOG}"
fi fi
if [ -z "${FDBSERVERID}" ]; then if [ -z "${FDBSERVERID}" ]; then
log 'FDB Server process is not defined' log 'FDB Server process is not defined'
let status="${status} + 1" let status="${status} + 1"
elif ! kill -0 "${FDBSERVERID}"; then elif ! kill -0 "${FDBSERVERID}"; then
log "Failed to locate FDB Server process (${FDBSERVERID})" log "Failed to locate FDB Server process (${FDBSERVERID})"
let status="${status} + 1" let status="${status} + 1"
elif "${BINDIR}/fdbcli" -C "${FDBCONF}" --exec "kill; kill ${CLUSTERSTRING}; sleep 3" --timeout 120 &>> "${LOGDIR}/fdbcli-kill.log" elif "${BINDIR}/fdbcli" -C "${FDBCONF}" --exec "kill; kill ${FDBCLUSTERTEXT}; sleep 3" --timeout 120 &>> "${LOGDIR}/fdbcli-kill.log"
then then
# Ensure that process is dead # Ensure that process is dead
if ! kill -0 "${FDBSERVERID}" 2> /dev/null; then if ! kill -0 "${FDBSERVERID}" 2> /dev/null; then
log "Killed cluster (${FDBSERVERID}) via cli" log "Killed cluster (${FDBSERVERID}) via cli"
elif ! kill -9 "${FDBSERVERID}"; then elif ! kill -9 "${FDBSERVERID}"; then
log "Failed to kill FDB Server process (${FDBSERVERID}) via cli or kill command" log "Failed to kill FDB Server process (${FDBSERVERID}) via cli or kill command"
let status="${status} + 1" let status="${status} + 1"
else else
log "Forcibly killed FDB Server process (${FDBSERVERID}) since cli failed" log "Forcibly killed FDB Server process (${FDBSERVERID}) since cli failed"
fi fi
elif ! kill -9 "${FDBSERVERID}"; then elif ! kill -9 "${FDBSERVERID}"; then
log "Failed to forcibly kill FDB Server process (${FDBSERVERID})" log "Failed to forcibly kill FDB Server process (${FDBSERVERID})"
let status="${status} + 1" let status="${status} + 1"
else else
log "Forcibly killed FDB Server process (${FDBSERVERID})" log "Forcibly killed FDB Server process (${FDBSERVERID})"
fi fi
return "${status}" return "${status}"
} }
# Start the server running. # Start the server running.
function startFdbServer function startFdbServer
{ {
local status=0 local status=0
# Add an audit entry, if enabled # Add an audit entry, if enabled
if [ "${AUDITCLUSTER}" -gt 0 ]; then if [ "${AUDITCLUSTER}" -gt 0 ]; then
printf '%-15s (%6s) Starting cluster %-20s\n' "$(date +'%Y-%m-%d %H:%M:%S')" "${$}" "${CLUSTERSTRING}" >> "${AUDITLOG}" printf '%-15s (%6s) Starting cluster %-20s\n' "$(date +'%Y-%m-%d %H:%M:%S')" "${$}" "${FDBCLUSTERTEXT}" >> "${AUDITLOG}"
fi fi
if [ "${status}" -ne 0 ]; then if ! displayMessage "Starting Fdb Server"
: then
elif ! displayMessage "Starting Fdb Server" log 'Failed to display user message'
then let status="${status} + 1"
log 'Failed to display user message'
let status="${status} + 1"
else else
"${BINDIR}/fdbserver" --knob_disable_posix_kernel_aio=1 -C "${FDBCONF}" -p "${CLUSTERSTRING}" -L "${LOGDIR}" -d "${WORKDIR}/fdb/${$}" &> "${LOGDIR}/fdbserver.log" & "${BINDIR}/fdbserver" --knob_disable_posix_kernel_aio=1 -C "${FDBCONF}" -p "${FDBCLUSTERTEXT}" -L "${LOGDIR}" -d "${WORKDIR}/fdb/${$}" &> "${LOGDIR}/fdbserver.log" &
fdbpid=$! if [ "${?}" -ne 0 ]
fdbrc=$? then
if [ $fdbrc -ne 0 ] log "Failed to start FDB Server"
then let status="${status} + 1"
log "Failed to start FDB Server" else
let status="${status} + 1" FDBSERVERID="${!}"
else fi
FDBSERVERID="${fdbpid}" fi
fi
fi
if [ -z "${FDBSERVERID}" ]; then if [ -z "${FDBSERVERID}" ]; then
log "FDB Server start failed because no process" log "FDB Server start failed because no process"
let status="${status} + 1" let status="${status} + 1"
elif ! kill -0 "${FDBSERVERID}" ; then elif ! kill -0 "${FDBSERVERID}" ; then
log "FDB Server start failed because process terminated unexpectedly" log "FDB Server start failed because process terminated unexpectedly"
let status="${status} + 1" let status="${status} + 1"
fi fi
return ${status} return ${status}
} }
function getStatus function getStatus
{ {
local status=0 local status=0
if [ "${status}" -ne 0 ]; then if [ "${status}" -ne 0 ]; then
: :
elif ! date &>> "${LOGDIR}/fdbclient.log" elif ! date &>> "${LOGDIR}/fdbclient.log"
then then
log 'Failed to get date' log 'Failed to get date'
let status="${status} + 1" let status="${status} + 1"
elif ! "${BINDIR}/fdbcli" -C "${FDBCONF}" --exec 'status json' --timeout 120 &>> "${LOGDIR}/fdbclient.log" elif ! "${BINDIR}/fdbcli" -C "${FDBCONF}" --exec 'status json' --timeout 120 &>> "${LOGDIR}/fdbclient.log"
then then
log 'Failed to get status from fdbcli' log 'Failed to get status from fdbcli'
let status="${status} + 1" let status="${status} + 1"
elif ! date &>> "${LOGDIR}/fdbclient.log" elif ! date &>> "${LOGDIR}/fdbclient.log"
then then
log 'Failed to get date' log 'Failed to get date'
let status="${status} + 1" let status="${status} + 1"
fi fi
return ${status} return ${status}
} }
# Verify that the cluster is available. # Verify that the cluster is available.
function verifyAvailable function verifyAvailable
{ {
local status=0 local status=0
if [ -z "${FDBSERVERID}" ]; then if [ -z "${FDBSERVERID}" ]; then
log "FDB Server process is not defined." log "FDB Server process is not defined."
let status="${status} + 1" let status="${status} + 1"
# Verify that the server is running. # Verify that the server is running.
elif ! kill -0 "${FDBSERVERID}" elif ! kill -0 "${FDBSERVERID}"
then then
log "FDB server process (${FDBSERVERID}) is not running" log "FDB server process (${FDBSERVERID}) is not running"
let status="${status} + 1" let status="${status} + 1"
# Display user message. # Display user message.
elif ! displayMessage "Checking cluster availability" elif ! displayMessage "Checking cluster availability"
then then
log 'Failed to display user message' log 'Failed to display user message'
let status="${status} + 1" let status="${status} + 1"
# Determine if status json says the database is available. # Determine if status json says the database is available.
else else
avail=`"${BINDIR}/fdbcli" -C "${FDBCONF}" --exec 'status json' --timeout "${SERVERCHECKS}" 2> /dev/null | grep -E '"database_available"|"available"' | grep 'true'` avail=`"${BINDIR}/fdbcli" -C "${FDBCONF}" --exec 'status json' --timeout "${SERVERCHECKS}" 2> /dev/null | grep -E '"database_available"|"available"' | grep 'true'`
log "Avail value: ${avail}" "${DEBUGLEVEL}" log "Avail value: ${avail}" "${DEBUGLEVEL}"
if [[ -n "${avail}" ]] ; then if [[ -n "${avail}" ]] ; then
: :
else else
let status="${status} + 1" let status="${status} + 1"
fi fi
fi fi
return "${status}" return "${status}"
} }
# Configure the database on the server. # Configure the database on the server.
function createDatabase function createDatabase
{ {
local status=0 local status=0
if [ "${status}" -ne 0 ]; then if [ "${status}" -ne 0 ]; then
: :
# Ensure that the server is running # Ensure that the server is running
elif ! kill -0 "${FDBSERVERID}" elif ! kill -0 "${FDBSERVERID}"
then then
log "FDB server process: (${FDBSERVERID}) is not running" log "FDB server process: (${FDBSERVERID}) is not running"
let status="${status} + 1" let status="${status} + 1"
# Display user message # Display user message
elif ! displayMessage "Creating database" elif ! displayMessage "Creating database"
then then
log 'Failed to display user message' log 'Failed to display user message'
let status="${status} + 1" let status="${status} + 1"
elif ! echo "Client log:" &> "${LOGDIR}/fdbclient.log" elif ! echo "Client log:" &> "${LOGDIR}/fdbclient.log"
then then
log 'Failed to create fdbclient.log' log 'Failed to create fdbclient.log'
let status="${status} + 1" let status="${status} + 1"
elif ! getStatus elif ! getStatus
then then
log 'Failed to get status' log 'Failed to get status'
let status="${status} + 1" let status="${status} + 1"
# Configure the database. # Configure the database.
else else
"${BINDIR}/fdbcli" -C "${FDBCONF}" --exec 'configure new single memory; status' --timeout "${CONFIGUREWAIT}" --log --log-dir "${LOGDIR}" &>> "${LOGDIR}/fdbclient.log" "${BINDIR}/fdbcli" -C "${FDBCONF}" --exec 'configure new single memory; status' --timeout "${CONFIGUREWAIT}" --log --log-dir "${LOGDIR}" &>> "${LOGDIR}/fdbclient.log"
if ! displayMessage "Checking if config succeeded" if ! displayMessage "Checking if config succeeded"
then then
log 'Failed to display user message.' log 'Failed to display user message.'
fi fi
iteration=0 iteration=0
while [[ "${iteration}" -lt "${SERVERCHECKS}" ]] && ! verifyAvailable while [[ "${iteration}" -lt "${SERVERCHECKS}" ]] && ! verifyAvailable
do do
log "Database not created (iteration ${iteration})." log "Database not created (iteration ${iteration})."
let iteration="${iteration} + 1" let iteration="${iteration} + 1"
done done
if ! verifyAvailable if ! verifyAvailable
then then
log "Failed to create database via cli" log "Failed to create database via cli"
getStatus getStatus
cat "${LOGDIR}/fdbclient.log" cat "${LOGDIR}/fdbclient.log"
log "Ignoring -- moving on" log "Ignoring -- moving on"
#let status="${status} + 1" #let status="${status} + 1"
fi fi
fi fi
return ${status} return ${status}
} }
# Begin the local cluster from scratch. # Begin the local cluster from scratch.
function startCluster function startCluster
{ {
local status=0 local status=0
if [ "${status}" -ne 0 ]; then if [ "${status}" -ne 0 ]; then
: :
elif ! createDirectories elif ! createDirectories
then then
log "Could not create directories." log "Could not create directories."
let status="${status} + 1" let status="${status} + 1"
elif ! createClusterFile elif ! createClusterFile
then then
log "Could not create cluster file." log "Could not create cluster file."
let status="${status} + 1" let status="${status} + 1"
elif ! startFdbServer elif ! startFdbServer
then then
log "Could not start FDB server." log "Could not start FDB server."
let status="${status} + 1" let status="${status} + 1"
elif ! createDatabase elif ! createDatabase
then then
log "Could not create database." log "Could not create database."
let status="${status} + 1" let status="${status} + 1"
fi fi
return ${status} return ${status}
} }