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)
committerMartin Schwenke <martin@meltin.net>
Wed, 24 Feb 2016 06:12:39 +0000 (17:12 +1100)
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>
(Imported from commit 579dda6858f547d360073cd67235e49ab03b355e)

config/functions

index 7f0b3bf6a9d957fd48445ec9ac48a56487da0520..b0bc5e65b7b30eeb296f24b30335212cd016eb19 100644 (file)
@@ -210,6 +210,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