[SCM] CTDB repository - branch master updated - 4bc20ac73e9fa94ffd43cccb6eeb438eeff9963c

Ronnie Sahlberg sahlberg at samba.org
Tue Feb 19 04:02:59 GMT 2008


The branch, master has been updated
       via  4bc20ac73e9fa94ffd43cccb6eeb438eeff9963c (commit)
       via  644a7248548260d37df432979b129797750907f4 (commit)
       via  792d5471ff0c2947b6e66183925860de27f30eaf (commit)
       via  d0e6dcbadaf41745d423640e5ff5bafd9f68eb88 (commit)
       via  d8953c89adc7d11d2fecc61323b7e1456b56fcaa (commit)
       via  3b797d851bd4bdb8ec2b3981061c668d2cf0f97c (commit)
       via  f6cc6bd1f62138fbf812d1917f7341e2fa2323da (commit)
      from  ca266a989ba1c6fcac48b1739e7cff7766481df7 (commit)

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


- Log -----------------------------------------------------------------
commit 4bc20ac73e9fa94ffd43cccb6eeb438eeff9963c
Author: Ronnie Sahlberg <sahlberg at samba.org>
Date:   Tue Feb 19 14:44:48 2008 +1100

    to make it easier/less disruptive to add nodes to a running cluster
    
    add a new control that causes the node to drop the current nodes list
    and reread it from the nodes file.
    During this operation, the node will also drop the tcp layer and restart it.
    
    When we drop the tcp layer, by talloc_free()ing the ctcp structure
    add a destructor to ctcp so that we also can clean up and remove the references in the ctdb structure to the transport layer
    
    add two new commands for the ctdb tool.
    one to list all nodes in the nodesfile and the second a command to trigger a node to drop the transport and reinitialize it with the nde nodes file

commit 644a7248548260d37df432979b129797750907f4
Author: Ronnie Sahlberg <sahlberg at samba.org>
Date:   Tue Feb 19 14:35:15 2008 +1100

    the ctdb structure must make its own copy of the ->address field and not just
    copy the content of the nodes structure.
    
    this ctdb_address structure contains a pointer which is talloced hanging off the structure itself.
    If we copy the content of this structure as we did in assigning to ctdb->address from nodes[i]
    then if we talloc_free() the node structure we end up with a wild pointer in ctdb->address

commit 792d5471ff0c2947b6e66183925860de27f30eaf
Author: Ronnie Sahlberg <sahlberg at samba.org>
Date:   Mon Feb 18 19:38:04 2008 +1100

    read the current debuglevel in each loop in the recovery daemon so that we
    pick up when they change in the parent daemon

commit d0e6dcbadaf41745d423640e5ff5bafd9f68eb88
Author: Ronnie Sahlberg <sahlberg at samba.org>
Date:   Wed Feb 13 08:20:20 2008 +1100

    from Mathieu PARENT <math.parent at gmail.com>
    
    Simulate "nice service" on systems that do not have "service"

commit d8953c89adc7d11d2fecc61323b7e1456b56fcaa
Author: Ronnie Sahlberg <sahlberg at samba.org>
Date:   Wed Feb 13 08:17:53 2008 +1100

    From Mathieu PARENT <math.parent at gmail.com>
    
    Set the correct permissions for events.d/README

commit 3b797d851bd4bdb8ec2b3981061c668d2cf0f97c
Author: Ronnie Sahlberg <sahlberg at samba.org>
Date:   Mon Feb 11 09:52:09 2008 +1100

    add helpers to stop/start nfs lockmanager on different platforms

commit f6cc6bd1f62138fbf812d1917f7341e2fa2323da
Author: Ronnie Sahlberg <sahlberg at samba.org>
Date:   Mon Feb 11 09:35:37 2008 +1100

    create a startstop_nfs function that can start/stop the nfs service of different platforms

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

