1
0
mirror of https://github.com/samba-team/samba.git synced 2025-01-12 09:18:10 +03:00

Add transactions to the dbwrap API

Only filled in for tdb so far, for rbt it's pointless, and ctdb itself needs to
be extended
This commit is contained in:
Volker Lendecke 2008-03-10 10:17:05 +01:00
parent 4ee21a98bc
commit 0a55e018dd
4 changed files with 48 additions and 0 deletions

View File

@ -42,6 +42,9 @@ struct db_context {
void *private_data),
void *private_data);
int (*get_seqnum)(struct db_context *db);
int (*transaction_start)(struct db_context *db);
int (*transaction_commit)(struct db_context *db);
int (*transaction_cancel)(struct db_context *db);
void *private_data;
bool persistent;
};

View File

@ -441,6 +441,13 @@ static int db_ctdb_get_seqnum(struct db_context *db)
return tdb_get_seqnum(ctx->wtdb->tdb);
}
static int db_ctdb_trans_dummy(struct db_context *db)
{
/*
* Not implemented yet, just return ok
*/
return 0;
}
struct db_context *db_open_ctdb(TALLOC_CTX *mem_ctx,
const char *name,
@ -495,6 +502,9 @@ struct db_context *db_open_ctdb(TALLOC_CTX *mem_ctx,
result->traverse = db_ctdb_traverse;
result->traverse_read = db_ctdb_traverse_read;
result->get_seqnum = db_ctdb_get_seqnum;
result->transaction_start = db_ctdb_trans_dummy;
result->transaction_commit = db_ctdb_trans_dummy;
result->transaction_cancel = db_ctdb_trans_dummy;
DEBUG(3,("db_open_ctdb: opened database '%s' with dbid 0x%x\n",
name, db_ctdb->db_id));

View File

@ -351,6 +351,14 @@ static int db_rbt_get_seqnum(struct db_context *db)
return 0;
}
static int db_rbt_trans_dummy(struct db_context *db)
{
/*
* Transactions are pretty pointless in-memory, just return success.
*/
return 0;
}
struct db_context *db_open_rbt(TALLOC_CTX *mem_ctx)
{
struct db_context *result;
@ -373,6 +381,9 @@ struct db_context *db_open_rbt(TALLOC_CTX *mem_ctx)
result->traverse = db_rbt_traverse;
result->traverse_read = db_rbt_traverse;
result->get_seqnum = db_rbt_get_seqnum;
result->transaction_start = db_rbt_trans_dummy;
result->transaction_commit = db_rbt_trans_dummy;
result->transaction_cancel = db_rbt_trans_dummy;
return result;
}

View File

@ -291,6 +291,27 @@ static int db_tdb_get_seqnum(struct db_context *db)
return tdb_get_seqnum(db_ctx->wtdb->tdb);
}
static int db_tdb_transaction_start(struct db_context *db)
{
struct db_tdb_ctx *db_ctx =
talloc_get_type_abort(db->private_data, struct db_tdb_ctx);
return tdb_transaction_start(db_ctx->wtdb->tdb);
}
static int db_tdb_transaction_commit(struct db_context *db)
{
struct db_tdb_ctx *db_ctx =
talloc_get_type_abort(db->private_data, struct db_tdb_ctx);
return tdb_transaction_commit(db_ctx->wtdb->tdb);
}
static int db_tdb_transaction_cancel(struct db_context *db)
{
struct db_tdb_ctx *db_ctx =
talloc_get_type_abort(db->private_data, struct db_tdb_ctx);
return tdb_transaction_cancel(db_ctx->wtdb->tdb);
}
struct db_context *db_open_tdb(TALLOC_CTX *mem_ctx,
const char *name,
int hash_size, int tdb_flags,
@ -324,6 +345,9 @@ struct db_context *db_open_tdb(TALLOC_CTX *mem_ctx,
result->traverse_read = db_tdb_traverse_read;
result->get_seqnum = db_tdb_get_seqnum;
result->persistent = ((tdb_flags & TDB_CLEAR_IF_FIRST) == 0);
result->transaction_start = db_tdb_transaction_start;
result->transaction_commit = db_tdb_transaction_commit;
result->transaction_cancel = db_tdb_transaction_cancel;
return result;
fail: