add a control to set a database priority. Let newly created databases default to...
authorRonnie Sahlberg <ronniesahlberg@gmail.com>
Sat, 10 Oct 2009 03:26:09 +0000 (14:26 +1100)
committerRonnie Sahlberg <ronniesahlberg@gmail.com>
Mon, 12 Oct 2009 02:45:10 +0000 (13:45 +1100)
database priorities will be used to control in which order databases are locked during recovery in.

client/ctdb_client.c
include/ctdb.h
include/ctdb_private.h
server/ctdb_control.c
server/ctdb_freeze.c
server/ctdb_ltdb_server.c
tools/ctdb.c

index fa6a990a4d9cfa647b339f5722595ea36c8bfad1..41d74d4a64d3dd6bd2784edd56c702311e020fdb 100644 (file)
@@ -3636,3 +3636,28 @@ int ctdb_ctrl_report_recd_lock_latency(struct ctdb_context *ctdb, struct timeval
 
        return 0;
 }
+
+int ctdb_ctrl_set_db_priority(struct ctdb_context *ctdb, struct timeval timeout, uint32_t destnode, struct ctdb_db_priority *db_prio)
+{
+       int ret;
+       int32_t res;
+       TDB_DATA data;
+       TALLOC_CTX *tmp_ctx = talloc_new(NULL);
+
+       data.dptr = (uint8_t*)db_prio;
+       data.dsize = sizeof(*db_prio);
+
+       ret = ctdb_control(ctdb, destnode, 0, 
+                          CTDB_CONTROL_SET_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;
+       }
+
+       talloc_free(tmp_ctx);
+
+       return 0;
+}
+
index 866ba76e2a8edd4a450bdd11ce712308bbf40787..c9918c351e039a8bf05f3ba437a99027e70056ea 100644 (file)
@@ -636,4 +636,12 @@ int ctdb_ctrl_getscriptstatus(struct ctdb_context *ctdb,
                    TALLOC_CTX *mem_ctx, struct ctdb_monitoring_wire **script_status);
 
 
+
+struct ctdb_db_priority {
+       uint32_t db_id;
+       uint32_t priority;
+};
+
+int ctdb_ctrl_set_db_priority(struct ctdb_context *ctdb, struct timeval timeout, uint32_t destnode, struct ctdb_db_priority *db_prio);
+
 #endif