Summary of changes:
 Makefile.in              |    2 +-
 client/ctdb_client.c     |   21 ++++++++++
 config/events.d/50.samba |    2 +-
 config/events.d/60.nfs   |   13 ++----
 config/functions         |   96 ++++++++++++++++++++++++++++++++++++++++++++++
 config/statd-callout     |    4 +-
 include/ctdb.h           |    3 +
 include/ctdb_private.h   |    5 ++
 server/ctdb_control.c    |    4 ++
 server/ctdb_recover.c    |   36 +++++++++++++++++
 server/ctdb_recoverd.c   |   15 +++++++
 server/ctdb_server.c     |    4 ++
 server/ctdbd.c           |   15 +++++--
 tcp/ctdb_tcp.h           |    1 +
 tcp/tcp_connect.c        |    5 +-
 tcp/tcp_init.c           |   20 +++++++++-
 tools/ctdb.c             |   42 ++++++++++++++++++++
 17 files changed, 268 insertions(+), 20 deletions(-)


Changeset truncated at 500 lines:

diff --git a/Makefile.in b/Makefile.in
index ff91147..161e2e9 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -178,7 +178,7 @@ install: all
 	${INSTALLCMD} -m 644 include/ctdb_private.h $(DESTDIR)$(includedir) # for samba3
 	${INSTALLCMD} -m 755 config/functions $(DESTDIR)$(etcdir)/ctdb
 	${INSTALLCMD} -m 755 config/statd-callout $(DESTDIR)$(etcdir)/ctdb
-	${INSTALLCMD} -m 755 config/events.d/README $(DESTDIR)$(etcdir)/ctdb/events.d
+	${INSTALLCMD} -m 644 config/events.d/README $(DESTDIR)$(etcdir)/ctdb/events.d
 	${INSTALLCMD} -m 755 config/events.d/00.ctdb $(DESTDIR)$(etcdir)/ctdb/events.d
 	${INSTALLCMD} -m 755 config/events.d/10.interface $(DESTDIR)$(etcdir)/ctdb/events.d
 	${INSTALLCMD} -m 755 config/events.d/40.vsftpd $(DESTDIR)$(etcdir)/ctdb/events.d
diff --git a/client/ctdb_client.c b/client/ctdb_client.c
index 1cdfee5..df328c0 100644
--- a/client/ctdb_client.c
+++ b/client/ctdb_client.c
@@ -1242,6 +1242,27 @@ int ctdb_ctrl_getnodemap(struct ctdb_context *ctdb,
 }
 
 /*
+  drop the transport, reload the nodes file and restart the transport
+ */
+int ctdb_ctrl_reload_nodes_file(struct ctdb_context *ctdb, 
+		    struct timeval timeout, uint32_t destnode)
+{
+	int ret;
+	int32_t res;
+
+	ret = ctdb_control(ctdb, destnode, 0, 
+			   CTDB_CONTROL_RELOAD_NODES_FILE, 0, tdb_null, 
+			   NULL, NULL, &res, &timeout, NULL);
+	if (ret != 0 || res != 0) {
+		DEBUG(DEBUG_ERR,(__location__ " ctdb_control for reloadnodesfile failed\n"));
+		return -1;
+	}
+
+	return 0;
+}
+
+
+/*
   set vnn map on a node
  */
 int ctdb_ctrl_setvnnmap(struct ctdb_context *ctdb, struct timeval timeout, uint32_t destnode, 
diff --git a/config/events.d/50.samba b/config/events.d/50.samba
index ed1136f..c67dbda 100755
--- a/config/events.d/50.samba
+++ b/config/events.d/50.samba
@@ -66,7 +66,7 @@ case $cmd in
 	# start Samba service. Start it reniced, as under very heavy load 
 	# the number of smbd processes will mean that it leaves few cycles for
 	# anything else
-	nice service smb start
+	nice_service smb start
 	;;
 	
      takeip)
diff --git a/config/events.d/60.nfs b/config/events.d/60.nfs
index 09a09a2..c84e7be 100755
--- a/config/events.d/60.nfs
+++ b/config/events.d/60.nfs
@@ -12,6 +12,8 @@ shift
 
 PATH=/usr/bin:/bin:/usr/sbin:/sbin:$PATH
 
+
+
 case $cmd in 
      startup)
 	/bin/mkdir -p $CTDB_BASE/state/nfs
