[SCM] CTDB repository - branch master updated - 7e587acaf8006254e89ff9b4bf48454821c85863

Ronnie Sahlberg sahlberg at samba.org
Tue May 6 01:23:50 GMT 2008


The branch, master has been updated
       via  7e587acaf8006254e89ff9b4bf48454821c85863 (commit)
       via  34b952e4adc53ee82345275a0e28231fa1b2533e (commit)
       via  50f1255ea9ed15bb8fa11cf838b29afa77e857fd (commit)
      from  40c7a536c6b428caef7904a1de860d82a70748af (commit)

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


- Log -----------------------------------------------------------------
commit 7e587acaf8006254e89ff9b4bf48454821c85863
Author: Ronnie Sahlberg <ronniesahlberg at gmail.com>
Date:   Tue May 6 11:19:17 2008 +1000

    Monitor that the recovery daemon is still running from the main ctdb daemon
    and if it has terminated, then we shut down the main daemon as well

commit 34b952e4adc53ee82345275a0e28231fa1b2533e
Author: Ronnie Sahlberg <ronniesahlberg at gmail.com>
Date:   Tue May 6 10:41:22 2008 +1000

    Add ability to disable recmaster and lmaster roles through sysconfig file and
    command line arguments

commit 50f1255ea9ed15bb8fa11cf838b29afa77e857fd
Author: Ronnie Sahlberg <ronniesahlberg at gmail.com>
Date:   Tue May 6 10:02:27 2008 +1000

    Add a capabilities field to the ctdb structure
    
    Define two capabilities :
    can be recmaster
    can be lmaster
    Default both capabilities to YES
    
    Update the ctdb tool to read capabilities off a node

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

Summary of changes:
 client/ctdb_client.c   |   40 ++++++++++++++++++++++++++++++++++++++++
 config/ctdb.init       |    6 ++++++
 config/ctdb.sysconfig  |   17 +++++++++++++++++
 include/ctdb.h         |    9 +++++++++
 include/ctdb_private.h |    6 ++++++
 server/ctdb_control.c  |    3 +++
 server/ctdb_recoverd.c |   34 ++++++++++++++++++++++++++++++++++
 server/ctdbd.c         |   13 +++++++++++++
 tools/ctdb.c           |   27 +++++++++++++++++++++++++++
 9 files changed, 155 insertions(+), 0 deletions(-)


Changeset truncated at 500 lines:

diff --git a/client/ctdb_client.c b/client/ctdb_client.c
index 395d2d7..4f3a0d5 100644
--- a/client/ctdb_client.c
+++ b/client/ctdb_client.c
@@ -2871,3 +2871,43 @@ ctdb_read_pnn_lock(int fd, int32_t pnn)
 	return c;
 }
 
+/*
+  get capabilities of a remote node
+ */
+struct ctdb_client_control_state *
+ctdb_ctrl_getcapabilities_send(struct ctdb_context *ctdb, TALLOC_CTX *mem_ctx, struct timeval timeout, uint32_t destnode)
+{
+	return ctdb_control_send(ctdb, destnode, 0, 
+			   CTDB_CONTROL_GET_CAPABILITIES, 0, tdb_null, 
+			   mem_ctx, &timeout, NULL);
+}
+
+int ctdb_ctrl_getcapabilities_recv(struct ctdb_context *ctdb, TALLOC_CTX *mem_ctx, struct ctdb_client_control_state *state, uint32_t *capabilities)
+{
+	int ret;
+	int32_t res;
+
+	ret = ctdb_control_recv(ctdb, state, mem_ctx, NULL, &res, NULL);
+	if (ret != 0) {
+		DEBUG(DEBUG_ERR,(__location__ " ctdb_ctrl_getcapabilities_recv failed\n"));
+		return -1;
+	}
+
+	if (capabilities) {
+		*capabilities = (uint32_t)res;
+	}
+
+	return 0;
+}
+
+int ctdb_ctrl_getcapabilities(struct ctdb_context *ctdb, struct timeval timeout, uint32_t destnode, uint32_t *capabilities)
+{
+	struct ctdb_client_control_state *state;
+	TALLOC_CTX *tmp_ctx = talloc_new(NULL);
+	int ret;
+
+	state = ctdb_ctrl_getcapabilities_send(ctdb, tmp_ctx, timeout, destnode);
+	ret = ctdb_ctrl_getcapabilities_recv(ctdb, tmp_ctx, state, capabilities);
+	talloc_free(tmp_ctx);
+	return ret;
+}
diff --git a/config/ctdb.init b/config/ctdb.init
index bae52c2..c83c091 100755
--- a/config/ctdb.init
+++ b/config/ctdb.init
@@ -66,6 +66,12 @@ CTDB_OPTIONS="$CTDB_OPTIONS --reclock=$CTDB_RECOVERY_LOCK"
 [ -z "$CTDB_START_AS_DISABLED" ] || [ "$CTDB_START_AS_DISABLED" != "yes" ] || {
 	CTDB_OPTIONS="$CTDB_OPTIONS --start-as-disabled"
 }
