ctdb-scripts: New function ctdb_get_pnn() does cached retrieval of PNN
authorMartin Schwenke <martin@meltin.net>
Fri, 17 Apr 2015 10:44:15 +0000 (20:44 +1000)
committerAmitay Isaacs <amitay@samba.org>
Mon, 27 Apr 2015 01:32:10 +0000 (03:32 +0200)
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 <martin@meltin.net>
Reviewed-by: Amitay Isaacs <amitay@gmail.com>
ctdb/config/functions

index 1b2384ec0886035c1a9d695b9e7117c3fcfdb64a..da69ef44e8af7e21c4b9d329597c8bcb37743005 100755 (executable)
@@ -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