add a ctdb uptime command that prints when ctdb was started and when the
authorRonnie Sahlberg <sahlberg@ronnie>
Thu, 17 Jan 2008 00:33:23 +0000 (11:33 +1100)
committerRonnie Sahlberg <sahlberg@ronnie>
Thu, 17 Jan 2008 00:33:23 +0000 (11:33 +1100)
last recovery occured

Makefile.in
client/ctdb_client.c
include/ctdb.h
include/ctdb_private.h
server/ctdb_control.c
server/ctdb_recover.c
server/ctdbd.c
tools/ctdb.c

index 8557b9c715126f65f3b02b0f24381c4687ba119e..3bff0d798c74f5d24d2105fa1eb8823689f3b1a3 100644 (file)
@@ -51,7 +51,7 @@ CTDB_SERVER_OBJ = server/ctdbd.o server/ctdb_daemon.o server/ctdb_lockwait.o \
        server/ctdb_control.o server/ctdb_call.o server/ctdb_ltdb_server.o \
        server/ctdb_traverse.o server/eventscript.o server/ctdb_takeover.o \
        server/ctdb_serverids.o server/ctdb_persistent.o \
-       server/ctdb_keepalive.o server/ctdb_logging.o \
+       server/ctdb_keepalive.o server/ctdb_logging.o server/ctdb_uptime.c \
        $(CTDB_CLIENT_OBJ) $(CTDB_TCP_OBJ) @INFINIBAND_WRAPPER_OBJ@
 
 TEST_BINS=bin/ctdb_bench bin/ctdb_fetch bin/ctdb_store bin/ctdb_randrec bin/ctdb_persistent bin/rb_test \
index 75a6cecc8f4ec400431e3169189473b5ad9e8c99..677e02da192169875a2a092ebdaf0a56480c645d 100644 (file)
@@ -2449,3 +2449,40 @@ uint32_t ctdb_get_pnn(struct ctdb_context *ctdb)
        return ctdb->pnn;
 }
 
+
+/*
+  get the uptime of a remote node
+ */
+struct ctdb_client_control_state *
+ctdb_ctrl_uptime_send(struct ctdb_context *ctdb, TALLOC_CTX *mem_ctx, struct timeval timeout, uint32_t destnode)
+{
+       return ctdb_control_send(ctdb, destnode, 0, 
+                          CTDB_CONTROL_UPTIME, 0, tdb_null, 
+                          mem_ctx, &timeout, NULL);
+}
+
+int ctdb_ctrl_uptime_recv(struct ctdb_context *ctdb, TALLOC_CTX *mem_ctx, struct ctdb_client_control_state *state, struct ctdb_uptime **uptime)
+{
+       int ret;
+       int32_t res;
+       TDB_DATA outdata;
+
+       ret = ctdb_control_recv(ctdb, state, mem_ctx, &outdata, &res, NULL);
+       if (ret != 0 || res != 0) {
+               DEBUG(0,(__location__ " ctdb_ctrl_uptime_recv failed\n"));
+               return -1;
+       }
+
+       *uptime = (struct ctdb_uptime *)talloc_steal(mem_ctx, outdata.dptr);
+
+       return 0;
+}
+
+int ctdb_ctrl_uptime(struct ctdb_context *ctdb, TALLOC_CTX *mem_ctx, struct timeval timeout, uint32_t destnode, struct ctdb_uptime **uptime)
+{
+       struct ctdb_client_control_state *state;
+
+       state = ctdb_ctrl_uptime_send(ctdb, mem_ctx, timeout, destnode);
+       return ctdb_ctrl_uptime_recv(ctdb, mem_ctx, state, uptime);
+}
+
index f734a521894f7b21853a8bdfa73a92288c7bb87a..eee698341727ce44bb5a1e6be45de75477045d44 100644 (file)
@@ -482,6 +482,21 @@ int ctdb_ctrl_get_server_id_list(struct ctdb_context *ctdb,
                struct timeval timeout, uint32_t destnode, 
                struct ctdb_server_id_list **svid_list);
 
