[SCM] CTDB repository - branch master updated - ctdb-1.0.81-9-g1c31fea

Ronnie Sahlberg sahlberg at samba.org
Mon May 11 23:01:18 GMT 2009


The branch, master has been updated
       via  1c31fea7432b870169fb839c1fbba5a33dec8e8a (commit)
       via  e781ff61e17d733349021bb036514f823c7cbfbb (commit)
       via  cdf092d69a710310d82d1d67baa0ffb19f676927 (commit)
       via  29559f5dd099bec210e98909c9b2e048461b7c81 (commit)
       via  a0f5148ac749758e2dfbd6099e829c5bf1d900e6 (commit)
       via  5f3d2e29a446972ac244e20a08e48f4c2f4ffef4 (commit)
       via  2d3fbbbb63f443686f9fec42c0bc2058d115806e (commit)
      from  bbae698656d5da9a4a5b0fbfc3003844f246d54b (commit)

http://gitweb.samba.org/?p=sahlberg/ctdb.git;a=shortlog;h=master


- Log -----------------------------------------------------------------
commit 1c31fea7432b870169fb839c1fbba5a33dec8e8a
Author: Ronnie Sahlberg <ronniesahlberg at gmail.com>
Date:   Tue May 12 08:59:49 2009 +1000

    From: Sumit Bose <sbose at redhat.com>
    
     fix handling of AC_INIT

commit e781ff61e17d733349021bb036514f823c7cbfbb
Author: Martin Schwenke <martin at meltin.net>
Date:   Mon May 11 14:43:17 2009 +1000

    Fix lvsmaster and natgwlist nodespecs.
    
    They both need to use a -Y option to ctdb and for natgwlist we only
    want the 1st line.
    
    Signed-off-by: Martin Schwenke <martin at meltin.net>

commit cdf092d69a710310d82d1d67baa0ffb19f676927
Author: Martin Schwenke <martin at meltin.net>
Date:   Mon May 11 14:14:11 2009 +1000

    Updated onnode docs to reflect recent changes.
    
    Signed-off-by: Martin Schwenke <martin at meltin.net>

commit 29559f5dd099bec210e98909c9b2e048461b7c81
Author: Martin Schwenke <martin at meltin.net>
Date:   Mon May 11 13:39:31 2009 +1000

    New lvs/lvsmaster and natgw/natgwlist nodespecs for onnode.
    
    Some code re-factoring to implement this and to make it easy to
    implement new ones.  New simpler implementation of echo_nth() no
    longer uses deleted get_nth() function.
    
    Signed-off-by: Martin Schwenke <martin at meltin.net>

commit a0f5148ac749758e2dfbd6099e829c5bf1d900e6
Author: Martin Schwenke <martin at meltin.net>
Date:   Wed May 6 13:17:34 2009 +1000

    New option "-o <prefix>" saves stdout from each node to file <prefix>.<ip>.
    
    Signed-off-by: Martin Schwenke <martin at meltin.net>

commit 5f3d2e29a446972ac244e20a08e48f4c2f4ffef4
Author: Martin Schwenke <martin at meltin.net>
Date:   Tue May 5 16:02:30 2009 +1000

    Use ctdb_fetch_lock rather than ctdb_call.
    
    Signed-off-by: Martin Schwenke <martin at meltin.net>

commit 2d3fbbbb63f443686f9fec42c0bc2058d115806e
Author: Martin Schwenke <martin at meltin.net>
Date:   Mon May 11 14:50:28 2009 +1000

    41.httpd event script workaround for RHEL5-ism.
    
    RHEL5 can SIGKILL httpd when stopping it, causing it to leak
    semaphores.  This means that eventually a node runs out of semaphores
    and httpd can't be started.  So, before we attempt to start httpd we
    clean up any semaphores owned by apache.  We also try to restart httpd
    in the monitor event if httpd has gone away.
    
    Signed-off-by: Martin Schwenke <martin at meltin.net>

-----------------------------------------------------------------------

