ctdb-scripts: Avoid no-op "ctdb ptrans" call
authorMartin Schwenke <martin@meltin.net>
Tue, 3 Jan 2017 22:53:54 +0000 (09:53 +1100)
committerMartin Schwenke <martins@samba.org>
Thu, 1 Mar 2018 18:39:15 +0000 (19:39 +0100)
This causes unnecessary g_lock activity and overhead.

This could be optimised in ctdb.c:control_ptrans().  However, that
makes the code more complex.  Let's only do that if we get more
potentially no-op uses.

Note no optimisation is needed in the "notify" case because there is
already an early exit if there are no items.

Signed-off-by: Martin Schwenke <martin@meltin.net>
Reviewed-by: Amitay Isaacs <amitay@gmail.com>
ctdb/config/statd-callout

index 38f847b1d9b03ea3cc545f207d9cecdb37e3b73a..e2bac639e4ba65ecc0ca57ad807f065819383477 100755 (executable)
@@ -91,10 +91,14 @@ case "$1" in
                 printf "/statd-state@%s@/p\n", ip }')
        # Intentional multi-word expansion for multiple files
        # shellcheck disable=SC2086
-        if sed -n "$sed_expr" $files | $CTDB ptrans "ctdb.tdb" ; then
-            rm $files
+       items=$(sed -n "$sed_expr" $files)
+       if [ -n "$items" ] ; then
+               if echo "$items"  | $CTDB ptrans "ctdb.tdb" ; then
+                       # shellcheck disable=SC2086
+                       rm $files
+               fi
        fi
-        ;;
+       ;;
 
     notify)
        # we must restart the lockmanager (on all nodes) so that we get