Skip to content

Commit

Permalink
wip -- add pg version mismatch opt, misc dbg
Browse files Browse the repository at this point in the history
  • Loading branch information
ransomw1c committed Oct 10, 2019
1 parent 35c362f commit a13c2e9
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 16 deletions.
5 changes: 5 additions & 0 deletions hack/fuse-demo/create_coord_pg_pod.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
#! /bin/zsh

setopt ERR_EXIT

SCRIPT_DIR="$( cd "$( dirname "$0" )" && pwd )"

# OUTPUT_LABEL=pg-coord-example-input
OUTPUT_LABEL=pg-coord-example
IS_INIT=false
IGNORE_VERSION_MISMATCH=false

proj_root_dir="$(dirname "$(dirname "$SCRIPT_DIR")")"

Expand All @@ -17,6 +20,7 @@ while getopts ioc: opt; do
(i)
OUTPUT_LABEL=pg-coord-example-input
IS_INIT=true
IGNORE_VERSION_MISMATCH=true
;;
(o)
# local deploy
Expand Down Expand Up @@ -49,6 +53,7 @@ kubectl create secret generic \

RES_DEF="$proj_root_dir"/hack/k8s/gen/example-coord-pg.yaml

IGNORE_VERSION_MISMATCH=$IGNORE_VERSION_MISMATCH \
IS_INIT=$IS_INIT \
PULL_POLICY=$pull_policy \
OUTPUT_LABEL=$OUTPUT_LABEL \
Expand Down
2 changes: 1 addition & 1 deletion hack/fuse-demo/demo_pg_coord.sh
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ params_create_pod=(-c $SOME_CONST)
if $init_demo_bundle; then
params_create_pod=($params_create_pod -i)
fi
./hack/fuse-demo/create_coord_pg_pod.sh $init_demo_bundle
./hack/fuse-demo/create_coord_pg_pod.sh $params_create_pod

##### follow_coord_logs.sh dupe

Expand Down
2 changes: 1 addition & 1 deletion hack/fuse-demo/mock_application_pg.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ fi
if [ -z "$SOME_CONST" ]; then
usage
fi
if [[ ! $IS_INIT = true && ! $IS_INIT = flase ]]; then
if [[ ! $IS_INIT = true && ! $IS_INIT = false ]]; then
usage
fi

Expand Down
41 changes: 30 additions & 11 deletions hack/fuse-demo/wrap_datamon_pg.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ BP_PG_VERSION=${BP_META}/pg_version
BP_DATA=data
BP_PG_TAR=${BP_DATA}/backup.tar.gz

IGNORE_VERSION_MISMATCH=false

#####

typeset COORD_POINT
Expand All @@ -58,11 +60,14 @@ typeset pg_db_id

SLEEP_INSTEAD_OF_EXIT=

while getopts Sc:xsm:l:r:b:p: opt; do
while getopts SV:c:xsm:l:r:b:p: opt; do
case $opt in
(S)
SLEEP_INSTEAD_OF_EXIT=true
;;
(V)
IGNORE_VERSION_MISMATCH="$OPTARG"
;;
(c)
COORD_POINT="$OPTARG"
;;
Expand Down Expand Up @@ -227,6 +232,7 @@ sudo chgrp developers /dev/fuse

dbg_print "starting postgres database processes"

typeset -a version_mismatched_pg_db_ids
typeset -A pg_pids
for pg_db_id in $PG_DB_IDS; do
data_dir=${PG_DATA_DIR_ROOT}/${pg_db_id}
Expand Down Expand Up @@ -274,14 +280,24 @@ for pg_db_id in $PG_DB_IDS; do
# verify metadata
bundle_pg_version=$(cat ${mount_dir}/${BP_PG_VERSION})
if [[ $bundle_pg_version != $PG_VERSION ]]; then
terminate "pg version mistmatch $bundle_pg_version -- $PG_VERSION"
if $IGNORE_VERSION_MISMATCH; then
dbg_print "pg version mistmatch $bundle_pg_version -- $PG_VERSION"
# todo: revisit what to do in case of postgres version bumps
dbg_print "starting blank database instead"
version_mismatched_pg_db_ids=($version_mismatched_pg_db_ids \
$pg_db_id)
initdb --no-locale -D $data_dir
else
terminate "pg version mistmatch $bundle_pg_version -- $PG_VERSION"
fi
else
(cd $data_dir && \
>${LOG_ROOT}/untar.${pg_db_id}.log \
2>${LOG_ROOT}/untar_err.${pg_db_id}.log \
tar -xvf ${mount_dir}/${BP_PG_TAR})
slay $datamon_pid
chmod -R 750 $data_dir
fi
(cd $data_dir && \
>${LOG_ROOT}/untar.${pg_db_id}.log \
2>${LOG_ROOT}/untar_err.${pg_db_id}.log \
tar -xvf ${mount_dir}/${BP_PG_TAR})
slay $datamon_pid
chmod -R 750 $data_dir
else
# --no-locale flag helps artifact portability
# ??? other parms to set here?
Expand All @@ -302,17 +318,20 @@ for pg_db_id in $PG_DB_IDS; do
fi
pg_pids[$pg_db_id]=$pg_pid
dbg_print "begin block on db id ${pg_db_id} start"
if [[ -n ${PG_DB_HAS_SRC[$pg_db_id]} ]]; then
if [[ -n ${PG_DB_HAS_SRC[$pg_db_id]} && \
${version_mismatched_pg_db_ids[(Ie)$pg_db_id]} -eq 0 ]]; then
dbg_print "block on ${pg_db_id} db start by query"
while ! &>/dev/null psql \
-h localhost \
-p $PG_DB_PORTS[$pg_db_id] \
-U $PG_SU -l; do
print "waiting on ${pg_db_id} db start..."
dbg_print "waiting on ${pg_db_id} db start (query)..."
sleep $POLL_INTERVAL
done
else
dbg_print "block on ${pg_db_id} db start by createuser"
while ! &>/dev/null createuser -p $PG_DB_PORTS[$pg_db_id] -s $PG_SU; do
print "waiting on ${pg_db_id} db start..."
dbg_print "waiting on ${pg_db_id} db start (createuser)..."
sleep $POLL_INTERVAL
done
fi
Expand Down
9 changes: 6 additions & 3 deletions hack/k8s/example-coord-pg.template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,12 @@ spec:
# args: ["--", "/bin/zsh"]

command: ["./wrap_datamon_pg.sh"]
args: ["-S", "-c", "/tmp/coord",
args: ["-S",
"-V", "$IGNORE_VERSION_MISMATCH",
"-c", "/tmp/coord",
"-x",
"-r", "ransom-datamon-test-repo",
"-l", "pg-coord-example-input",
"-l", "$OUTPUT_LABEL",
"-m", "postgres coordination example",
"-p", "5430",
"-x",
Expand All @@ -62,7 +64,8 @@ spec:
"-p", "5429",
"-s",
"-r", "ransom-datamon-test-repo",
"-l", "$OUTPUT_LABEL"]
"-l", "pg-coord-example-input",
]

securityContext:
privileged: true
Expand Down

0 comments on commit a13c2e9

Please sign in to comment.