@@ -21,17 +23,12 @@ case $cmd in
 	/bin/rm -f $CTDB_BASE/state/statd/statd.restart >/dev/null 2>/dev/null
 
 	# make sure nfs is stopped before we start it, or it may get a bind error
-	service nfs stop > /dev/null 2>&1
-	service nfslock stop > /dev/null 2>&1
-
-	service nfslock start
-	service nfs start
+	startstop_nfs stop
+	startstop_nfs start
 	;;
 
      shutdown)
-	# shutting down nfs can take a while so put it in the background
-	service nfs stop &
-	service nfslock stop &
+	startstop_nfs stop
 	exit 0
 	;;
 
diff --git a/config/functions b/config/functions
index e60427f..9b33422 100644
--- a/config/functions
+++ b/config/functions
@@ -28,6 +28,19 @@ service() {
   fi
 }
 
+######################################################
+# simulate /sbin/service (niced) on platforms that don't have it
+nice_service() { 
+  service_name="$1"
+  op="$2"
+  if [ -x /sbin/service ]; then
+      nice /sbin/service "$service_name" "$op"
+  elif [ -x /etc/init.d/$service_name ]; then
+      nice /etc/init.d/$service_name "$op"
+  elif [ -x /etc/rc.d/init.d/$service_name ]; then
+      nice /etc/rc.d/init.d/$service_name "$op"
+  fi
+}
 
 ######################################################
 # wait for a command to return a zero exit status
@@ -227,3 +240,86 @@ kill_tcp_connections() {
     echo "killed $_killcount TCP connections to released IP $_IP"
 }
 
+########################################################
+# start/stop the nfs service on different platforms
+########################################################
+startstop_nfs() {
+	PLATFORM="unknown"
+	[ -x /etc/init.d/nfsserver ] && {
+		PLATFORM="sles"
+	}
+	[ -x /etc/init.d/nfslock ] && {
+		PLATFORM="rhel"
+	}
+
+	case $PLATFORM in
+	sles)
+		case $1 in
+		start)
+			service nfsserver start
+			;;
+		stop)
+			service nfsserver stop > /dev/null 2>&1
+			;;
+		esac
+		;;
+	rhel)
+		case $1 in
+		start)
+			service nfslock start
+			service nfs start
+			;;
+		stop)
+			service nfs stop > /dev/null 2>&1
+			service nfslock stop > /dev/null 2>&1
+			;;
+		esac
+		;;
+	*)
+		echo "Unknown platform. NFS is not supported with ctdb"
+		exit 1
+		;;
+	esac
+}
+
+########################################################
+# start/stop the nfs lockmanager service on different platforms
+########################################################
+startstop_nfslock() {
+	PLATFORM="unknown"
+	[ -x /etc/init.d/nfsserver ] && {
+		PLATFORM="sles"
+	}
+	[ -x /etc/init.d/nfslock ] && {
+		PLATFORM="rhel"
+	}
+
+	case $PLATFORM in
+	sles)
+		# for sles there is no service for lockmanager
+		# so we instead just shutdown/restart nfs
+		case $1 in
+		start)
+			service nfsserver start
+			;;
+		stop)
+			service nfsserver stop > /dev/null 2>&1
+			;;
+		esac
+		;;
+	rhel)
+		case $1 in
+		start)
+			service nfslock start
+			;;
+		stop)
+			service nfslock stop > /dev/null 2>&1
+			;;
+		esac
+		;;
+	*)
+		echo "Unknown platform. NFS locking is not supported with ctdb"
+		exit 1
+		;;
+	esac
+}
diff --git a/config/statd-callout b/config/statd-callout
index 1e3168d..a18890b 100755
--- a/config/statd-callout
+++ b/config/statd-callout
@@ -81,7 +81,7 @@ case "$1" in
 	# will respond "strangely" immediately after restarting it, which
 	# causes clients to fail to reclaim the locks.
 	# 
-	service nfslock stop > /dev/null 2>&1
+	startstop_nfslock stop > /dev/null 2>&1
 	sleep 2
 
 	# copy all monitored clients on this node to the local lockmanager
@@ -96,7 +96,7 @@ case "$1" in
 	done
 
 	# now start lockmanager again with the new state directory.
