From 808b4a6ed9f6122a958146ef6ac6665f0e75fe32 Mon Sep 17 00:00:00 2001 From: Ronnie Sahlberg Date: Sat, 10 Oct 2009 14:26:09 +1100 Subject: [PATCH] add a control to set a database priority. Let newly created databases default to priority 1. database priorities will be used to control in which order databases are locked during recovery in. --- client/ctdb_client.c | 25 +++++++++++++++++++++++++ include/ctdb.h | 8 ++++++++ include/ctdb_private.h | 4 ++++ server/ctdb_control.c | 5 +++++ server/ctdb_freeze.c | 1 + server/ctdb_ltdb_server.c | 19 +++++++++++++++++++ tools/ctdb.c | 25 +++++++++++++++++++++++++ 7 files changed, 87 insertions(+) diff --git a/client/ctdb_client.c b/client/ctdb_client.c index fa6a990a..41d74d4a 100644 --- a/client/ctdb_client.c +++ b/client/ctdb_client.c @@ -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; +} + diff --git a/include/ctdb.h b/include/ctdb.h index 866ba76e..c9918c35 100644 --- a/include/ctdb.h +++ b/include/ctdb.h @@ -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 diff --git a/include/ctdb_private.h b/include/ctdb_private.h index 2e3b472b..92a5ed40 100644 --- a/include/ctdb_private.h +++ b/include/ctdb_private.h @@ -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 diff --git a/server/ctdb_control.c b/server/ctdb_control.c index f9bd4240..77e55ca5 100644 --- a/server/ctdb_control.c +++ b/server/ctdb_control.c @@ -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; diff --git a/server/ctdb_freeze.c b/server/ctdb_freeze.c index 6f99f8be..c9499c85 100644 --- a/server/ctdb_freeze.c +++ b/server/ctdb_freeze.c @@ -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; } diff --git a/server/ctdb_ltdb_server.c b/server/ctdb_ltdb_server.c index e76a50a5..8044c4ed 100644 --- a/server/ctdb_ltdb_server.c +++ b/server/ctdb_ltdb_server.c @@ -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; +} + + diff --git a/tools/ctdb.c b/tools/ctdb.c index 39ed5b6d..53b41155 100644 --- a/tools/ctdb.c +++ b/tools/ctdb.c @@ -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", " "}, }; /* -- 2.34.1