index 2e3b472bfa5ff17a154a251de780511e3582122d..92a5ed40ff6d691f65209b79086ab5038265ce7b 100644 (file)
@@ -434,6 +434,7 @@ struct ctdb_db_context {
        struct ctdb_db_context *next, *prev;
        struct ctdb_context *ctdb;
        uint32_t db_id;
+       uint32_t priority;
        bool persistent;
        const char *db_name;
        const char *db_path;
@@ -575,6 +576,7 @@ enum ctdb_controls {CTDB_CONTROL_PROCESS_EXISTS          = 0,
                    CTDB_CONTROL_GET_EVENT_SCRIPT_STATUS = 96,
                    CTDB_CONTROL_TRAVERSE_KILL           = 97,
                    CTDB_CONTROL_RECD_RECLOCK_LATENCY    = 98,
+                   CTDB_CONTROL_SET_DB_PRIORITY         = 111,
 };     
 
 /*
@@ -1449,4 +1451,6 @@ int ctdb_ctrl_report_recd_lock_latency(struct ctdb_context *ctdb, struct timeval
 
 int ctdb_vacuum_init(struct ctdb_db_context *ctdb_db);
 
+int32_t ctdb_control_set_db_priority(struct ctdb_context *ctdb, TDB_DATA indata);
+
 #endif
index f9bd42405ee0848085f8bee840823b010c0fd007..77e55ca54604554700c37e3fb90c0418ff0066d8 100644 (file)
@@ -445,6 +445,11 @@ static int32_t ctdb_control_dispatch(struct ctdb_context *ctdb,
                CHECK_CONTROL_DATA_SIZE(sizeof(double));
                ctdb_reclock_latency(ctdb, "recd reclock", &ctdb->statistics.reclock.recd, *((double *)indata.dptr));
                return 0;
+
+       case CTDB_CONTROL_SET_DB_PRIORITY:
+               CHECK_CONTROL_DATA_SIZE(sizeof(struct ctdb_db_priority));
+               return ctdb_control_set_db_priority(ctdb, indata);
+
        default:
                DEBUG(DEBUG_CRIT,(__location__ " Unknown CTDB control opcode %u\n", opcode));
                return -1;
index 6f99f8beb401da008624d4fbb384a416a4d95a81..c9499c85a13c23ea0052485a582b3fbb0a72bd33 100644 (file)
@@ -34,6 +34,7 @@ static int ctdb_lock_all_databases(struct ctdb_context *ctdb)
 {
        struct ctdb_db_context *ctdb_db;
        for (ctdb_db=ctdb->db_list;ctdb_db;ctdb_db=ctdb_db->next) {
+               DEBUG(DEBUG_INFO,("locking database 0x%08x priority:%u %s\n", ctdb_db->db_id, ctdb_db->priority, ctdb_db->db_name));
                if (tdb_lockall(ctdb_db->ltdb->tdb) != 0) {
                        return -1;
                }
index e76a50a552b6cf35ee65b1c65250fd6d4f73c4bc..8044c4ed2a1e064746170611c378794f9aa48e2b 100644 (file)
@@ -202,6 +202,7 @@ static int ctdb_local_attach(struct ctdb_context *ctdb, const char *db_name, boo
        ctdb_db = talloc_zero(ctdb, struct ctdb_db_context);
        CTDB_NO_MEMORY(ctdb, ctdb_db);
 
+       ctdb_db->priority = 1;
        ctdb_db->ctdb = ctdb;
        ctdb_db->db_name = talloc_strdup(ctdb_db, db_name);
        CTDB_NO_MEMORY(ctdb, ctdb_db->db_name);
@@ -491,3 +492,21 @@ int32_t ctdb_ltdb_enable_seqnum(struct ctdb_context *ctdb, uint32_t db_id)
        return 0;
 }
 
+int32_t ctdb_control_set_db_priority(struct ctdb_context *ctdb, TDB_DATA indata)
+{
+       struct ctdb_db_priority *db_prio = (struct ctdb_db_priority *)indata.dptr;
+       struct ctdb_db_context *ctdb_db;
+
+       ctdb_db = find_ctdb_db(ctdb, db_prio->db_id);
+       if (!ctdb_db) {
+               DEBUG(DEBUG_ERR,("Unknown db_id 0x%x in ctdb_set_db_priority\n", db_prio->db_id));
+               return -1;
+       }
+
+       ctdb_db->priority = db_prio->priority;
+       DEBUG(DEBUG_INFO,("Setting DB priority to %u for db 0x%08x\n", db_prio->priority, db_prio->db_id));
+
+       return 0;
+}
+
+
index 39ed5b6dbb01256f265556cdcfaf477d91293874..53b4115553f0b60d9fbe02be4b4831339ee0b099 100644 (file)
@@ -2295,6 +2295,30 @@ static int control_attach(struct ctdb_context *ctdb, int argc, const char **argv
        return 0;
 }
 
+/*
+  set db priority
+ */
+static int control_setdbprio(struct ctdb_context *ctdb, int argc, const char **argv)
+{
+       struct ctdb_db_priority db_prio;
+       int ret;
+
+       if (argc < 2) {
+               usage();
+       }
+
+       db_prio.db_id    = strtoul(argv[0], NULL, 0);
+       db_prio.priority = strtoul(argv[1], NULL, 0);
+
+       ret = ctdb_ctrl_set_db_priority(ctdb, TIMELIMIT(), options.pnn, &db_prio);
+       if (ret != 0) {
+               DEBUG(DEBUG_ERR,("Unable to set db prio\n"));
+               return -1;
+       }
+
+       return 0;
+}
+
 /*
   run an eventscript on a node
  */
@@ -2905,6 +2929,7 @@ static const struct {
        { "scriptstatus",        control_scriptstatus,    false,        false, "show the status of the monitoring scripts"},
        { "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>"},
 };
 
 /*