mirror of
https://github.com/samba-team/samba.git
synced 2024-12-31 17:18:04 +03:00
ctdb-daemon: Add accessors for CTDB_DB_FLAGS_PERSISTENT flag
This allows to differentiate between the two database models. ctdb_db_persistent() - replicated and permanent ctdb_db_volatile() - distributed and temporary Signed-off-by: Amitay Isaacs <amitay@gmail.com> Reviewed-by: Martin Schwenke <martin@meltin.net>
This commit is contained in:
parent
2975de6ffb
commit
94af277c48
@ -933,8 +933,9 @@ again:
|
||||
*/
|
||||
int ctdb_record_store(struct ctdb_record_handle *h, TDB_DATA data)
|
||||
{
|
||||
if (h->ctdb_db->persistent) {
|
||||
DEBUG(DEBUG_ERR, (__location__ " ctdb_record_store prohibited for persistent dbs\n"));
|
||||
if (! ctdb_db_volatile(h->ctdb_db)) {
|
||||
DEBUG(DEBUG_ERR,
|
||||
("ctdb_record_store prohibited for non-volatile dbs\n"));
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -44,6 +44,9 @@ int ctdb_db_tdb_flags(uint8_t db_flags, bool with_valgrind, bool with_mutex);
|
||||
struct ctdb_db_context *ctdb_db_handle(struct ctdb_context *ctdb,
|
||||
const char *name);
|
||||
|
||||
bool ctdb_db_persistent(struct ctdb_db_context *ctdb_db);
|
||||
bool ctdb_db_volatile(struct ctdb_db_context *ctdb_db);
|
||||
|
||||
uint32_t ctdb_lmaster(struct ctdb_context *ctdb, const TDB_DATA *key);
|
||||
|
||||
int ctdb_ltdb_fetch(struct ctdb_db_context *ctdb_db,
|
||||
|
@ -78,6 +78,15 @@ struct ctdb_db_context *ctdb_db_handle(struct ctdb_context *ctdb, const char *na
|
||||
return NULL;
|
||||
}
|
||||
|
||||
bool ctdb_db_persistent(struct ctdb_db_context *ctdb_db)
|
||||
{
|
||||
return ctdb_db->persistent;
|
||||
}
|
||||
|
||||
bool ctdb_db_volatile(struct ctdb_db_context *ctdb_db)
|
||||
{
|
||||
return !ctdb_db->persistent;
|
||||
}
|
||||
|
||||
/*
|
||||
return the lmaster given a key
|
||||
@ -133,7 +142,8 @@ int ctdb_ltdb_fetch(struct ctdb_db_context *ctdb_db,
|
||||
if (data) {
|
||||
*data = tdb_null;
|
||||
}
|
||||
if (ctdb_db->persistent || header->dmaster == ctdb_db->ctdb->pnn) {
|
||||
if (ctdb_db_persistent(ctdb_db) ||
|
||||
header->dmaster == ctdb_db->ctdb->pnn) {
|
||||
if (ctdb_ltdb_store(ctdb_db, key, header, tdb_null) != 0) {
|
||||
DEBUG(DEBUG_NOTICE,
|
||||
(__location__ "failed to store initial header\n"));
|
||||
@ -285,8 +295,10 @@ int ctdb_ltdb_unlock(struct ctdb_db_context *ctdb_db, TDB_DATA key)
|
||||
*/
|
||||
int ctdb_ltdb_delete(struct ctdb_db_context *ctdb_db, TDB_DATA key)
|
||||
{
|
||||
if (ctdb_db->persistent != 0) {
|
||||
DEBUG(DEBUG_ERR,("Trying to delete empty record in persistent database\n"));
|
||||
if (! ctdb_db_volatile(ctdb_db)) {
|
||||
DEBUG(DEBUG_WARNING,
|
||||
("Ignored deletion of empty record from "
|
||||
"non-volatile database\n"));
|
||||
return 0;
|
||||
}
|
||||
if (tdb_delete(ctdb_db->ltdb->tdb, key) != 0) {
|
||||
|
@ -1974,7 +1974,7 @@ int ctdb_migration_init(struct ctdb_db_context *ctdb_db)
|
||||
struct tevent_timer *te;
|
||||
int ret;
|
||||
|
||||
if (ctdb_db->persistent) {
|
||||
if (! ctdb_db_volatile(ctdb_db)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -845,7 +845,7 @@ int32_t ctdb_control_wipe_database(struct ctdb_context *ctdb, TDB_DATA indata)
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!ctdb_db->persistent) {
|
||||
if (ctdb_db_volatile(ctdb_db)) {
|
||||
talloc_free(ctdb_db->delete_queue);
|
||||
ctdb_db->delete_queue = trbt_create(ctdb_db, 0);
|
||||
if (ctdb_db->delete_queue == NULL) {
|
||||
|
@ -143,7 +143,7 @@ static int ctdb_ltdb_store_server(struct ctdb_db_context *ctdb_db,
|
||||
}
|
||||
|
||||
if (keep) {
|
||||
if (!ctdb_db->persistent &&
|
||||
if (ctdb_db_volatile(ctdb_db) &&
|
||||
(ctdb_db->ctdb->pnn == header->dmaster) &&
|
||||
!(header->flags & CTDB_REC_RO_FLAGS))
|
||||
{
|
||||
@ -607,7 +607,7 @@ int ctdb_recheck_persistent_health(struct ctdb_context *ctdb)
|
||||
int fail = 0;
|
||||
|
||||
for (ctdb_db = ctdb->db_list; ctdb_db; ctdb_db = ctdb_db->next) {
|
||||
if (!ctdb_db->persistent) {
|
||||
if (!ctdb_db_persistent(ctdb_db)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -722,8 +722,9 @@ int ctdb_set_db_readonly(struct ctdb_context *ctdb, struct ctdb_db_context *ctdb
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (ctdb_db->persistent) {
|
||||
DEBUG(DEBUG_ERR,("Persistent databases do not support readonly property\n"));
|
||||
if (! ctdb_db_volatile(ctdb_db)) {
|
||||
DEBUG(DEBUG_ERR,
|
||||
("Non-volatile databases do not support readonly flag\n"));
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -779,7 +780,7 @@ static int ctdb_local_attach(struct ctdb_context *ctdb, const char *db_name,
|
||||
ctdb_db->db_id = ctdb_hash(&key);
|
||||
ctdb_db->persistent = persistent;
|
||||
|
||||
if (!ctdb_db->persistent) {
|
||||
if (ctdb_db_volatile(ctdb_db)) {
|
||||
ctdb_db->delete_queue = trbt_create(ctdb_db, 0);
|
||||
if (ctdb_db->delete_queue == NULL) {
|
||||
CTDB_NO_MEMORY(ctdb, ctdb_db->delete_queue);
|
||||
@ -1170,10 +1171,10 @@ int32_t ctdb_control_db_attach(struct ctdb_context *ctdb, TDB_DATA indata,
|
||||
/* see if we already have this name */
|
||||
db = ctdb_db_handle(ctdb, db_name);
|
||||
if (db) {
|
||||
if (db->persistent != persistent) {
|
||||
if (ctdb_db_persistent(db) != persistent) {
|
||||
DEBUG(DEBUG_ERR, ("ERROR: DB Attach %spersistent to %spersistent "
|
||||
"database %s\n", persistent ? "" : "non-",
|
||||
db-> persistent ? "" : "non-", db_name));
|
||||
ctdb_db_persistent(db) ? "" : "non-", db_name));
|
||||
return -1;
|
||||
}
|
||||
outdata->dptr = (uint8_t *)&db->db_id;
|
||||
@ -1234,9 +1235,10 @@ int32_t ctdb_control_db_detach(struct ctdb_context *ctdb, TDB_DATA indata,
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (ctdb_db->persistent) {
|
||||
DEBUG(DEBUG_ERR, ("DB detach from persistent database %s "
|
||||
"denied\n", ctdb_db->db_name));
|
||||
if (! ctdb_db_volatile(ctdb_db)) {
|
||||
DEBUG(DEBUG_ERR,
|
||||
("Detaching non-volatile database %s denied\n",
|
||||
ctdb_db->db_name));
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -1572,8 +1574,9 @@ int ctdb_set_db_sticky(struct ctdb_context *ctdb, struct ctdb_db_context *ctdb_d
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (ctdb_db->persistent) {
|
||||
DEBUG(DEBUG_ERR,("Trying to set persistent database with sticky property\n"));
|
||||
if (! ctdb_db_volatile(ctdb_db)) {
|
||||
DEBUG(DEBUG_ERR,
|
||||
("Non-volatile databases do not support sticky flag\n"));
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -115,7 +115,7 @@ ctdb_control_getdbmap(struct ctdb_context *ctdb, uint32_t opcode, TDB_DATA indat
|
||||
dbid_map->num = len;
|
||||
for (i=0,ctdb_db=ctdb->db_list;ctdb_db;i++,ctdb_db=ctdb_db->next){
|
||||
dbid_map->dbs[i].db_id = ctdb_db->db_id;
|
||||
if (ctdb_db->persistent != 0) {
|
||||
if (ctdb_db_persistent(ctdb_db)) {
|
||||
dbid_map->dbs[i].flags |= CTDB_DB_FLAGS_PERSISTENT;
|
||||
}
|
||||
if (ctdb_db->readonly != 0) {
|
||||
|
@ -120,7 +120,7 @@ static int ctdb_traverse_local_fn(struct tdb_context *tdb, TDB_DATA key, TDB_DAT
|
||||
|
||||
hdr = (struct ctdb_ltdb_header *)data.dptr;
|
||||
|
||||
if (h->ctdb_db->persistent == 0) {
|
||||
if (ctdb_db_volatile(h->ctdb_db)) {
|
||||
/* filter out zero-length records */
|
||||
if (!h->withemptyrecords &&
|
||||
data.dsize <= sizeof(struct ctdb_ltdb_header))
|
||||
@ -386,7 +386,7 @@ static struct ctdb_traverse_all_handle *ctdb_daemon_traverse_all(struct ctdb_db_
|
||||
data.dsize = sizeof(r);
|
||||
}
|
||||
|
||||
if (ctdb_db->persistent == 0) {
|
||||
if (ctdb_db_volatile(ctdb_db)) {
|
||||
/* normal database, traverse all nodes */
|
||||
destination = CTDB_BROADCAST_VNNMAP;
|
||||
} else {
|
||||
@ -587,7 +587,7 @@ int32_t ctdb_control_traverse_data(struct ctdb_context *ctdb, TDB_DATA data, TDB
|
||||
/* Persistent databases are only scanned on one node (the local
|
||||
* node)
|
||||
*/
|
||||
if (state->ctdb_db->persistent == 0) {
|
||||
if (ctdb_db_volatile(state->ctdb_db)) {
|
||||
if (state->null_count != ctdb_get_num_active_nodes(ctdb)) {
|
||||
return 0;
|
||||
}
|
||||
|
@ -339,7 +339,7 @@ int32_t ctdb_control_update_record(struct ctdb_context *ctdb,
|
||||
state->c = c;
|
||||
state->m = m;
|
||||
state->flags = 0;
|
||||
if (!ctdb_db->persistent) {
|
||||
if (ctdb_db_volatile(ctdb_db)) {
|
||||
state->flags = UPDATE_FLAGS_REPLACE_ONLY;
|
||||
}
|
||||
|
||||
|
@ -1574,8 +1574,10 @@ void ctdb_stop_vacuuming(struct ctdb_context *ctdb)
|
||||
*/
|
||||
int ctdb_vacuum_init(struct ctdb_db_context *ctdb_db)
|
||||
{
|
||||
if (ctdb_db->persistent != 0) {
|
||||
DEBUG(DEBUG_ERR,("Vacuuming is disabled for persistent database %s\n", ctdb_db->db_name));
|
||||
if (! ctdb_db_volatile(ctdb_db)) {
|
||||
DEBUG(DEBUG_ERR,
|
||||
("Vacuuming is disabled for non-volatile database %s\n",
|
||||
ctdb_db->db_name));
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user