Summary of changes:
 config/events.d/41.httpd |   36 ++++++++---
 configure.ac             |    2 +-
 doc/onnode.1.xml         |   23 +++++++
 tests/src/ctdb_fetch.c   |   35 +++--------
 tools/onnode             |  144 +++++++++++++++++++++++++++++-----------------
 5 files changed, 149 insertions(+), 91 deletions(-)


Changeset truncated at 500 lines:

diff --git a/config/events.d/41.httpd b/config/events.d/41.httpd
index fae9f47..4d8c440 100755
--- a/config/events.d/41.httpd
+++ b/config/events.d/41.httpd
@@ -34,19 +34,35 @@ loadconfig "${CTDB_CONFIG_HTTP}"
 cmd="$1"
 shift
 
-case $cmd in 
-     startup)
-        service "${CTDB_SERVICE_HTTP}" stop > /dev/null 2>&1
-        service "${CTDB_SERVICE_HTTP}" start
-        ;;
+# RHEL5 sometimes use a SIGKILL to terminate httpd, which then leaks
+# semaphores.  This is a hack to clean them up.
+cleanup_httpd_semaphore_leak() {
+    killall -q -0 "${CTDB_SERVICE_HTTP}" ||
+    for i in $(ipcs -s | awk '$3 == "apache" { print $2 }') ; do
+	ipcrm -s $i
+    done
+}
 
-     shutdown)
-        service "${CTDB_SERVICE_HTTP}" stop
-        ;;
+case $cmd in
+    startup)
+	cleanup_httpd_semaphore_leak
+	service "${CTDB_SERVICE_HTTP}" start
+	;;
+
+    shutdown)
+	service "${CTDB_SERVICE_HTTP}" stop
+	killall -q -9 "${CTDB_SERVICE_HTTP}"
+	;;
 
      monitor)
-        ctdb_check_tcp_ports "http" 80
-        ;;
+	( ctdb_check_tcp_ports "http" 80 )
+	if [ $? -ne 0 ] ; then
+	    echo "HTTPD is not running. Trying to restart HTTPD."
+	    cleanup_httpd_semaphore_leak
+	    service "${CTDB_SERVICE_HTTP}" start
+	    exit 1
+	fi
+	;;
 esac
 
 exit 0
diff --git a/configure.ac b/configure.ac
index 2074546..416349d 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1,5 +1,5 @@
 AC_PREREQ(2.50)
-AC_INIT(ctdb, m4_esyscmd([grep 'Version:' ./packaging/RPM/ctdb.spec 2>/dev/null | head -1 | sed -e 's/[ \t]*Version:[ \t]*\([^ \t]*\)[ \t].*/\1/' | tr -d '\n']))
+AC_INIT(ctdb, m4_esyscmd([grep 'Version:' ./packaging/RPM/ctdb.spec 2>/dev/null | head -1 | sed -e 's/[ \t]*Version:[ \t]*\([^ \t]*\)[ \t]*.*/\1/' | tr -d '\n']))
 AC_DEFUN([AC_CHECK_LIB_EXT], [
 	AC_CHECK_LIB([$1],[$3],[$4],[$5],[$7])
 	ac_cv_lib_ext_$1_$3=$ac_cv_lib_$1_$3
diff --git a/doc/onnode.1.xml b/doc/onnode.1.xml
index 0bf4d82..8710d36 100644
--- a/doc/onnode.1.xml
+++ b/doc/onnode.1.xml
@@ -70,6 +70,20 @@
 	  </para>
         </listitem>
       </varlistentry>
+      <varlistentry><term>lvs | lvsmaster</term>
+        <listitem>
+          <para>
+            The current LVS master.
+	  </para>
+        </listitem>
+      </varlistentry>
+      <varlistentry><term>natgw | natgwlist</term>
+        <listitem>
+          <para>
+            The current NAT gateway.
+	  </para>
+        </listitem>
+      </varlistentry>
       <varlistentry><term>rm | recmaster</term>
         <listitem>
           <para>
@@ -92,6 +106,15 @@
         </listitem>
       </varlistentry>
 
+      <varlistentry><term>-o &lt;prefix&gt;</term>
+        <listitem>
+          <para>
+	    Causes standard output from each node to be saved into a
+	    file with name &lt;prefix&gt;.&lt;ip&gt;.
+	  </para>
+        </listitem>
+      </varlistentry>
+
       <varlistentry><term>-p</term>
         <listitem>
           <para>
diff --git a/tests/src/ctdb_fetch.c b/tests/src/ctdb_fetch.c
index 2cc51d5..aab4fe1 100644
--- a/tests/src/ctdb_fetch.c
+++ b/tests/src/ctdb_fetch.c
@@ -145,17 +145,6 @@ static void bench_fetch(struct ctdb_context *ctdb, struct event_context *ev)
 	printf("Fetch: %.2f msgs/sec\n", msg_count/end_timer());
 }
 
-enum my_functions {FUNC_FETCH=1};
-
-/*
-  ctdb call function to fetch a record
-*/
-static int fetch_func(struct ctdb_call_info *call)
-{
-	call->reply_data = &call->record_data;
-	return 0;
-}
-
 /*
   handler for reconfigure message
 */
@@ -185,10 +174,10 @@ int main(int argc, const char *argv[])
 	int opt;
 	const char **extra_argv;
 	int extra_argc = 0;
-	int ret;
 	poptContext pc;
 	struct event_context *ev;
-	struct ctdb_call call;
+	TDB_DATA key, data;
+	struct ctdb_record_handle *h;
 	int cluster_ready=0;
 
 	pc = poptGetContext(argv[0], argc, argv, popt_options, POPT_CONTEXT_KEEP_FIRST);
@@ -225,8 +214,6 @@ int main(int argc, const char *argv[])
 		exit(1);
 	}
 
