diff options
author | Volker Lendecke <vl@samba.org> | 2012-03-27 14:31:04 +0200 |
---|---|---|
committer | Volker Lendecke <vl@samba.org> | 2012-04-17 10:21:00 +0200 |
commit | 94cf5cc284ba908675ed5fd573dd101d7b9bad02 (patch) | |
tree | fa3cbe066f5400c31cfa13ea149e13bada59fbdc /source3/lib/dbwrap/dbwrap_tdb.c | |
parent | bd9178506ed8796a0aa7e4e757f2adc20dcae4f8 (diff) | |
download | samba-94cf5cc284ba908675ed5fd573dd101d7b9bad02.tar.gz samba-94cf5cc284ba908675ed5fd573dd101d7b9bad02.tar.bz2 samba-94cf5cc284ba908675ed5fd573dd101d7b9bad02.zip |
s3: Add dbwrap_try_fetch_locked
This is designed to spread the load on individual ctdb records to allow upper
layers to do backoff mechanisms. In the ctdb case, do not get the record if a
local lock is already taken. If we are not dmaster, do at most one migrate
attempt.
For the tdb case, this is a nonblocking fetch_locked. If someone else has the
lock, give up.
Diffstat (limited to 'source3/lib/dbwrap/dbwrap_tdb.c')
-rw-r--r-- | source3/lib/dbwrap/dbwrap_tdb.c | 41 |
1 files changed, 32 insertions, 9 deletions
diff --git a/source3/lib/dbwrap/dbwrap_tdb.c b/source3/lib/dbwrap/dbwrap_tdb.c index 46d6cdb8d1..ffad39bed8 100644 --- a/source3/lib/dbwrap/dbwrap_tdb.c +++ b/source3/lib/dbwrap/dbwrap_tdb.c @@ -101,20 +101,13 @@ static int db_tdb_fetchlock_parse(TDB_DATA key, TDB_DATA data, return 0; } -static struct db_record *db_tdb_fetch_locked(struct db_context *db, - TALLOC_CTX *mem_ctx, TDB_DATA key) +static struct db_record *db_tdb_fetch_locked_internal( + struct db_context *db, TALLOC_CTX *mem_ctx, TDB_DATA key) { struct db_tdb_ctx *ctx = talloc_get_type_abort(db->private_data, struct db_tdb_ctx); struct tdb_fetch_locked_state state; - db_tdb_log_key("Locking", key); - - if (tdb_chainlock(ctx->wtdb->tdb, key) != 0) { - DEBUG(3, ("tdb_chainlock failed\n")); - return NULL; - } - state.mem_ctx = mem_ctx; state.result = NULL; @@ -140,6 +133,35 @@ static struct db_record *db_tdb_fetch_locked(struct db_context *db, return state.result; } +static struct db_record *db_tdb_fetch_locked( + struct db_context *db, TALLOC_CTX *mem_ctx, TDB_DATA key) +{ + struct db_tdb_ctx *ctx = talloc_get_type_abort(db->private_data, + struct db_tdb_ctx); + + db_tdb_log_key("Locking", key); + if (tdb_chainlock(ctx->wtdb->tdb, key) != 0) { + DEBUG(3, ("tdb_chainlock failed\n")); + return NULL; + } + return db_tdb_fetch_locked_internal(db, mem_ctx, key); +} + +static struct db_record *db_tdb_try_fetch_locked( + struct db_context *db, TALLOC_CTX *mem_ctx, TDB_DATA key) +{ + struct db_tdb_ctx *ctx = talloc_get_type_abort(db->private_data, + struct db_tdb_ctx); + + db_tdb_log_key("Trying to lock", key); + if (tdb_chainlock_nonblock(ctx->wtdb->tdb, key) != 0) { + DEBUG(3, ("tdb_chainlock_nonblock failed\n")); + return NULL; + } + return db_tdb_fetch_locked_internal(db, mem_ctx, key); +} + + static int db_tdb_exists(struct db_context *db, TDB_DATA key) { struct db_tdb_ctx *ctx = talloc_get_type_abort( @@ -373,6 +395,7 @@ struct db_context *db_open_tdb(TALLOC_CTX *mem_ctx, } result->fetch_locked = db_tdb_fetch_locked; + result->try_fetch_locked = db_tdb_try_fetch_locked; result->traverse = db_tdb_traverse; result->traverse_read = db_tdb_traverse_read; result->parse_record = db_tdb_parse; |