/* 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_db_context *ctdb_db, TDB_DATA key, struct ctdb_ltdb_header *header, TALLOC_CTX *mem_ctx, TDB_DATA *data) { TDB_DATA rec; struct ctdb_context *ctdb = ctdb_db->ctdb; rec = tdb_fetch(ctdb_db->ltdb->tdb, key); if (rec.dsize < sizeof(*header)) { /* return an initial header */ if (rec.dptr) free(rec.dptr); if (ctdb->vnn_map == NULL) { /* called from the client */ ZERO_STRUCTP(data); header->dmaster = (uint32_t)-1; return -1; } ltdb_initial_header(ctdb_db, key, header); if (data) { *data = tdb_null; } if (ctdb_db->persistent || header->dmaster == ctdb_db->ctdb->pnn) { if (ctdb_ltdb_store(ctdb_db, key, header, tdb_null) != 0) { DEBUG(DEBUG_NOTICE, (__location__ "failed to store initial header\n")); } } return 0; } *header = *(struct ctdb_ltdb_header *)rec.dptr; if (data) { data->dsize = rec.dsize - sizeof(struct ctdb_ltdb_header); data->dptr = talloc_memdup(mem_ctx, sizeof(struct ctdb_ltdb_header)+rec.dptr, data->dsize); } free(rec.dptr); if (data) { 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_fetch(struct ctdb_db_context *ctdb_db, TDB_DATA key, struct ctdb_ltdb_header *header, TALLOC_CTX *mem_ctx, TDB_DATA *data) { TDB_DATA rec; struct ctdb_context *ctdb = ctdb_db->ctdb; rec = tdb_fetch(ctdb_db->ltdb->tdb, key); if (rec.dsize < sizeof(*header)) { TDB_DATA d2; /* return an initial header */ if (rec.dptr) free(rec.dptr); if (ctdb->vnn_map == NULL) { /* called from the client */ ZERO_STRUCTP(data); header->dmaster = (uint32_t)-1; return -1; } ltdb_initial_header(ctdb_db, key, header); ZERO_STRUCT(d2); if (data) { *data = d2; } ctdb_ltdb_store(ctdb_db, key, header, d2); return 0; } *header = *(struct ctdb_ltdb_header *)rec.dptr; if (data) { data->dsize = rec.dsize - sizeof(struct ctdb_ltdb_header); data->dptr = talloc_memdup(mem_ctx, sizeof(struct ctdb_ltdb_header)+rec.dptr, data->dsize); } free(rec.dptr); if (data) { CTDB_NO_MEMORY(ctdb, data->dptr); } return 0; }