tools/ctdb: add "ctdb getdbstatus <dbname>"
authorStefan Metzmacher <metze@samba.org>
Wed, 2 Dec 2009 11:57:29 +0000 (12:57 +0100)
committerStefan Metzmacher <metze@samba.org>
Wed, 16 Dec 2009 07:08:32 +0000 (08:08 +0100)
metze

tools/ctdb.c

index 4b67db03c2ff3bff8a8614249b3fc111f4d03015..937b544de6845ceb7c73346c87116630c5301e13 100644 (file)
@@ -2575,6 +2575,52 @@ static int control_getdbmap(struct ctdb_context *ctdb, int argc, const char **ar
        return 0;
 }
 
+/*
+  display the status of a database on a remote ctdb
+ */
+static int control_getdbstatus(struct ctdb_context *ctdb, int argc, const char **argv)
+{
+       int i, ret;
+       struct ctdb_dbid_map *dbmap=NULL;
+       const char *db_name;
+
+       if (argc < 1) {
+               usage();
+       }
+
+       db_name = argv[0];
+
+       ret = ctdb_ctrl_getdbmap(ctdb, TIMELIMIT(), options.pnn, ctdb, &dbmap);
+       if (ret != 0) {
+               DEBUG(DEBUG_ERR, ("Unable to get dbids from node %u\n", options.pnn));
+               return ret;
+       }
+
+       for(i=0;i<dbmap->num;i++){
+               const char *path;
+               const char *name;
+               const char *health;
+               bool persistent;
+
+               ctdb_ctrl_getdbname(ctdb, TIMELIMIT(), options.pnn, dbmap->dbs[i].dbid, ctdb, &name);
+               if (strcmp(name, db_name) != 0) {
+                       continue;
+               }
+
+               ctdb_ctrl_getdbpath(ctdb, TIMELIMIT(), options.pnn, dbmap->dbs[i].dbid, ctdb, &path);
+               ctdb_ctrl_getdbhealth(ctdb, TIMELIMIT(), options.pnn, dbmap->dbs[i].dbid, ctdb, &health);
+               persistent = dbmap->dbs[i].persistent;
+               printf("dbid: 0x%08x\nname: %s\npath: %s\nPERSISTENT: %s\nHEALTH: %s\n",
+                      dbmap->dbs[i].dbid, name, path,
+                      persistent?"yes":"no",
+                      health?health:"OK");
+               return 0;
+       }
+
+       DEBUG(DEBUG_ERR, ("db %s doesn't exist on node %u\n", db_name, options.pnn));
+       return 0;
+}
+
 /*
   check if the local node is recmaster or not
   it will return 1 if this node is the recmaster and 0 if it is not
@@ -3803,6 +3849,7 @@ static const struct {
        { "ip",              control_ip,                false,  false,  "show which public ip's that ctdb manages" },
        { "process-exists",  control_process_exists,    true,   false,  "check if a process exists on a node",  "<pid>"},
        { "getdbmap",        control_getdbmap,          true,   false,  "show the database map" },
+       { "getdbstatus",     control_getdbstatus,       true,   false,  "show the status of a database", "<dbname>" },
        { "catdb",           control_catdb,             true,   false,  "dump a database" ,                     "<dbname>"},
        { "getmonmode",      control_getmonmode,        true,   false,  "show monitoring mode" },
        { "getcapabilities", control_getcapabilities,   true,   false,  "show node capabilities" },