From 579dda6858f547d360073cd67235e49ab03b355e Mon Sep 17 00:00:00 2001 From: Martin Schwenke Date: Fri, 17 Apr 2015 20:44:15 +1000 Subject: [PATCH] ctdb-scripts: New function ctdb_get_pnn() does cached retrieval of PNN This avoids the expense of establishing a client connection to the daemon just to get the PNN of the current node. Signed-off-by: Martin Schwenke Reviewed-by: Amitay Isaacs --- ctdb/config/functions | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/ctdb/config/functions b/ctdb/config/functions index 1b2384ec088..da69ef44e8a 100755 --- a/ctdb/config/functions +++ b/ctdb/config/functions @@ -198,6 +198,20 @@ nice_service() _service "$@" } +###################################################### +# Cached retrieval of PNN from local node. This never changes so why +# open a client connection to the server each time this is needed? +# This sets $pnn - this avoid an unnecessary subprocess. +ctdb_get_pnn () +{ + _pnn_file="$CTDB_VARDIR/state/my-pnn" + if [ ! -f "$_pnn_file" ] ; then + ctdb pnn | sed -e 's@.*:@@' >"$_pnn_file" + fi + + read pnn <"$_pnn_file" +} + ###################################################### # wrapper around /proc/ settings to allow them to be hooked # for testing -- 2.34.1