-	ret = ctdb_set_call(ctdb_db, fetch_func, FUNC_FETCH);
-
 	ctdb_set_message_handler(ctdb, 0, message_handler, &msg_count);
 
 	printf("Waiting for cluster\n");
@@ -239,24 +226,20 @@ int main(int argc, const char *argv[])
 
 	bench_fetch(ctdb, ev);
 
-	ZERO_STRUCT(call);
-	call.key.dptr = discard_const(TESTKEY);
-	call.key.dsize = strlen(TESTKEY);
+	key.dptr = discard_const(TESTKEY);
+	key.dsize = strlen(TESTKEY);
 
 	printf("Fetching final record\n");
 
-	/* fetch the record */
-	call.call_id = FUNC_FETCH;
-	call.call_data.dptr = NULL;
-	call.call_data.dsize = 0;
+	h = ctdb_fetch_lock(ctdb_db, ctdb, key, &data);
 
-	ret = ctdb_call(ctdb_db, &call);
-	if (ret == -1) {
-		printf("ctdb_call FUNC_FETCH failed - %s\n", ctdb_errstr(ctdb));
+	if (h == NULL) {
+		printf("Failed to fetch record '%s' on node %d\n", 
+		       (const char *)key.dptr, ctdb_get_pnn(ctdb));
 		exit(1);
 	}
 
-	printf("DATA:\n%s\n", (char *)call.reply_data.dptr);
+	printf("DATA:\n%s\n", (char *)data.dptr);
 
 	return 0;
 }
diff --git a/tools/onnode b/tools/onnode
index 5bb5ebb..d7adbb0 100755
--- a/tools/onnode
+++ b/tools/onnode
@@ -30,15 +30,17 @@ usage ()
     cat >&2 <<EOF
 Usage: onnode [OPTION] ... <NODES> <COMMAND> ...
   options:
-    -c         Run in current working directory on specified nodes.
-    -p         Run command in parallel on specified nodes.
-    -q         Do not print node addresses (overrides -v).
-    -v         Print node address even for a single node.
-  <NODES>      "all", "ok" (or "healthy"), "con" (or "connected"),
-               "rm" (or "recmaster");
-               or a node number (0 base); or
-               list (comma separated) of <NODES>; or
-               range (hyphen separated) of node numbers.
+    -c          Run in current working directory on specified nodes.
+    -o <prefix> Save standard output from each node to file <prefix>.<ip>
+    -p          Run command in parallel on specified nodes.
+    -q          Do not print node addresses (overrides -v).
+    -v          Print node address even for a single node.
+  <NODES>       "all", "ok" (or "healthy"), "con" (or "connected"),
+                "rm" (or "recmaster"), "lvs" (or "lvsmaster"),
+                "natgw" (or "natgwlist");
+                or a node number (0 base); or
+                list (comma separated) of <NODES>; or
+                range (hyphen separated) of node numbers.
 EOF
     exit 1
 