-	service nfslock start > /dev/null 2>&1
+	startstop_nfslock start > /dev/null 2>&1
 
 	# we now need to send out additional statd notifications to ensure
 	# that clients understand that the lockmanager has restarted.
diff --git a/include/ctdb.h b/include/ctdb.h
index d9bf992..d7f754f 100644
--- a/include/ctdb.h
+++ b/include/ctdb.h
@@ -295,6 +295,9 @@ int ctdb_ctrl_getnodemap(struct ctdb_context *ctdb,
 		    struct timeval timeout, uint32_t destnode, 
 		    TALLOC_CTX *mem_ctx, struct ctdb_node_map **nodemap);
 
+int ctdb_ctrl_reload_nodes_file(struct ctdb_context *ctdb, 
+		    struct timeval timeout, uint32_t destnode);
+
 struct ctdb_key_list {
 	uint32_t dbid;
 	uint32_t num;
diff --git a/include/ctdb_private.h b/include/ctdb_private.h
index ab87592..c34a9d9 100644
--- a/include/ctdb_private.h
+++ b/include/ctdb_private.h
@@ -490,6 +490,7 @@ enum ctdb_controls {CTDB_CONTROL_PROCESS_EXISTS          = 0,
 		    CTDB_CONTROL_UPTIME                  = 69,
 		    CTDB_CONTROL_START_RECOVERY          = 70,
 		    CTDB_CONTROL_END_RECOVERY            = 71,
+		    CTDB_CONTROL_RELOAD_NODES_FILE       = 72,
 };	
 
 /*
@@ -1244,5 +1245,9 @@ int ctdb_client_async_control(struct ctdb_context *ctdb,
 				bool dont_log_errors,
 				TDB_DATA data);
 
+void ctdb_load_nodes_file(struct ctdb_context *ctdb);
+
+int ctdb_control_reload_nodes_file(struct ctdb_context *ctdb, uint32_t opcode);
+
 
 #endif
diff --git a/server/ctdb_control.c b/server/ctdb_control.c
index 3ea8f16..dc890cf 100644
--- a/server/ctdb_control.c
+++ b/server/ctdb_control.c
@@ -134,6 +134,10 @@ static int32_t ctdb_control_dispatch(struct ctdb_context *ctdb,
 	case CTDB_CONTROL_GET_NODEMAP:
 		return ctdb_control_getnodemap(ctdb, opcode, indata, outdata);
 
+	case CTDB_CONTROL_RELOAD_NODES_FILE:
+		CHECK_CONTROL_DATA_SIZE(0);
+		return ctdb_control_reload_nodes_file(ctdb, opcode);
+
 	case CTDB_CONTROL_SETVNNMAP:
 		return ctdb_control_setvnnmap(ctdb, opcode, indata, outdata);
 
diff --git a/server/ctdb_recover.c b/server/ctdb_recover.c
index c3a0caf..96882db 100644
--- a/server/ctdb_recover.c
+++ b/server/ctdb_recover.c
@@ -171,6 +171,42 @@ ctdb_control_getnodemap(struct ctdb_context *ctdb, uint32_t opcode, TDB_DATA ind
 	return 0;
 }
 
+static void
+ctdb_reload_nodes_event(struct event_context *ev, struct timed_event *te, 
+			       struct timeval t, void *private_data)
+{
+	int ret;
+	struct ctdb_context *ctdb = talloc_get_type(private_data, struct ctdb_context);
+	int ctdb_tcp_init(struct ctdb_context *);
+
+	/* shut down the transport */
+	ctdb->methods->shutdown(ctdb);
+
+	/* start the transport again */
+	ctdb_load_nodes_file(ctdb);
+	ret = ctdb_tcp_init(ctdb);
+	if (ret != 0) {
+		DEBUG(DEBUG_CRIT, (__location__ " Failed to init TCP\n"));
+		exit(1);
+	}
+	ctdb->methods->initialise(ctdb);
+	ctdb->methods->start(ctdb);
+
+	return;
+}
+
+/*
+  reload the nodes file after a short delay (so that we can send the response
+  back first
+*/
+int 
+ctdb_control_reload_nodes_file(struct ctdb_context *ctdb, uint32_t opcode)
+{
+	event_add_timed(ctdb->ev, ctdb, timeval_current_ofs(1,0), ctdb_reload_nodes_event, ctdb);
+
+	return 0;
+}
+
 /* 
    a traverse function for pulling all relevent records from pulldb
  */
