[SCM] CTDB repository - branch master updated - b2ccb891b81b041e2186e038b67bb4354b7892aa

Ronnie Sahlberg sahlberg at samba.org
Thu Jul 10 01:48:26 GMT 2008


The branch, master has been updated
       via  b2ccb891b81b041e2186e038b67bb4354b7892aa (commit)
       via  00025eef662b867293829228c681df491cd6f371 (commit)
       via  172d01fb34f032e098b1c77a7b0f17bf11301640 (commit)
      from  dd900d4ed8f07003c4f1db2d441cfc2ef2c89ef5 (commit)

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


- Log -----------------------------------------------------------------
commit b2ccb891b81b041e2186e038b67bb4354b7892aa
Author: Ronnie Sahlberg <ronniesahlberg at gmail.com>
Date:   Thu Jul 10 11:42:37 2008 +1000

    Update to the LVS eventscript.
    Do not assume all nodes are members of LVS so always deciding the recmaster will be lvsmaster wont work.
    
    Instead,
    Create the set of active LVS nodes as those nodes that are LVS capable and
    also HEALTHY.
    Except if ALL LVS capable nodes are unhealthy in which case we allow the unhealthy
    nodes to be part of the active set.
    
    In the active set, pick one of the active nodes as being the lvsmaster
    which will receive all incoming traffic and distribute it across
    the active lvs nodes in the cluster.

commit 00025eef662b867293829228c681df491cd6f371
Author: Ronnie Sahlberg <ronniesahlberg at gmail.com>
Date:   Thu Jul 10 11:12:58 2008 +1000

    Add three mode commands to the CTDB tool.
    
    lvs: which shows which nodes are active LVS servers
    lvsmaster: which shows which node is the lvs master multiplex node
    pnn: which prints the pnn of the local node

commit 172d01fb34f032e098b1c77a7b0f17bf11301640
Author: Ronnie Sahlberg <ronniesahlberg at gmail.com>
Date:   Thu Jul 10 10:37:22 2008 +1000

    make LVS a capability so that we can see which nodes are configured with
    LVS and which are not using LVS.
    
    "ctdb getcapabilities"

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

Summary of changes:
 config/ctdb.init       |    3 +
 config/events.d/91.lvs |   11 +++-
 include/ctdb_private.h |    2 +
 server/ctdbd.c         |    5 ++
 tools/ctdb.c           |  164 +++++++++++++++++++++++++++++++++++++++++++++++-
 5 files changed, 179 insertions(+), 6 deletions(-)


Changeset truncated at 500 lines:

diff --git a/config/ctdb.init b/config/ctdb.init
index 760d6de..72de84d 100755
--- a/config/ctdb.init
+++ b/config/ctdb.init
@@ -72,6 +72,9 @@ CTDB_OPTIONS="$CTDB_OPTIONS --reclock=$CTDB_RECOVERY_LOCK"
 [ -z "$CTDB_CAPABILITY_LMASTER" ] || [ "$CTDB_CAPABILITY_LMASTER" != "no" ] || {
 	CTDB_OPTIONS="$CTDB_OPTIONS --no-lmaster"
 }
+[ -z "$CTDB_LVS_PUBLIC_IP" ] || {
+	CTDB_OPTIONS="$CTDB_OPTIONS --lvs"
+}
 
 if [ "$CTDB_VALGRIND" = "yes" ]; then
     init_style="valgrind"
diff --git a/config/events.d/91.lvs b/config/events.d/91.lvs
index 678215b..4860030 100755
--- a/config/events.d/91.lvs
+++ b/config/events.d/91.lvs
@@ -54,8 +54,11 @@ case $cmd in
 	ipvsadm -D -u $CTDB_LVS_PUBLIC_IP:0
 	kill_tcp_connections $CTDB_LVS_PUBLIC_IP
 