@@ -55,13 +57,14 @@ current=false
 parallel=false
 verbose=false
 quiet=false
+prefix=""
 
 parse_options ()
 {
     # $POSIXLY_CORRECT means that the command passed to onnode can
     # take options and getopt won't reorder things to make them
     # options ot onnode.
-    local temp=$(POSIXLY_CORRECT=1 getopt -n "$prog" -o "chpqv" -l help -- "$@")
+    local temp=$(POSIXLY_CORRECT=1 getopt -n "$prog" -o "cho:pqv" -l help -- "$@")
 
     [ $? != 0 ] && usage
 
@@ -70,6 +73,7 @@ parse_options ()
     while true ; do
 	case "$1" in
 	    -c) current=true ; shift ;;
+	    -o) prefix="$2" ; shift 2 ;;
 	    -p) parallel=true ; shift ;;
 	    -q) quiet=true ; shift ;;
 	    -v) verbose=true ; shift ;;
@@ -84,25 +88,13 @@ parse_options ()
     command="$@"
 }
 
-# Can probably be avoided if we use bash?
-get_nth ()
+echo_nth ()
 {
     local n="$1" ; shift
 
-    local c=0
-    local j
-    for j ; do
-	if [ $n -eq $c ] ; then
-	    echo $j
-	    break
-	fi
-	c=$(($c + 1))
-    done
-}
+    shift $n
+    local node="$1"
 
-echo_nth ()
-{
-    local node=$(get_nth "$@")
     if [ -n "$node" ] ; then
 	echo $node
     else
@@ -119,7 +111,9 @@ parse_nodespec ()
 	for i in $1 ; do
 	    case "$i" in
 		*-*) seq "${i%-*}" "${i#*-}" 2>/dev/null || invalid_nodespec ;;
-		all|ok|healthy|con|connected|rm|recmaster) echo "$i" ;;
+		# Separate lines for readability.
+		all|ok|healthy|con|connected) echo "$i" ;;
+		rm|recmaster|lvs|lvsmaster|natgw|natgwlist) echo "$i" ;;
 		*)
 		    [ $i -gt -1 ] 2>/dev/null || invalid_nodespec
 		    echo $i
@@ -128,8 +122,7 @@ parse_nodespec ()
     )
 }
 
-# Cache
-ctdb_status_output=""
+ctdb_status_output="" # cache
 get_nodes_with_status ()
 {
     local all_nodes="$1"
@@ -137,10 +130,10 @@ get_nodes_with_status ()
 
     local bits
     case "$status" in
-	ok|healthy)
+	healthy)
 	    bits="0:0:0:0"
 	    ;;
-	con|connected)
+	connected)
 	    bits="0:[0-1]:[0-1]:[0-1]"
 	    ;;
 	*)
@@ -164,8 +157,8 @@ get_nodes_with_status ()
 	local t="${i%:${bits}:}"
 	if [ "$t" != "$i" ] ; then
 	    # Succeeded.  Get address.  NOTE: this is an optimisation.
-	    # It might be better to get the node number and then use
-	    # get_nth() to get the address.  This would make things
+	    # It might be better to get the node number and then get
+	    # the nth node to get the address.  This would make things
 	    # more consistent if /etc/ctdb/nodes actually contained
 	    # hostnames.
 	    nodes="${nodes} ${t##*:}"
@@ -175,7 +168,36 @@ get_nodes_with_status ()
     echo $nodes
 }
 