diff --git a/server/ctdb_recoverd.c b/server/ctdb_recoverd.c
index 7367093..430dac8 100644
--- a/server/ctdb_recoverd.c
+++ b/server/ctdb_recoverd.c
@@ -1399,6 +1399,8 @@ static int do_recovery(struct ctdb_recoverd *rec,
 		DEBUG(DEBUG_INFO, (__location__ " Recovery - done takeover\n"));
 	}
 
+	DEBUG(DEBUG_NOTICE, (__location__ " Recovery - takeip finished\n"));
+
 	/* execute the "recovered" event script on all nodes */
 	ret = run_recovered_eventscript(ctdb, nodemap);
 	if (ret!=0) {
@@ -1406,6 +1408,8 @@ static int do_recovery(struct ctdb_recoverd *rec,
 		return -1;
 	}
 
+	DEBUG(DEBUG_NOTICE, (__location__ " Recovery - finished the recovered event\n"));
+
 	/* disable recovery mode */
 	ret = set_recovery_mode(ctdb, nodemap, CTDB_RECOVERY_NORMAL);
 	if (ret!=0) {
@@ -1413,6 +1417,8 @@ static int do_recovery(struct ctdb_recoverd *rec,
 		return -1;
 	}
 
+	DEBUG(DEBUG_NOTICE, (__location__ " Recovery - disabled recovery mode\n"));
+
 	/* send a message to all clients telling them that the cluster 
 	   has been reconfigured */
 	ctdb_send_message(ctdb, CTDB_BROADCAST_CONNECTED, CTDB_SRVID_RECONFIGURE, tdb_null);
@@ -1963,6 +1969,7 @@ static void monitor_cluster(struct ctdb_context *ctdb)
 	struct ctdb_node_map *remote_nodemap=NULL;
 	struct ctdb_vnn_map *vnnmap=NULL;
 	struct ctdb_vnn_map *remote_vnnmap=NULL;
+	int32_t debug_level;
 	int i, j, ret;
 	struct ctdb_recoverd *rec;
 	struct ctdb_all_public_ips *ips;
@@ -2019,6 +2026,14 @@ again:
 		goto again;
 	}
 
+	/* read the debug level from the parent and update locally */
+	ret = ctdb_ctrl_get_debuglevel(ctdb, CTDB_CURRENT_NODE, &debug_level);
+	if (ret !=0) {
+		DEBUG(DEBUG_ERR, (__location__ " Failed to read debuglevel from parent\n"));
+		goto again;
+	}
+	LogLevel = debug_level;
+
 
 	/* We must check if we need to ban a node here but we want to do this
 	   as early as possible so we dont wait until we have pulled the node
diff --git a/server/ctdb_server.c b/server/ctdb_server.c
index d97e3cb..47a65c9 100644
--- a/server/ctdb_server.c
+++ b/server/ctdb_server.c
@@ -134,6 +134,10 @@ int ctdb_set_nlist(struct ctdb_context *ctdb, const char *nlist)
 	int nlines;
 	int i;
 
+	talloc_free(ctdb->nodes);
+	ctdb->nodes     = NULL;
+	ctdb->num_nodes = 0;
+
 	talloc_free(ctdb->node_list_file);
 	ctdb->node_list_file = talloc_strdup(ctdb, nlist);
 
diff --git a/server/ctdbd.c b/server/ctdbd.c
index a40c4ef..ca366fc 100644
--- a/server/ctdbd.c
+++ b/server/ctdbd.c
@@ -73,7 +73,16 @@ static void ctdb_recv_pkt(struct ctdb_context *ctdb, uint8_t *data, uint32_t len
 	ctdb_input_pkt(ctdb, hdr);
 }
 
+void ctdb_load_nodes_file(struct ctdb_context *ctdb)
+{
+	int ret;
 
+	ret = ctdb_set_nlist(ctdb, options.nlist);
+	if (ret == -1) {
+		DEBUG(DEBUG_ALERT,("ctdb_set_nlist failed - %s\n", ctdb_errstr(ctdb)));
+		exit(1);
+	}
+}
 
 static const struct ctdb_upcalls ctdb_upcalls = {
 	.recv_pkt       = ctdb_recv_pkt,
@@ -188,11 +197,7 @@ int main(int argc, const char *argv[])
 	}
 
 	/* tell ctdb what nodes are available */
-	ret = ctdb_set_nlist(ctdb, options.nlist);
-	if (ret == -1) {
-		DEBUG(DEBUG_ALERT,("ctdb_set_nlist failed - %s\n", ctdb_errstr(ctdb)));
-		exit(1);
-	}
+	ctdb_load_nodes_file(ctdb);
 
 	/* if a node-ip was specified, verify that it exists in the
 	   nodes file
diff --git a/tcp/ctdb_tcp.h b/tcp/ctdb_tcp.h
index 7d47cbc..9a17bd6 100644
--- a/tcp/ctdb_tcp.h
+++ b/tcp/ctdb_tcp.h
@@ -20,6 +20,7 @@
 
 /* ctdb_tcp main state */
 struct ctdb_tcp {
+	struct ctdb_context *ctdb;
 	int listen_fd;
 };
 
diff --git a/tcp/tcp_connect.c b/tcp/tcp_connect.c
index 1bad440..f85e3df 100644
--- a/tcp/tcp_connect.c
+++ b/tcp/tcp_connect.c
@@ -302,7 +302,8 @@ static int ctdb_tcp_listen_automatic(struct ctdb_context *ctdb)
 		DEBUG(DEBUG_CRIT,("Unable to bind to any of the node addresses - giving up\n"));
 		goto failed;
 	}
