add controls to enable/disable the monitoring of dead nodes
authorRonnie Sahlberg <sahlberg@ronnie>
Sun, 20 May 2007 23:24:34 +0000 (09:24 +1000)
committerRonnie Sahlberg <sahlberg@ronnie>
Sun, 20 May 2007 23:24:34 +0000 (09:24 +1000)
(This used to be ctdb commit 79d29c39bb81feb069db3fc6d3d392c1e75a4d13)

ctdb/common/ctdb_client.c
ctdb/common/ctdb_control.c
ctdb/common/ctdb_monitor.c
ctdb/include/ctdb.h
ctdb/include/ctdb_private.h
ctdb/tools/ctdb_control.c

index c95dc65f183a1d1c05dd9e7b093e7d3438b97152..0a02ac20693a2062a59c7387f75cc1802b0ae4c8 100644 (file)
@@ -1722,3 +1722,50 @@ int ctdb_ctrl_thaw(struct ctdb_context *ctdb, struct timeval timeout, uint32_t d
 
        return 0;
 }
+
+/*
+  set the monitoring mode of a remote node
+ */
+int ctdb_ctrl_setmonmode(struct ctdb_context *ctdb, struct timeval timeout, uint32_t destnode, uint32_t monmode)
+{
+       int ret;
+       TDB_DATA data, outdata;
+       int32_t res;
+
+       data.dsize = sizeof(uint32_t);
+       data.dptr = (unsigned char *)&monmode;
+
+       ret = ctdb_control(ctdb, destnode, 0, 
+                          CTDB_CONTROL_SET_MONMODE, 0, data, 
+                          ctdb, &outdata, &res, &timeout, NULL);
+       if (ret != 0 || res != 0) {
+               DEBUG(0,(__location__ " ctdb_control for setmonmode failed\n"));
+               return -1;
+       }
+
+       return 0;
+}
+
+/*
+  get the monitoring mode of a remote node
+ */
+int ctdb_ctrl_getmonmode(struct ctdb_context *ctdb, struct timeval timeout, uint32_t destnode, uint32_t *monmode)
+{
+       int ret;
+       TDB_DATA data, outdata;
+       int32_t res;
+
+       ZERO_STRUCT(data);
+       ret = ctdb_control(ctdb, destnode, 0, 
+                          CTDB_CONTROL_GET_MONMODE, 0, data, 
+                          ctdb, &outdata, &res, &timeout, NULL);
+       if (ret != 0) {
+               DEBUG(0,(__location__ " ctdb_control for getrecmode failed\n"));
+               return -1;
+       }
+
+       *monmode = res;
+
+       return 0;
+}
+
index 3c3a6d17d36493eb023ba4e3767abeb8aa5e2477..db01072d75b12262dfaf303db453339101a5a2c6 100644 (file)
@@ -241,6 +241,14 @@ static int32_t ctdb_control_dispatch(struct ctdb_context *ctdb,
                CHECK_CONTROL_DATA_SIZE(sizeof(uint32_t));              
                return ctdb_control_set_recmode(ctdb, indata, errormsg);
 
+       case CTDB_CONTROL_SET_MONMODE:
+               CHECK_CONTROL_DATA_SIZE(sizeof(uint32_t));              
+               ctdb->monitoring_mode = *(uint32_t *)indata.dptr;
+               return 0;
+
+       case CTDB_CONTROL_GET_MONMODE: 
+               return ctdb->monitoring_mode;
+
        case CTDB_CONTROL_SHUTDOWN:
                exit(10);
 
index a2a65241aefb0b6d4e1bef3219c8681cf541dff2..44b2c4a6639353dcfaabd74ea5ad0aaa412f2a1b 100644 (file)
@@ -34,6 +34,13 @@ static void ctdb_check_for_dead_nodes(struct event_context *ev, struct timed_eve
        struct ctdb_context *ctdb = talloc_get_type(private_data, struct ctdb_context);
        int i;
 
+       if (ctdb->monitoring_mode==CTDB_MONITORING_DISABLED) {
+               event_add_timed(ctdb->ev, ctdb, 
+                       timeval_current_ofs(CTDB_MONITORING_TIMEOUT, 0), 
+                       ctdb_check_for_dead_nodes, ctdb);
+               return;
+       }
+
        /* send a keepalive to all other nodes, unless */
        for (i=0;i<ctdb->num_nodes;i++) {
                struct ctdb_node *node = ctdb->nodes[i];
index a330f709a51564b4e0765152fbc32b2c46297566..2c50d96965613a56d126ce77e7e5d2ce23d56643 100644 (file)
@@ -299,6 +299,14 @@ int ctdb_ctrl_getrecmode(struct ctdb_context *ctdb, struct timeval timeout, uint
   set the recovery mode of a remote node
  */
 int ctdb_ctrl_setrecmode(struct ctdb_context *ctdb, struct timeval timeout, uint32_t destnode, uint32_t recmode);
+/*
+  get the monitoring mode of a remote node
+ */
+int ctdb_ctrl_getmonmode(struct ctdb_context *ctdb, struct timeval timeout, uint32_t destnode, uint32_t *monmode);
+/*
+  set the monitoringmode of a remote node
+ */
+int ctdb_ctrl_setmonmode(struct ctdb_context *ctdb, struct timeval timeout, uint32_t destnode, uint32_t monmode);
 
 /*
   get the recovery master of a remote node
index 61abf41d27e1829129c5e5fc71e0e4384a6d3927..0ab79410ac1882ac4c932cfeb31b7ca8741af60b 100644 (file)
@@ -234,10 +234,14 @@ struct ctdb_write_record {
 
 enum ctdb_freeze_mode {CTDB_FREEZE_NONE, CTDB_FREEZE_PENDING, CTDB_FREEZE_FROZEN};
 
+#define CTDB_MONITORING_ACTIVE         0
+#define CTDB_MONITORING_DISABLED       1
+
 /* main state of the ctdb daemon */
 struct ctdb_context {
        struct event_context *ev;
        uint32_t recovery_mode;
+       uint32_t monitoring_mode;
        enum ctdb_freeze_mode freeze_mode;
        struct ctdb_freeze_handle *freeze_handle;
        struct ctdb_address address;
@@ -367,6 +371,8 @@ enum ctdb_controls {CTDB_CONTROL_PROCESS_EXISTS,
                    CTDB_CONTROL_THAW,
                    CTDB_CONTROL_GET_VNN,
                    CTDB_CONTROL_SHUTDOWN,
+                   CTDB_CONTROL_GET_MONMODE,
+                   CTDB_CONTROL_SET_MONMODE,
 };
 
 
index df0d755d0a1b89908ecabc5fe16f4f18ae8ba129..992991c2324f35f1127f55fcc694ab0b72e27772 100644 (file)
@@ -55,6 +55,8 @@ static void usage(void)
                "  setrecmode <vnn> <mode>            set recovery mode\n"
                "  getrecmaster <vnn>                 get recovery master\n"
                "  setrecmaster <vnn> <master_vnn>    set recovery master\n"
+               "  getmonmode <vnn>                   get monitoring mode\n"
+               "  setmonmode <vnn> <mode>            set monitoring mode\n"
                "  attach <dbname>                    attach a database\n"
                "  getpid <vnn>                       get the pid of a ctdb daemon\n"
                "  shutdown <vnn>                     shutdown a remote ctdb\n"
@@ -420,6 +422,56 @@ static int control_setrecmode(struct ctdb_context *ctdb, int argc, const char **
        return 0;
 }
 
+/*
+  display monitoring mode of a remote node
+ */
+static int control_getmonmode(struct ctdb_context *ctdb, int argc, const char **argv)
+{
+       uint32_t vnn, monmode;
+       int ret;
+
+
+       if (argc < 1) {
+               usage();
+       }
+
+       vnn     = strtoul(argv[0], NULL, 0);
+
+       ret = ctdb_ctrl_getmonmode(ctdb, timeval_current_ofs(timelimit, 0), vnn, &monmode);
+       if (ret != 0) {
+               printf("Unable to get monmode from node %u\n", vnn);
+               return ret;
+       }
+       printf("Monitoring mode:%s (%d)\n",monmode==CTDB_MONITORING_ACTIVE?"ACTIVE":"DISABLED",monmode);
+
+       return 0;
+}
+
+/*
+  set the monitoring mode of a remote node
+ */
+static int control_setmonmode(struct ctdb_context *ctdb, int argc, const char **argv)
+{
+       uint32_t vnn, monmode;
+       int ret;
+
+
+       if (argc < 2) {
+               usage();
+       }
+
+       vnn     = strtoul(argv[0], NULL, 0);
+       monmode = strtoul(argv[1], NULL, 0);
+
+       ret = ctdb_ctrl_setmonmode(ctdb, timeval_current_ofs(timelimit, 0), vnn, monmode);
+       if (ret != 0) {
+               printf("Unable to set monmode on node %u\n", vnn);
+               return ret;
+       }
+
+       return 0;
+}
+
 /*
   display recovery master of a remote node
  */
@@ -994,6 +1046,8 @@ int main(int argc, const char *argv[])
                { "setrecmode", control_setrecmode },
                { "getrecmaster", control_getrecmaster },
                { "setrecmaster", control_setrecmaster },
+               { "getmonmode", control_getmonmode },
+               { "setmonmode", control_setmonmode },
                { "ping", control_ping },
                { "debug", control_debug },
                { "debuglevel", control_debuglevel },