add a control to read the db priority from a database
authorRonnie Sahlberg <ronniesahlberg@gmail.com>
Sat, 10 Oct 2009 04:04:18 +0000 (15:04 +1100)
committerRonnie Sahlberg <ronniesahlberg@gmail.com>
Mon, 12 Oct 2009 02:45:26 +0000 (13:45 +1100)
client/ctdb_client.c
include/ctdb.h
include/ctdb_private.h
server/ctdb_control.c
tools/ctdb.c

index 41d74d4a64d3dd6bd2784edd56c702311e020fdb..7ca589703c8c399baade1e5c0ff1a6ec5ceab1f4 100644 (file)
@@ -3661,3 +3661,30 @@ int ctdb_ctrl_set_db_priority(struct ctdb_context *ctdb, struct timeval timeout,
        return 0;
 }
 
+int ctdb_ctrl_get_db_priority(struct ctdb_context *ctdb, struct timeval timeout, uint32_t destnode, uint32_t db_id, uint32_t *priority)
+{
+       int ret;
+       int32_t res;
+       TDB_DATA data;
+       TALLOC_CTX *tmp_ctx = talloc_new(NULL);
+
+       data.dptr = (uint8_t*)&db_id;
+       data.dsize = sizeof(db_id);
+
+       ret = ctdb_control(ctdb, destnode, 0, 
+                          CTDB_CONTROL_GET_DB_PRIORITY, 0, data,
+                          tmp_ctx, NULL, &res, &timeout, NULL);
+       if (ret != 0 || res < 0) {
+               DEBUG(DEBUG_ERR,(__location__ " ctdb_control for set_db_priority failed\n"));
+               talloc_free(tmp_ctx);
+               return -1;
+       }
+
+       if (priority) {
+               *priority = res;
+       }
+
+       talloc_free(tmp_ctx);
+
+       return 0;
+}
index c9918c351e039a8bf05f3ba437a99027e70056ea..5f1699024ef1e078fb9f7a09a48a1ccf034ffa0e 100644 (file)
@@ -643,5 +643,6 @@ struct ctdb_db_priority {
 };
 
 int ctdb_ctrl_set_db_priority(struct ctdb_context *ctdb, struct timeval timeout, uint32_t destnode, struct ctdb_db_priority *db_prio);
+int ctdb_ctrl_get_db_priority(struct ctdb_context *ctdb, struct timeval timeout, uint32_t destnode, uint32_t db_id, uint32_t *priority);
 
 #endif
index 92a5ed40ff6d691f65209b79086ab5038265ce7b..da6a40632333530559fb12e147b08afb26c53ef9 100644 (file)
@@ -577,6 +577,7 @@ enum ctdb_controls {CTDB_CONTROL_PROCESS_EXISTS          = 0,
                    CTDB_CONTROL_TRAVERSE_KILL           = 97,
                    CTDB_CONTROL_RECD_RECLOCK_LATENCY    = 98,
                    CTDB_CONTROL_SET_DB_PRIORITY         = 111,
+                   CTDB_CONTROL_GET_DB_PRIORITY         = 112,
 };     
 
 /*
index 77e55ca54604554700c37e3fb90c0418ff0066d8..997b100f49e7bdd02e38ab353544576c11ef518b 100644 (file)
@@ -450,6 +450,17 @@ static int32_t ctdb_control_dispatch(struct ctdb_context *ctdb,
                CHECK_CONTROL_DATA_SIZE(sizeof(struct ctdb_db_priority));
                return ctdb_control_set_db_priority(ctdb, indata);
 
+       case CTDB_CONTROL_GET_DB_PRIORITY: {
+               uint32_t db_id;
+               struct ctdb_db_context *ctdb_db;
+
+               CHECK_CONTROL_DATA_SIZE(sizeof(db_id));
+               db_id = *(uint32_t *)indata.dptr;
+               ctdb_db = find_ctdb_db(ctdb, db_id);
+               if (ctdb_db == NULL) return -1;
+               return ctdb_db->priority;
+       }
+
        default:
                DEBUG(DEBUG_CRIT,(__location__ " Unknown CTDB control opcode %u\n", opcode));
                return -1;
index 53b4115553f0b60d9fbe02be4b4831339ee0b099..6f4725f9460c1be872d1b0c63faa220b8cb2ff9c 100644 (file)
@@ -2319,6 +2319,31 @@ static int control_setdbprio(struct ctdb_context *ctdb, int argc, const char **a
        return 0;
 }
 
+/*
+  get db priority
+ */
+static int control_getdbprio(struct ctdb_context *ctdb, int argc, const char **argv)
+{
+       uint32_t db_id, priority;
+       int ret;
+
+       if (argc < 1) {
+               usage();
+       }
+
+       db_id = strtoul(argv[0], NULL, 0);
+
+       ret = ctdb_ctrl_get_db_priority(ctdb, TIMELIMIT(), options.pnn, db_id, &priority);
+       if (ret != 0) {
+               DEBUG(DEBUG_ERR,("Unable to get db prio\n"));
+               return -1;
+       }
+
+       DEBUG(DEBUG_ERR,("Priority:%u\n", priority));
+
+       return 0;
+}
+
 /*
   run an eventscript on a node
  */
@@ -2930,6 +2955,7 @@ static const struct {
        { "natgwlist",        control_natgwlist,    false,      false, "show the nodes belonging to this natgw configuration"},
        { "xpnn",             control_xpnn,               true, true,  "find the pnn of the local node without talking to the daemon (unreliable)" },
        { "setdbprio",        control_setdbprio,        false,  false, "Set DB priority", "<dbid> <prio:1-3>"},
+       { "getdbprio",        control_getdbprio,        false,  false, "Get DB priority", "<dbid>"},
 };
 
 /*