+[ -z "$CTDB_CAPABILITY_RECMASTER" ] || [ "$CTDB_CAPABILITY_RECMASTER" != "yes" ] || {
+	CTDB_OPTIONS="$CTDB_OPTIONS --no-recmaster"
+}
+[ -z "$CTDB_CAPABILITY_LMASTER" ] || [ "$CTDB_CAPABILITY_LMASTER" != "yes" ] || {
+	CTDB_OPTIONS="$CTDB_OPTIONS --no-lmaster"
+}
 
 if [ -x /sbin/startproc ]; then
     init_style="suse"
diff --git a/config/ctdb.sysconfig b/config/ctdb.sysconfig
index 9d1e434..58edbff 100644
--- a/config/ctdb.sysconfig
+++ b/config/ctdb.sysconfig
@@ -91,6 +91,23 @@
 # the node with "ctdb enable"
 # CTDB_START_AS_DISABLED="yes"
 
+# LMASTER and RECMASTER capabilities.
+# By default all nodes are capable of both being LMASTER for records and
+# also for taking the RECMASTER role and perform recovery.
+# These parameters can be used to disable these two roles on a node.
+# Note: If there are NO available nodes left in a cluster that can perform
+# the RECMASTER role, the cluster will not be able to recover from a failure
+# and will remain in RECOVERY mode until an RECMASTER capable node becomes
+# available. Same for LMASTER.
+# These parametersd are useful for scenarios where you have one "remote" node
+# in a cluster and you do not want the remote node to be fully participating
+# in the cluster and slow things down.
+# For that case, set both roles to "no" for the remote node on the remote site
+# but leave the roles default to "yes" on the primary nodes in the central
+# datacentre.
+# CTDB_CAPABILITY_RECMASTER=yes
+# CTDB_CAPABILITY_LMASTER=yes
+
 # where to log messages
 # the default is /var/log/log.ctdb
 # CTDB_LOGFILE=/var/log/log.ctdb
