1
0
mirror of https://github.com/samba-team/samba.git synced 2024-12-22 13:34:15 +03:00

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.

(This used to be ctdb commit 67741c0ee01916d94cace8e9462ef02507e06078)
This commit is contained in:
Ronnie Sahlberg 2009-10-10 14:26:09 +11:00
parent e8e2f35985
commit 6cf7d8e131
7 changed files with 82 additions and 0 deletions

View File

@ -3944,3 +3944,27 @@ int ctdb_ctrl_get_ban(struct ctdb_context *ctdb, struct timeval timeout, uint32_
}
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;
}

View File

@ -674,5 +674,11 @@ struct ctdb_ban_time {
int ctdb_ctrl_set_ban(struct ctdb_context *ctdb, struct timeval timeout, uint32_t destnode, struct ctdb_ban_time *bantime);
int ctdb_ctrl_get_ban(struct ctdb_context *ctdb, struct timeval timeout, uint32_t destnode, TALLOC_CTX *mem_ctx, struct ctdb_ban_time **bantime);
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

View File

@ -441,6 +441,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;
@ -595,6 +596,7 @@ enum ctdb_controls {CTDB_CONTROL_PROCESS_EXISTS = 0,
CTDB_CONTROL_DISABLE_SCRIPT = 108,
CTDB_CONTROL_SET_BAN_STATE = 109,
CTDB_CONTROL_GET_BAN_STATE = 110,
CTDB_CONTROL_SET_DB_PRIORITY = 111,
};
/*
@ -1479,5 +1481,6 @@ int32_t ctdb_control_disable_script(struct ctdb_context *ctdb, TDB_DATA indata);
int32_t ctdb_control_set_ban_state(struct ctdb_context *ctdb, TDB_DATA indata);
int32_t ctdb_control_get_ban_state(struct ctdb_context *ctdb, TDB_DATA *outdata);
int32_t ctdb_control_set_db_priority(struct ctdb_context *ctdb, TDB_DATA indata);
#endif

View File

@ -526,6 +526,10 @@ static int32_t ctdb_control_dispatch(struct ctdb_context *ctdb,
CHECK_CONTROL_DATA_SIZE(0);
return ctdb_control_get_ban_state(ctdb, outdata);
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;

View 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;
}

View 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);
@ -497,3 +498,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;
}

View File

@ -2752,6 +2752,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
*/
@ -3428,6 +3452,7 @@ static const struct {
{ "setnatgwstate", control_setnatgwstate, false, false, "Set NATGW state to on/off", "{on|off}"},
{ "setlmasterrole", control_setlmasterrole, false, false, "Set LMASTER role to on/off", "{on|off}"},
{ "setrecmasterrole", control_setrecmasterrole, false, false, "Set RECMASTER role to on/off", "{on|off}"},
{ "setdbprio", control_setdbprio, false, false, "Set DB priority", "<dbid> <prio:1-3>"},
};
/*