-	ctdb->address = ctdb->nodes[i]->address;
+	ctdb->address.address = talloc_strdup(ctdb, ctdb->nodes[i]->address.address);
+	ctdb->address.port    = ctdb->nodes[i]->address.port;
 	ctdb->name = talloc_asprintf(ctdb, "%s:%u", 
 				     ctdb->address.address, 
 				     ctdb->address.port);
@@ -363,7 +364,7 @@ int ctdb_tcp_listen(struct ctdb_context *ctdb)
 #endif
 	sock.sin_port = htons(ctdb->address.port);
 	sock.sin_family = PF_INET;
-	
+
 	if (ctdb_tcp_get_address(ctdb, ctdb->address.address, 
 				 &sock.sin_addr) != 0) {
 		goto failed;
diff --git a/tcp/tcp_init.c b/tcp/tcp_init.c
index 624f650..527373c 100644
--- a/tcp/tcp_init.c
+++ b/tcp/tcp_init.c
@@ -54,7 +54,10 @@ static int ctdb_tcp_initialise(struct ctdb_context *ctdb)
 	int i;
 
 	/* listen on our own address */
-	if (ctdb_tcp_listen(ctdb) != 0) return -1;
+	if (ctdb_tcp_listen(ctdb) != 0) {
+		DEBUG(DEBUG_CRIT, (__location__ " Failed to start listening on the CTDB socket\n"));
+		exit(1);
+	}
 
 	for (i=0; i<ctdb->num_nodes; i++) {
 		if (ctdb_tcp_add_node(ctdb->nodes[i]) != 0) {
@@ -142,6 +145,18 @@ static const struct ctdb_methods ctdb_tcp_methods = {
 	.restart      = ctdb_tcp_restart,
 };
 
+static int tcp_ctcp_destructor(struct ctdb_tcp *ctcp)
+{
+	if (ctcp->listen_fd) {
+		close(ctcp->listen_fd);
+	}
+	ctcp->ctdb->private_data = NULL;
+	ctcp->ctdb->methods = NULL;
+	
+	return 0;
+}
+
+		
 /*
   initialise tcp portion of ctdb 
 */
@@ -152,8 +167,11 @@ int ctdb_tcp_init(struct ctdb_context *ctdb)
 	CTDB_NO_MEMORY(ctdb, ctcp);
 
 	ctcp->listen_fd = -1;


-- 
CTDB repository


More information about the samba-cvs mailing list