From: Andrew Tridgell Date: Mon, 18 Dec 2006 02:24:02 +0000 (+1100) Subject: added storage of extended ltdb header information X-Git-Tag: tevent-0.9.20~348^2~3000 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=3804b8b3e400af8ec94a1778df5f51e8337ef2ff;p=thirdparty%2Fsamba.git added storage of extended ltdb header information (This used to be ctdb commit a18c9411081a4e5997bf030fa924abfc33fb3310) --- diff --git a/ctdb/common/ctdb_call.c b/ctdb/common/ctdb_call.c index a2219403a25..441e22b613c 100644 --- a/ctdb/common/ctdb_call.c +++ b/ctdb/common/ctdb_call.c @@ -34,18 +34,20 @@ static int ctdb_call_local(struct ctdb_context *ctdb, TDB_DATA key, int call_id, struct ctdb_call *c; struct ctdb_registered_call *fn; TDB_DATA data; + struct ctdb_ltdb_header header; + int ret; c = talloc(ctdb, struct ctdb_call); CTDB_NO_MEMORY(ctdb, c); - data = tdb_fetch(ctdb->ltdb, key); + ret = ctdb_ltdb_fetch(ctdb, c, key, &header, &data); + if (ret != 0) return -1; c->key = key; c->call_data = call_data; c->record_data.dptr = talloc_memdup(c, data.dptr, data.dsize); c->record_data.dsize = data.dsize; CTDB_NO_MEMORY(ctdb, c->record_data.dptr); - if (data.dptr) free(data.dptr); c->new_data = NULL; c->reply_data = NULL; @@ -58,13 +60,12 @@ static int ctdb_call_local(struct ctdb_context *ctdb, TDB_DATA key, int call_id, } if (fn->fn(c) != 0) { - free(c->record_data.dptr); ctdb_set_error(ctdb, "ctdb_call %u failed\n", call_id); return -1; } if (c->new_data) { - if (tdb_store(ctdb->ltdb, key, *c->new_data, TDB_REPLACE) != 0) { + if (ctdb_ltdb_store(ctdb, key, &header, *c->new_data) != 0) { ctdb_set_error(ctdb, "ctdb_call tdb_store failed\n"); return -1; } diff --git a/ctdb/common/ctdb_ltdb.c b/ctdb/common/ctdb_ltdb.c index 4fe316f4db9..004ab254d5d 100644 --- a/ctdb/common/ctdb_ltdb.c +++ b/ctdb/common/ctdb_ltdb.c @@ -40,3 +40,72 @@ int ctdb_attach(struct ctdb_context *ctdb, const char *name, int tdb_flags, } return 0; } + + +/* + construct an initial header for a record with no ltdb header yet +*/ +static void ltdb_initial_header(struct ctdb_context *ctdb, + TDB_DATA key, + struct ctdb_ltdb_header *header) +{ + header->rsn = 0; + header->dmaster = ctdb_hash(&key) % ctdb->num_nodes; + header->laccessor = header->dmaster; + header->lacount = 0; +} + + +/* + fetch a record from the ltdb, separating out the header information + and returning the body of the record. A valid (initial) header is + returned if the record is not present +*/ +int ctdb_ltdb_fetch(struct ctdb_context *ctdb, TALLOC_CTX *mem_ctx, + TDB_DATA key, struct ctdb_ltdb_header *header, TDB_DATA *data) +{ + TDB_DATA rec; + + rec = tdb_fetch(ctdb->ltdb, key); + if (rec.dsize < sizeof(*header)) { + /* return an initial header */ + ltdb_initial_header(ctdb, key, header); + data->dptr = NULL; + data->dsize = 0; + return 0; + } + + *header = *(struct ctdb_ltdb_header *)rec.dptr; + + data->dsize = rec.dsize - sizeof(struct ctdb_ltdb_header); + data->dptr = talloc_memdup(mem_ctx, sizeof(struct ctdb_ltdb_header)+rec.dptr, + data->dsize); + CTDB_NO_MEMORY(ctdb, data->dptr); + + return 0; +} + + +/* + fetch a record from the ltdb, separating out the header information + and returning the body of the record. A valid (initial) header is + returned if the record is not present +*/ +int ctdb_ltdb_store(struct ctdb_context *ctdb, TDB_DATA key, + struct ctdb_ltdb_header *header, TDB_DATA data) +{ + TDB_DATA rec; + int ret; + + rec.dsize = sizeof(struct ctdb_ltdb_header) + data.dsize; + rec.dptr = talloc_size(ctdb, rec.dsize); + CTDB_NO_MEMORY(ctdb, rec.dptr); + + memcpy(rec.dptr, header, sizeof(*header)); + memcpy(rec.dptr + sizeof(*header), data.dptr, data.dsize); + + ret = tdb_store(ctdb->ltdb, key, rec, TDB_REPLACE); + talloc_free(rec.dptr); + + return ret; +} diff --git a/ctdb/include/ctdb_private.h b/ctdb/include/ctdb_private.h index 32f258b2bf8..bbddd74b589 100644 --- a/ctdb/include/ctdb_private.h +++ b/ctdb/include/ctdb_private.h @@ -101,13 +101,26 @@ struct ctdb_context { /* arbitrary maximum timeout for ctdb operations */ #define CTDB_REQ_TIMEOUT 10 +/* + the extended header for records in the ltdb +*/ +struct ctdb_ltdb_header { + uint64_t rsn; + uint32_t dmaster; + uint32_t laccessor; + uint32_t lacount; +}; + /* operation IDs */ enum ctdb_operation { CTDB_REQ_CALL = 0, - CTDB_REPLY_CALL = 1 + CTDB_REPLY_CALL = 1, + CTDB_REPLY_REDIRECT = 2, + CTDB_REQ_DMASTER = 3, + CTDB_REPLY_DMASTER = 4, }; /* @@ -145,3 +158,9 @@ uint32_t ctdb_hash(TDB_DATA *key); void ctdb_request_call(struct ctdb_context *ctdb, struct ctdb_req_header *hdr); void ctdb_reply_call(struct ctdb_context *ctdb, struct ctdb_req_header *hdr); +int ctdb_ltdb_fetch(struct ctdb_context *ctdb, TALLOC_CTX *mem_ctx, + TDB_DATA key, struct ctdb_ltdb_header *header, TDB_DATA *data); +int ctdb_ltdb_store(struct ctdb_context *ctdb, TDB_DATA key, + struct ctdb_ltdb_header *header, TDB_DATA data); + +