1
0
mirror of https://github.com/samba-team/samba.git synced 2025-08-26 01:49:31 +03:00

ctdb-daemon: Refactor calculation of tdb open flags based on database type

Signed-off-by: Amitay Isaacs <amitay@gmail.com>
Reviewed-by: Martin Schwenke <martin@meltin.net>
This commit is contained in:
Amitay Isaacs
2017-03-21 13:50:07 +11:00
committed by Martin Schwenke
parent 45ea95126e
commit 1be2ff8b81
4 changed files with 53 additions and 43 deletions

View File

@ -2085,15 +2085,15 @@ struct ctdb_db_context *ctdb_attach(struct ctdb_context *ctdb,
struct timeval timeout,
const char *name,
bool persistent,
uint32_t tdb_flags)
uint32_t tdb_flags_unused)
{
struct ctdb_db_context *ctdb_db;
TDB_DATA data;
int ret;
int32_t res;
#ifdef TDB_MUTEX_LOCKING
uint32_t mutex_enabled = 0;
#endif
uint8_t db_flags = 0;
int tdb_flags;
bool with_mutex = false;
ctdb_db = ctdb_db_handle(ctdb, name);
if (ctdb_db) {
@ -2110,16 +2110,10 @@ struct ctdb_db_context *ctdb_attach(struct ctdb_context *ctdb,
data.dptr = discard_const(name);
data.dsize = strlen(name)+1;
/* CTDB has switched to using jenkins hash for volatile databases.
* Even if tdb_flags do not explicitly mention TDB_INCOMPATIBLE_HASH,
* always set it.
*/
if (!persistent) {
tdb_flags |= TDB_INCOMPATIBLE_HASH;
}
#ifdef TDB_MUTEX_LOCKING
if (!persistent) {
uint32_t mutex_enabled = 0;
ret = ctdb_ctrl_get_tunable(ctdb, timeval_current_ofs(3,0),
CTDB_CURRENT_NODE,
"TDBMutexEnabled",
@ -2129,11 +2123,16 @@ struct ctdb_db_context *ctdb_attach(struct ctdb_context *ctdb,
}
if (mutex_enabled == 1) {
tdb_flags |= (TDB_MUTEX_LOCKING | TDB_CLEAR_IF_FIRST);
with_mutex = true;
}
}
#endif
if (persistent) {
db_flags = CTDB_DB_FLAGS_PERSISTENT;
}
tdb_flags = ctdb_db_tdb_flags(db_flags, ctdb->valgrinding, with_mutex);
/* tell ctdb daemon to attach */
ret = ctdb_control(ctdb, CTDB_CURRENT_NODE, tdb_flags,
persistent?CTDB_CONTROL_DB_ATTACH_PERSISTENT:CTDB_CONTROL_DB_ATTACH,
@ -2143,7 +2142,7 @@ struct ctdb_db_context *ctdb_attach(struct ctdb_context *ctdb,
talloc_free(ctdb_db);
return NULL;
}
ctdb_db->db_id = *(uint32_t *)data.dptr;
talloc_free(data.dptr);
@ -2154,21 +2153,6 @@ struct ctdb_db_context *ctdb_attach(struct ctdb_context *ctdb,
return NULL;
}
if (persistent) {
tdb_flags = TDB_DEFAULT;
} else {
tdb_flags = TDB_NOSYNC;
#ifdef TDB_MUTEX_LOCKING
if (mutex_enabled) {
tdb_flags |= (TDB_MUTEX_LOCKING | TDB_CLEAR_IF_FIRST);
}
#endif
}
if (ctdb->valgrinding) {
tdb_flags |= TDB_NOMMAP;
}
tdb_flags |= TDB_DISALLOW_NESTING;
ctdb_db->ltdb = tdb_wrap_open(ctdb_db, ctdb_db->db_path, 0, tdb_flags,
O_RDWR, 0);
if (ctdb_db->ltdb == NULL) {

View File

@ -39,6 +39,8 @@ struct ctdb_queue *ctdb_queue_setup(struct ctdb_context *ctdb,
/* From common/ctdb_ltdb.c */
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);

View File

@ -33,6 +33,37 @@
#include "common/common.h"
#include "common/logging.h"
/*
* Calculate tdb flags based on databse type
*/
int ctdb_db_tdb_flags(uint8_t db_flags, bool with_valgrind, bool with_mutex)
{
int tdb_flags = 0;
if (db_flags & CTDB_DB_FLAGS_PERSISTENT) {
tdb_flags = TDB_DEFAULT;
} else {
tdb_flags = TDB_NOSYNC |
TDB_CLEAR_IF_FIRST |
TDB_INCOMPATIBLE_HASH;
#ifdef TDB_MUTEX_LOCKING
if (with_mutex && tdb_runtime_check_for_robust_mutexes()) {
tdb_flags |= TDB_MUTEX_LOCKING;
}
#endif
}
tdb_flags |= TDB_DISALLOW_NESTING;
if (with_valgrind) {
tdb_flags |= TDB_NOMMAP;
}
return tdb_flags;
}
/*
find an attached ctdb_db handle given a name
*/

View File

@ -763,9 +763,10 @@ static int ctdb_local_attach(struct ctdb_context *ctdb, const char *db_name,
struct ctdb_db_context *ctdb_db, *tmp_db;
int ret;
struct TDB_DATA key;
unsigned tdb_flags;
int tdb_flags;
int mode = 0600;
int remaining_tries = 0;
uint8_t db_flags = 0;
ctdb_db = talloc_zero(ctdb, struct ctdb_db_context);
CTDB_NO_MEMORY(ctdb, ctdb_db);
@ -844,20 +845,12 @@ static int ctdb_local_attach(struct ctdb_context *ctdb, const char *db_name,
persistent?ctdb->db_directory_persistent:ctdb->db_directory,
db_name, ctdb->pnn);
tdb_flags = persistent? TDB_DEFAULT : TDB_CLEAR_IF_FIRST | TDB_NOSYNC;
if (ctdb->valgrinding) {
tdb_flags |= TDB_NOMMAP;
if (persistent) {
db_flags = CTDB_DB_FLAGS_PERSISTENT;
}
tdb_flags |= TDB_DISALLOW_NESTING;
if (jenkinshash) {
tdb_flags |= TDB_INCOMPATIBLE_HASH;
}
#ifdef TDB_MUTEX_LOCKING
if (ctdb->tunable.mutex_enabled && mutexes &&
tdb_runtime_check_for_robust_mutexes()) {
tdb_flags |= (TDB_MUTEX_LOCKING | TDB_CLEAR_IF_FIRST);
}
#endif
tdb_flags = ctdb_db_tdb_flags(db_flags, ctdb->valgrinding,
ctdb->tunable.mutex_enabled);
again:
ctdb_db->ltdb = tdb_wrap_open(ctdb_db, ctdb_db->db_path,