-ctdb_recmaster=""
+ctdb_props="" # cache
+get_node_with_property ()
+{
+    local all_nodes="$1"
+    local prop="$2"
+
+    local prop_node=""
+    if [ "${ctdb_props##:${prop}:}" = "$ctdb_props" ] ; then
+	prop_node=$(ctdb "$prop" -Y 2>/dev/null)
+	# We only want the first line.
+	local nl="
+"
+	prop_node="${prop_node%%${nl}*}"
+	if [ $? -eq 0 ] ; then
+	    ctdb_props="${ctdb_props}${ctdb_props:+ }:${prop}:${prop_node}"
+	else
+	    prop_node=""
+	fi
+    else
+	prop_node="${ctdb_props##:${prop}:}"
+	prop_node="${prop_node%% *}"
+    fi
+    if [ -n "$prop_node" ] ; then
+	echo_nth "$prop_node" $all_nodes
+    else
+	echo "${prog}: No ${prop} available" >&2
+	exit 1
+    fi
+}
+
 get_nodes ()
 {
     local all_nodes
@@ -194,21 +216,20 @@ get_nodes ()
 	case "$n" in
 	    all)
 		echo $all_nodes ;;
-	    ok|healthy|con|connected) 
-		get_nodes_with_status "$all_nodes" "$n" || exit 1
+	    ok|healthy) 
+		get_nodes_with_status "$all_nodes" "healthy" || exit 1
+		;;
+	    con|connected) 
+		get_nodes_with_status "$all_nodes" "connected" || exit 1
 		;;
 	    rm|recmaster)
-		if [ -z "$ctdb_recmaster" ] ; then
-		    ctdb_recmaster=$(ctdb recmaster 2>/dev/null)
-		    [ $? -eq 0 ] || ctdb_recmaster=""
-		fi
-		if [ -n "$ctdb_recmaster" ] ; then
-		    echo_nth "$ctdb_recmaster" $all_nodes
-		else
-		    echo "${prog}: No recmaster available" >&2
-		    exit 1
-		fi
-		
+		get_node_with_property "$all_nodes" "recmaster" || exit 1
+		;;
+	    lvs|lvsmaster)
+		get_node_with_property "$all_nodes" "lvsmaster" || exit 1
+		;;
+	    natgw|natgwlist)
+		get_node_with_property "$all_nodes" "natgwlist" || exit 1
 		;;
 	    *)
 		echo_nth $n $all_nodes
@@ -222,6 +243,26 @@ fakessh ()
     CTDB_SOCKET="$1" sh -c "$2"
 }
 
+stdout_filter ()
+{
+    if [ -n "$prefix" ] ; then
+	cat >"${prefix}.${n}"
+    elif $verbose && $parallel ; then
+	sed -e "s@^@[$n] @"
+    else
+	cat
+    fi
+}
+
+stderr_filter ()
+{
+    if $verbose && $parallel ; then
+	sed -e "s@^@[$n] @"
+    else
+	cat
+    fi
+}
+
 ######################################################################
 
 parse_options "$@"
@@ -263,21 +304,16 @@ trap 'kill -TERM $pids 2>/dev/null' INT TERM
 # the part of the window where it matter is very small.
 retcode=0
 for n in $nodes ; do
+    set -o pipefail 2>/dev/null
     if $parallel ; then
-	if $verbose ; then
-	    # pipefail is a bashism - is there some way to do this with plain sh?
-	    set -o pipefail 2>/dev/null
-	    ($SSH $ssh_opts $EXTRA_SSH_OPTS $n "$command" 2>&1 | sed -e "s@^@[$n] @" )&
-	else
-	    $SSH $ssh_opts $EXTRA_SSH_OPTS $n "$command" &
-	fi
+	{ exec 3>&1 ; { $SSH $ssh_opts $EXTRA_SSH_OPTS $n "$command" | stdout_filter >&3 ; } 2>&1 | stderr_filter ; } &
 	pids="${pids} $!"
     else
 	if $verbose ; then
 	    echo >&2 ; echo ">> NODE: $n <<" >&2
 	fi
 
-	$SSH $ssh_opts $EXTRA_SSH_OPTS $n "$command" 
+	{ exec 3>&1 ; { $SSH $ssh_opts $EXTRA_SSH_OPTS $n "$command" | stdout_filter >&3 ; } 2>&1 | stderr_filter ; }
 	[ $? = 0 ] || retcode=$?
     fi
 done


-- 
CTDB repository


More information about the samba-cvs mailing list