-	# are we the recmaster ? 
-	ctdb isnotrecmaster >/dev/null 2>/dev/null || {
+	PNN=`ctdb pnn | sed -e "s/.*PNN://"`
+	LVSMASTER=`ctdb lvsmaster | sed -e "s/.*Node //" -e "s/ .*//"`
+
+	[ "$PNN" != "$LVSMASTER" ] && {
+	    # we are not the lvs master so we have to
 	    # change the ip address to have scope host so we wont respond
 	    # to arps
 	    ip addr del $CTDB_LVS_PUBLIC_IP/32 dev lo >/dev/null 2>/dev/null
@@ -70,10 +73,12 @@ case $cmd in
 	ipvsadm -A -t $CTDB_LVS_PUBLIC_IP:0 -p 9999 -s lc
 	ipvsadm -A -u $CTDB_LVS_PUBLIC_IP:0 -p 9999 -s lc
 
-	ctdb status 2>/dev/null | egrep "^pnn:" | grep -v DISCONNECTED | grep -v "(THIS NODE)" | sed -e "s/^pnn:[0-9]* //" -e "s/[ 	].*//" | while read IP; do
+	# add all nodes (except ourselves) to the lvs config
+	ctdb lvs | egrep -v "^$PNN:" | sed -e "s/.*://" | while read IP; do
 		ipvsadm -a -t $CTDB_LVS_PUBLIC_IP:0 -r $IP -g
 		ipvsadm -a -u $CTDB_LVS_PUBLIC_IP:0 -r $IP -g
 	done
+	# and add the localhost too
 	ipvsadm -a -t $CTDB_LVS_PUBLIC_IP:0 -r 127.0.0.1
 	ipvsadm -a -u $CTDB_LVS_PUBLIC_IP:0 -r 127.0.0.1
 
diff --git a/include/ctdb_private.h b/include/ctdb_private.h
index ad4805f..4124f64 100644
--- a/include/ctdb_private.h
+++ b/include/ctdb_private.h
@@ -355,6 +355,8 @@ enum ctdb_freeze_mode {CTDB_FREEZE_NONE, CTDB_FREEZE_PENDING, CTDB_FREEZE_FROZEN
 /* The different capabilities of the ctdb daemon. */
 #define CTDB_CAP_RECMASTER		0x00000001
 #define CTDB_CAP_LMASTER		0x00000002
+/* This capability is set if CTDB_LVS_PUBLIC_IP is set */
+#define CTDB_CAP_LVS			0x00000004
 
 /* main state of the ctdb daemon */
 struct ctdb_context {
diff --git a/server/ctdbd.c b/server/ctdbd.c
index aa5253a..b797904 100644
--- a/server/ctdbd.c
+++ b/server/ctdbd.c
@@ -45,6 +45,7 @@ static struct {
 	int         start_as_disabled;
 	int         no_lmaster;
 	int         no_recmaster;
+	int         lvs;
 } options = {
 	.nlist = ETCDIR "/ctdb/nodes",
 	.transport = "tcp",
@@ -124,6 +125,7 @@ int main(int argc, const char *argv[])
 		{ "start-as-disabled", 0, POPT_ARG_NONE, &options.start_as_disabled, 0, "Node starts in disabled state", NULL },
 		{ "no-lmaster", 0, POPT_ARG_NONE, &options.no_lmaster, 0, "disable lmaster role on this node", NULL },
 		{ "no-recmaster", 0, POPT_ARG_NONE, &options.no_recmaster, 0, "disable recmaster role on this node", NULL },
+		{ "lvs", 0, POPT_ARG_NONE, &options.lvs, 0, "lvs is enabled on this node", NULL },
 		POPT_TABLEEND
 	};
 	int opt, ret;
@@ -213,6 +215,9 @@ int main(int argc, const char *argv[])
 	if (options.no_recmaster == 0) {
 		ctdb->capabilities |= CTDB_CAP_RECMASTER;
 	}
+	if (options.lvs != 0) {
+		ctdb->capabilities |= CTDB_CAP_LVS;
+	}
 
 	/* tell ctdb what nodes are available */
 	ctdb_load_nodes_file(ctdb);
diff --git a/tools/ctdb.c b/tools/ctdb.c
index 1d77707..22671a7 100644
--- a/tools/ctdb.c
+++ b/tools/ctdb.c
@@ -289,6 +289,23 @@ static int control_uptime(struct ctdb_context *ctdb, int argc, const char **argv
 }
 
 /*
+  show the PNN of the current node
+ */
+static int control_pnn(struct ctdb_context *ctdb, int argc, const char **argv)
+{
+	int mypnn;
+
+	mypnn = ctdb_ctrl_getpnn(ctdb, TIMELIMIT(), CTDB_CURRENT_NODE);
+	if (mypnn == -1) {
+		DEBUG(DEBUG_ERR, ("Unable to get pnn from local node."));
+		return -1;
+	}
+
+	printf("PNN:%d\n", mypnn);
+	return 0;
+}
+
+/*
   display remote ctdb status
  */
 static int control_status(struct ctdb_context *ctdb, int argc, const char **argv)
@@ -1226,12 +1243,150 @@ static int control_getcapabilities(struct ctdb_context *ctdb, int argc, const ch
 	if (!options.machinereadable){
 		printf("RECMASTER: %s\n", (capabilities&CTDB_CAP_RECMASTER)?"YES":"NO");
 		printf("LMASTER: %s\n", (capabilities&CTDB_CAP_LMASTER)?"YES":"NO");
+		printf("LVS: %s\n", (capabilities&CTDB_CAP_LVS)?"YES":"NO");
 	} else {
-		printf(":RECMASTER:LMASTER:\n");
-		printf(":%d:%d:\n",
+		printf(":RECMASTER:LMASTER:LVS:\n");
+		printf(":%d:%d:%d:\n",
 			!!(capabilities&CTDB_CAP_RECMASTER),
-			!!(capabilities&CTDB_CAP_LMASTER));
+			!!(capabilities&CTDB_CAP_LMASTER),
+			!!(capabilities&CTDB_CAP_LVS));
+	}
+	return 0;
+}
+
+/*
+  display lvs configuration
+ */
+static int control_lvs(struct ctdb_context *ctdb, int argc, const char **argv)
+{
+	uint32_t *capabilities;
+	struct ctdb_node_map *nodemap=NULL;
+	int i, ret;
+	int healthy_count = 0;
+
+	ret = ctdb_ctrl_getnodemap(ctdb, TIMELIMIT(), options.pnn, ctdb, &nodemap);
+	if (ret != 0) {
+		DEBUG(DEBUG_ERR, ("Unable to get nodemap from node %u\n", options.pnn));
+		return ret;
+	}
+
+	capabilities = talloc_array(ctdb, uint32_t, nodemap->num);
+	CTDB_NO_MEMORY(ctdb, capabilities);
+	
+	/* collect capabilities for all connected nodes */
+	for (i=0; i<nodemap->num; i++) {
+		if (nodemap->nodes[i].flags & NODE_FLAGS_INACTIVE) {
+			continue;
+		}
+		if (nodemap->nodes[i].flags & NODE_FLAGS_PERMANENTLY_DISABLED) {
+			continue;
+		}
+	
+		ret = ctdb_ctrl_getcapabilities(ctdb, TIMELIMIT(), i, &capabilities[i]);
+		if (ret != 0) {
+			DEBUG(DEBUG_ERR, ("Unable to get capabilities from node %u\n", i));
+			return ret;
+		}
+
+		if (!(capabilities[i] & CTDB_CAP_LVS)) {
+			continue;
+		}
+
+		if (!(nodemap->nodes[i].flags & NODE_FLAGS_UNHEALTHY)) {
+			healthy_count++;
+		}
+	}
+
+	/* Print all LVS nodes */
+	for (i=0; i<nodemap->num; i++) {
+		if (nodemap->nodes[i].flags & NODE_FLAGS_INACTIVE) {
+			continue;
+		}
+		if (nodemap->nodes[i].flags & NODE_FLAGS_PERMANENTLY_DISABLED) {
+			continue;
+		}
+		if (!(capabilities[i] & CTDB_CAP_LVS)) {
+			continue;
+		}
+
+		if (healthy_count != 0) {
+			if (nodemap->nodes[i].flags & NODE_FLAGS_UNHEALTHY) {
+				continue;
+			}
+		}
+
+		printf("%d:%s\n", i, inet_ntoa(nodemap->nodes[i].sin.sin_addr));
+	}
+
+	return 0;
+}
+
+/*
+  display who is the lvs master
+ */
+static int control_lvsmaster(struct ctdb_context *ctdb, int argc, const char **argv)
+{
+	uint32_t *capabilities;
+	struct ctdb_node_map *nodemap=NULL;
+	int i, ret;
+	int healthy_count = 0;
+
+	ret = ctdb_ctrl_getnodemap(ctdb, TIMELIMIT(), options.pnn, ctdb, &nodemap);
+	if (ret != 0) {
+		DEBUG(DEBUG_ERR, ("Unable to get nodemap from node %u\n", options.pnn));
+		return ret;
+	}
+
+	capabilities = talloc_array(ctdb, uint32_t, nodemap->num);
+	CTDB_NO_MEMORY(ctdb, capabilities);
+	
+	/* collect capabilities for all connected nodes */
+	for (i=0; i<nodemap->num; i++) {
+		if (nodemap->nodes[i].flags & NODE_FLAGS_INACTIVE) {
+			continue;
+		}
+		if (nodemap->nodes[i].flags & NODE_FLAGS_PERMANENTLY_DISABLED) {
+			continue;
+		}
+	
+		ret = ctdb_ctrl_getcapabilities(ctdb, TIMELIMIT(), i, &capabilities[i]);
+		if (ret != 0) {
+			DEBUG(DEBUG_ERR, ("Unable to get capabilities from node %u\n", i));
+			return ret;
+		}
+
+		if (!(capabilities[i] & CTDB_CAP_LVS)) {
+			continue;
+		}
+
+		if (!(nodemap->nodes[i].flags & NODE_FLAGS_UNHEALTHY)) {
+			healthy_count++;
+		}
+	}
+
+	/* find and show the lvsmaster */
+	for (i=0; i<nodemap->num; i++) {
+		if (nodemap->nodes[i].flags & NODE_FLAGS_INACTIVE) {
+			continue;
+		}
+		if (nodemap->nodes[i].flags & NODE_FLAGS_PERMANENTLY_DISABLED) {
+			continue;
+		}
+		if (!(capabilities[i] & CTDB_CAP_LVS)) {
+			continue;
+		}
+
+		if (healthy_count != 0) {
+			if (nodemap->nodes[i].flags & NODE_FLAGS_UNHEALTHY) {
+				continue;
+			}
+		}
+
+		printf("Node %d is LVS master\n", i);
+		return 0;
 	}
+
+	printf("There is no LVS master\n");
 	return 0;
 }
 
@@ -1842,6 +1997,9 @@ static const struct {
 	{ "catdb",           control_catdb,             true,  "dump a database" ,                     "<dbname>"},
 	{ "getmonmode",      control_getmonmode,        true,  "show monitoring mode" },
 	{ "getcapabilities", control_getcapabilities,   true,  "show node capabilities" },
+	{ "pnn",             control_pnn,               true,  "show the pnn of the currnet node" },
+	{ "lvs",             control_lvs,               true,  "show lvs configuration" },
+	{ "lvsmaster",       control_lvsmaster,         true,  "show which node is the lvs master" },
 	{ "disablemonitor",      control_disable_monmode,        true,  "set monitoring mode to DISABLE" },
 	{ "enablemonitor",      control_enable_monmode,        true,  "set monitoring mode to ACTIVE" },
 	{ "setdebug",        control_setdebug,          true,  "set debug level",                      "<EMERG|ALERT|CRIT|ERR|WARNING|NOTICE|INFO|DEBUG>" },


-- 
CTDB repository


More information about the samba-cvs mailing list