eventscripts: Add modulo (%) operator to ctdb_check_counter()
authorMartin Schwenke <martin@meltin.net>
Fri, 2 Aug 2013 05:18:47 +0000 (15:18 +1000)
committerAmitay Isaacs <amitay@gmail.com>
Wed, 14 Aug 2013 05:57:03 +0000 (15:57 +1000)
Also add it to the corresponding eventscript unit test infrastructure.

Signed-off-by: Martin Schwenke <martin@meltin.net>
config/functions
tests/eventscripts/scripts/local.sh

index eb90946f5345c4a9154b097b4faf121e95b1497d..d9c8a2193054580beb28b00e03ecd8b8d987e895 100755 (executable)
@@ -1037,12 +1037,7 @@ drop_all_public_ips ()
 }
 
 ########################################################
-# some simple logic for counting events - per eventscript
-# usage: ctdb_counter_init
-#        ctdb_counter_incr
-#        ctdb_check_counter_limit <limit>
-# ctdb_check_counter_limit fails when count >= <limit>
-########################################################
+# Simple counters
 _ctdb_counter_common () {
     _service_name="${1:-${service_name:-${script_name}}}"
     _counter_file="$ctdb_fail_dir/$_service_name"
@@ -1068,7 +1063,17 @@ ctdb_check_counter () {
 
     # unary counting!
     _size=$(stat -c "%s" "$_counter_file" 2>/dev/null || echo 0)
-    if [ $_size $_op $_limit ] ; then
+    _hit=false
+    if [ "$_op" != "%" ] ; then
+       if [ $_size $_op $_limit ] ; then
+           _hit=true
+       fi
+    else
+       if [ $(($_size $_op $_limit)) -eq 0 ] ; then
+           _hit=true
+       fi
+    fi
+    if $_hit ; then
        if [ "$_msg" = "error" ] ; then
            echo "ERROR: $_limit consecutive failures for $_service_name, marking node unhealthy"
            exit 1              
index fafc8f3b2e4e6495ac94fdac9f5b13752f26cd94..00da7732dd2322ee56c43089e5357ca84a6f0957 100644 (file)
@@ -675,7 +675,17 @@ rpc_set_service_failure_response ()
            \#*) continue ;;
        esac
 
-       if [ "$_numfails" "$_op" "$_li" ] ; then
+       _hit=false
+       if [ "$_op" != "%" ] ; then
+           if [ $_numfails $_op $_li ] ; then
+               _hit=true
+           fi
+       else
+           if [ $(($_numfails $_op $_li)) -eq 0 ] ; then
+               _hit=true
+           fi
+       fi
+       if $_hit ; then
            _out=""
            _rc=0
            for _action in $_actions ; do