From 7b43362a9ea942e6759fd9298b2a67cb3328520f Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Mon, 12 Nov 2012 13:03:56 +0100 Subject: s3: Avoid db_ctdb_fetch for persistent databases Reviewed-by: Michael Adam --- source3/lib/dbwrap/dbwrap_ctdb.c | 44 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) (limited to 'source3') diff --git a/source3/lib/dbwrap/dbwrap_ctdb.c b/source3/lib/dbwrap/dbwrap_ctdb.c index a971d21d2e..639e385150 100644 --- a/source3/lib/dbwrap/dbwrap_ctdb.c +++ b/source3/lib/dbwrap/dbwrap_ctdb.c @@ -1347,15 +1347,59 @@ static NTSTATUS db_ctdb_fetch(struct db_context *db, TALLOC_CTX *mem_ctx, return status; } +struct db_ctdb_parse_record_state { + void (*parser)(TDB_DATA key, TDB_DATA data, void *private_data); + void *private_data; +}; + +static void db_ctdb_parse_record_parser( + TDB_DATA key, struct ctdb_ltdb_header *header, + TDB_DATA data, void *private_data) +{ + struct db_ctdb_parse_record_state *state = + (struct db_ctdb_parse_record_state *)private_data; + state->parser(key, data, state->private_data); +} + static NTSTATUS db_ctdb_parse_record(struct db_context *db, TDB_DATA key, void (*parser)(TDB_DATA key, TDB_DATA data, void *private_data), void *private_data) { + struct db_ctdb_ctx *ctx = talloc_get_type_abort( + db->private_data, struct db_ctdb_ctx); + struct db_ctdb_parse_record_state state; NTSTATUS status; TDB_DATA data; + state.parser = parser; + state.private_data = private_data; + + if (ctx->transaction != NULL) { + struct db_ctdb_transaction_handle *h = ctx->transaction; + bool found; + + /* + * Transactions only happen for persistent db's. + */ + + found = parse_newest_in_marshall_buffer( + h->m_write, key, db_ctdb_parse_record_parser, &state); + + if (found) { + return NT_STATUS_OK; + } + } + + if (db->persistent) { + /* + * Persistent db, but not found in the transaction buffer + */ + return db_ctdb_ltdb_parse( + ctx, key, db_ctdb_parse_record_parser, &state); + } + status = db_ctdb_fetch(db, talloc_tos(), key, &data); if (!NT_STATUS_IS_OK(status)) { return status; -- cgit