diff --git a/include/ctdb.h b/include/ctdb.h
index bfba37e..95d3f2f 100644
--- a/include/ctdb.h
+++ b/include/ctdb.h
@@ -536,4 +536,13 @@ uint32_t *list_of_vnnmap_nodes(struct ctdb_context *ctdb,
 
 int ctdb_read_pnn_lock(int fd, int32_t pnn);
 
+/*
+  get capabilities of a remote node
+ */
+int ctdb_ctrl_getcapabilities(struct ctdb_context *ctdb, struct timeval timeout, uint32_t destnode, uint32_t *capabilities);
+
+struct ctdb_client_control_state *ctdb_ctrl_getcapabilities_send(struct ctdb_context *ctdb, TALLOC_CTX *mem_ctx, struct timeval timeout, uint32_t destnode);
+
+int ctdb_ctrl_getcapabilities_recv(struct ctdb_context *ctdb, TALLOC_CTX *mem_ctx, struct ctdb_client_control_state *state, uint32_t *capabilities);
+
 #endif
diff --git a/include/ctdb_private.h b/include/ctdb_private.h
index 2435b0f..d2abc99 100644
--- a/include/ctdb_private.h
+++ b/include/ctdb_private.h
@@ -332,6 +332,10 @@ enum ctdb_freeze_mode {CTDB_FREEZE_NONE, CTDB_FREEZE_PENDING, CTDB_FREEZE_FROZEN
 #define CTDB_MONITORING_ACTIVE		0
 #define CTDB_MONITORING_DISABLED	1
 
+/* The different capabilities of the ctdb daemon. */
+#define CTDB_CAP_RECMASTER		0x00000001
+#define CTDB_CAP_LMASTER		0x00000002
+
 /* main state of the ctdb daemon */
 struct ctdb_context {
 	struct event_context *ev;
@@ -356,6 +360,7 @@ struct ctdb_context {
 	uint32_t num_nodes;
 	uint32_t num_connected;
 	unsigned flags;
+	uint32_t capabilities;
 	struct idr_context *idr;
 	uint16_t idr_cnt;
 	struct ctdb_node **nodes; /* array of nodes in the cluster - indexed by vnn */
@@ -513,6 +518,7 @@ enum ctdb_controls {CTDB_CONTROL_PROCESS_EXISTS          = 0,
 		    CTDB_CONTROL_ADD_PUBLIC_IP           = 77,
 		    CTDB_CONTROL_DEL_PUBLIC_IP           = 78,
 		    CTDB_CONTROL_RUN_EVENTSCRIPTS        = 79,
+		    CTDB_CONTROL_GET_CAPABILITIES	 = 80,
 };	
 
 /*
diff --git a/server/ctdb_control.c b/server/ctdb_control.c
index 9097854..a7f16a8 100644
--- a/server/ctdb_control.c
+++ b/server/ctdb_control.c
@@ -389,6 +389,9 @@ static int32_t ctdb_control_dispatch(struct ctdb_context *ctdb,
 	case CTDB_CONTROL_DEL_PUBLIC_IP:
 		return ctdb_control_del_public_address(ctdb, indata);
 
+	case CTDB_CONTROL_GET_CAPABILITIES:
+		return ctdb->capabilities;
+
 	default:
 		DEBUG(DEBUG_CRIT,(__location__ " Unknown CTDB control opcode %u\n", opcode));
 		return -1;
diff --git a/server/ctdb_recoverd.c b/server/ctdb_recoverd.c
index 1ffae72..1a53bb8 100644
--- a/server/ctdb_recoverd.c
+++ b/server/ctdb_recoverd.c
@@ -2688,6 +2688,37 @@ static void ctdb_recoverd_parent(struct event_context *ev, struct fd_event *fde,
 }
 
 /*
+  called regularly to verify that the recovery daemon is still running
+ */
+static void ctdb_check_recd(struct event_context *ev, struct timed_event *te, 
+			      struct timeval yt, void *p)
+{
+	struct ctdb_context *ctdb = talloc_get_type(p, struct ctdb_context);
+
+	/* make sure we harvest the child if signals are blocked for some
+	   reason
+	*/
+	waitpid(ctdb->recoverd_pid, 0, WNOHANG);
+
+	if (kill(ctdb->recoverd_pid, 0) != 0) {
+		DEBUG(DEBUG_ERR,("Recovery daemon (pid:%d) is no longer running. Shutting down main daemon\n", (int)ctdb->recoverd_pid));
+
+		ctdb_stop_recoverd(ctdb);
+		ctdb_stop_keepalive(ctdb);
+		ctdb_stop_monitoring(ctdb);
+		ctdb_release_all_ips(ctdb);
+		ctdb->methods->shutdown(ctdb);
+		ctdb_event_script(ctdb, "shutdown");
+
+		exit(10);	
+	}
+
+	event_add_timed(ctdb->ev, ctdb, 
+			timeval_current_ofs(30, 0),
+			ctdb_check_recd, ctdb);
+}
+
+/*
   startup the recovery daemon as a child of the main ctdb daemon
  */
 int ctdb_start_recoverd(struct ctdb_context *ctdb)
@@ -2708,6 +2739,9 @@ int ctdb_start_recoverd(struct ctdb_context *ctdb)
 	
 	if (ctdb->recoverd_pid != 0) {
 		close(fd[0]);
+		event_add_timed(ctdb->ev, ctdb, 
+				timeval_current_ofs(30, 0),
+				ctdb_check_recd, ctdb);
 		return 0;
 	}
 
diff --git a/server/ctdbd.c b/server/ctdbd.c
index 0686e0b..c21d434 100644
--- a/server/ctdbd.c
+++ b/server/ctdbd.c
@@ -43,6 +43,8 @@ static struct {
 	int         no_setsched;
 	int         use_syslog;
 	int         start_as_disabled;
+	int         no_lmaster;
+	int         no_recmaster;
 } options = {
 	.nlist = ETCDIR "/ctdb/nodes",
 	.transport = "tcp",
@@ -120,6 +122,8 @@ int main(int argc, const char *argv[])
 		{ "nosetsched", 0, POPT_ARG_NONE, &options.no_setsched, 0, "disable setscheduler SCHED_FIFO call", NULL },
 		{ "syslog", 0, POPT_ARG_NONE, &options.use_syslog, 0, "log messages to syslog", NULL },
 		{ "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 },
 		POPT_TABLEEND
 	};
 	int opt, ret;
@@ -200,6 +204,15 @@ int main(int argc, const char *argv[])
 		}
 	}
 
+	/* set ctdbd capabilities */
+	ctdb->capabilities = 0;
+	if (options.no_lmaster == 0) {
+		ctdb->capabilities |= CTDB_CAP_LMASTER;
+	}
+	if (options.no_recmaster == 0) {
+		ctdb->capabilities |= CTDB_CAP_RECMASTER;
+	}
+
 	/* tell ctdb what nodes are available */
 	ctdb_load_nodes_file(ctdb);
 
diff --git a/tools/ctdb.c b/tools/ctdb.c
index 2af9a15..3968e0d 100644
--- a/tools/ctdb.c
+++ b/tools/ctdb.c
@@ -1203,6 +1203,32 @@ static int control_getmonmode(struct ctdb_context *ctdb, int argc, const char **
 
 
 /*
+  display capabilities of a remote node
+ */
+static int control_getcapabilities(struct ctdb_context *ctdb, int argc, const char **argv)
+{
+	uint32_t capabilities;
+	int ret;
+
+	ret = ctdb_ctrl_getcapabilities(ctdb, TIMELIMIT(), options.pnn, &capabilities);
+	if (ret != 0) {
+		DEBUG(DEBUG_ERR, ("Unable to get capabilities from node %u\n", options.pnn));
+		return ret;
+	}
+	
+	if (!options.machinereadable){
+		printf("RECMASTER: %s\n", (capabilities&CTDB_CAP_RECMASTER)?"YES":"NO");
+		printf("LMASTER: %s\n", (capabilities&CTDB_CAP_LMASTER)?"YES":"NO");
+	} else {
+		printf(":RECMASTER:LMASTER:\n");
+		printf(":%d:%d:\n",
+			!!(capabilities&CTDB_CAP_RECMASTER),
+			!!(capabilities&CTDB_CAP_LMASTER));
+	}
+	return 0;
+}
+
+/*
   disable monitoring on a  node
  */
 static int control_disable_monmode(struct ctdb_context *ctdb, int argc, const char **argv)
@@ -1808,6 +1834,7 @@ static const struct {
 	{ "getdbmap",        control_getdbmap,          true,  "show the database map" },
 	{ "catdb",           control_catdb,             true,  "dump a database" ,                     "<dbname>"},
 	{ "getmonmode",      control_getmonmode,        true,  "show monitoring mode" },
+	{ "getcapabilities", control_getcapabilities,   true,  "show node capabilities" },
 	{ "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