+struct ctdb_uptime {
+       struct timeval current_time;
+       struct timeval ctdbd_start_time;
+       struct timeval last_recovery_time;
+};
+
 int ctdb_socket_connect(struct ctdb_context *ctdb);
 
+/*
+  get the uptime of a remote node
+ */
+int ctdb_ctrl_uptime(struct ctdb_context *ctdb, TALLOC_CTX *mem_ctx, struct timeval timeout, uint32_t destnode, struct ctdb_uptime **uptime);
+
+struct ctdb_client_control_state *ctdb_ctrl_uptime_send(struct ctdb_context *ctdb, TALLOC_CTX *mem_ctx, struct timeval timeout, uint32_t destnode);
+
+int ctdb_ctrl_uptime_recv(struct ctdb_context *ctdb, TALLOC_CTX *mem_ctx, struct ctdb_client_control_state *state, struct ctdb_uptime **uptime);
+
 #endif
index a7f17e6ac4ddaa22248428110d3664c9b7b6ddea..57501fc68a8e7aba33bc3de6974841d0e2ed7d21 100644 (file)
@@ -322,6 +322,8 @@ enum ctdb_freeze_mode {CTDB_FREEZE_NONE, CTDB_FREEZE_PENDING, CTDB_FREEZE_FROZEN
 /* main state of the ctdb daemon */
 struct ctdb_context {
        struct event_context *ev;
+       struct timeval ctdbd_start_time;
+       struct timeval last_recovery_time;
        uint32_t recovery_mode;
        TALLOC_CTX *tickle_update_context;
        TALLOC_CTX *keepalive_ctx;
@@ -485,6 +487,7 @@ enum ctdb_controls {CTDB_CONTROL_PROCESS_EXISTS          = 0,
                    CTDB_CONTROL_TRANSACTION_COMMIT      = 66,
                    CTDB_CONTROL_WIPE_DATABASE           = 67,
                    CTDB_CONTROL_DELETE_RECORD           = 68,
+                   CTDB_CONTROL_UPTIME                  = 69,
 };     
 
 /*
@@ -1191,6 +1194,8 @@ int32_t ctdb_control_unregister_server_id(struct ctdb_context *ctdb,
                      TDB_DATA indata);
 int32_t ctdb_control_get_server_id_list(struct ctdb_context *ctdb, 
                      TDB_DATA *outdata);
+int32_t ctdb_control_uptime(struct ctdb_context *ctdb, 
+                     TDB_DATA *outdata);
 
 int ctdb_attach_persistent(struct ctdb_context *ctdb);
 
index bcb259af39fb8d73db2261a51bae6db49f2d582e..f08e44d58ecbf330f6ee10919235a01d06d82ebf 100644 (file)
@@ -325,6 +325,9 @@ static int32_t ctdb_control_dispatch(struct ctdb_context *ctdb,
        case CTDB_CONTROL_DELETE_RECORD:
                return ctdb_control_delete_record(ctdb, indata);
 
+       case CTDB_CONTROL_UPTIME:
+               return ctdb_control_uptime(ctdb, outdata);
+
        default:
                DEBUG(0,(__location__ " Unknown CTDB control opcode %u\n", opcode));
                return -1;
index 3bc7a3744c1ed33eaad645f80a16ff6562b4e2da..65ad47156476f77d2045d0a681e147535231686e 100644 (file)
@@ -20,6 +20,7 @@
 #include "includes.h"
 #include "lib/events/events.h"
 #include "lib/tdb/include/tdb.h"
+#include "system/time.h"
 #include "system/network.h"
 #include "system/filesys.h"
 #include "system/wait.h"
@@ -412,6 +413,8 @@ static void ctdb_recovered_callback(struct ctdb_context *ctdb, int status, void
 
        ctdb_request_control_reply(ctdb, state->c, NULL, status, NULL);
        talloc_free(state);
+
+       gettimeofday(&ctdb->last_recovery_time, NULL);
 }
 
 /*
index afa2c83e536227bc9b56309e1efb6ba0e0dec2d6..449b3f2346c5d9da3f36b5e899ad71e6e35ef502 100644 (file)
@@ -21,6 +21,7 @@
 #include "lib/events/events.h"
 #include "system/filesys.h"
 #include "popt.h"
+#include "system/time.h"
 #include "system/wait.h"
 #include "system/network.h"
 #include "cmdline.h"
@@ -155,7 +156,8 @@ int main(int argc, const char *argv[])
        }
 
        DEBUG(0,("Starting CTDB daemon\n"));
-
+       gettimeofday(&ctdb->ctdbd_start_time, NULL);
+       gettimeofday(&ctdb->last_recovery_time, NULL);
        ctdb->recovery_mode    = CTDB_RECOVERY_NORMAL;
        ctdb->recovery_master  = (uint32_t)-1;
        ctdb->upcalls          = &ctdb_upcalls;
index 75b9749b61faa8a61ca217b1ac2cc68d9667cdc9..7fa8ebfeffa6197acc53b78bb16d2f99c2d3a47c 100644 (file)
@@ -20,6 +20,7 @@
 
 #include "includes.h"
 #include "lib/events/events.h"
+#include "system/time.h"
 #include "system/filesys.h"
 #include "system/network.h"
 #include "popt.h"
@@ -210,6 +211,52 @@ static int control_statistics_reset(struct ctdb_context *ctdb, int argc, const c
 }
 
 
+/*
+  display uptime of remote node
+ */
+static int control_uptime(struct ctdb_context *ctdb, int argc, const char **argv)
+{
+       int ret;
+       int mypnn;
+       struct ctdb_uptime *uptime = NULL;
+       int tmp, days, hours, minutes, seconds;
+
+       mypnn = ctdb_ctrl_getpnn(ctdb, TIMELIMIT(), options.pnn);
+       if (mypnn == -1) {
+               return -1;
+       }
+
+       ret = ctdb_ctrl_uptime(ctdb, ctdb, TIMELIMIT(), options.pnn, &uptime);
+       if (ret != 0) {
+               DEBUG(0, ("Unable to get uptime from node %u\n", options.pnn));
+               return ret;
+       }
+
+       printf("Current time of node  : %s", ctime(&uptime->current_time.tv_sec));
+
+       tmp = uptime->current_time.tv_sec - uptime->ctdbd_start_time.tv_sec;
+       seconds = tmp%60;
+       tmp    /= 60;
+       minutes = tmp%60;
+       tmp    /= 60;
+       hours   = tmp%24;
+       tmp    /= 24;
+       days    = tmp;
+       printf("Ctdbd start time      : (%03d %02d:%02d:%02d) %s", days, hours, minutes, seconds, ctime(&uptime->ctdbd_start_time.tv_sec));
+
+       tmp = uptime->current_time.tv_sec - uptime->last_recovery_time.tv_sec;
+       seconds = tmp%60;
+       tmp    /= 60;
+       minutes = tmp%60;
+       tmp    /= 60;
+       hours   = tmp%24;
+       tmp    /= 24;
+       days    = tmp;
+       printf("Time of last recovery : (%03d %02d:%02d:%02d) %s", days, hours, minutes, seconds, ctime(&uptime->last_recovery_time.tv_sec));
+
+       return 0;
+}
+
 /*
   display remote ctdb status
  */
@@ -1034,6 +1081,7 @@ static const struct {
        const char *args;
 } ctdb_commands[] = {
        { "status",          control_status,            true,  "show node status" },
+       { "uptime",          control_uptime,            true,  "show node uptime" },
        { "ping",            control_ping,              true,  "ping all nodes" },
        { "getvar",          control_getvar,            true,  "get a tunable variable",               "<name>"},
        { "setvar",          control_setvar,            true,  "set a tunable variable",               "<name> <value>"},