ReadOnly: Add a ctdb_ltdb_fetch_readonly() helper function
authorRonnie Sahlberg <ronniesahlberg@gmail.com>
Wed, 20 Jul 2011 05:31:44 +0000 (15:31 +1000)
committerRonnie Sahlberg <ronniesahlberg@gmail.com>
Tue, 23 Aug 2011 00:33:17 +0000 (10:33 +1000)
common/ctdb_ltdb.c
include/ctdb_private.h

index bc17b47e6a892734e634fb39fd937e85ca66eca8..76274ceafba0bd8c96e6214a047200383ec4216a 100644 (file)
@@ -119,6 +119,40 @@ int ctdb_ltdb_fetch(struct ctdb_db_context *ctdb_db,
        return 0;
 }
 
+/*
+  fetch a record from the ltdb, separating out the header information
+  and returning the body of the record.
+  if the record does not exist, *header will be NULL
+  and data = {0, NULL}
+*/
+int ctdb_ltdb_fetch_readonly(struct ctdb_db_context *ctdb_db, 
+                   TDB_DATA key, struct ctdb_ltdb_header *header, 
+                   TALLOC_CTX *mem_ctx, TDB_DATA *data)
+{
+       TDB_DATA rec;
+
+       rec = tdb_fetch(ctdb_db->ltdb->tdb, key);
+       if (rec.dsize < sizeof(*header)) {
+               free(rec.dptr);
+
+               data->dsize = 0;
+               data->dptr = NULL;
+               return -1;
+       }
+
+       *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);
+
+       return 0;
+}
+
 
 /*
   write a record to a normal database
index 93ac28e41610fddb57b38008b0cbb7084635b141..4937bc8762ffb5bd0a61c765c336c4a0823770a2 100644 (file)
@@ -669,6 +669,9 @@ int ctdb_ltdb_fetch(struct ctdb_db_context *ctdb_db,
 int ctdb_ltdb_store(struct ctdb_db_context *ctdb_db, TDB_DATA key, 
                    struct ctdb_ltdb_header *header, TDB_DATA data);
 int ctdb_ltdb_delete(struct ctdb_db_context *ctdb_db, TDB_DATA key);
+int ctdb_ltdb_fetch_readonly(struct ctdb_db_context *ctdb_db,
+                  TDB_DATA key, struct ctdb_ltdb_header *header,
+                  TALLOC_CTX *mem_ctx, TDB_DATA *data);
 int32_t ctdb_control_start_persistent_update(struct ctdb_context *ctdb, 
                        struct ctdb_req_control *c,
                        TDB_DATA recdata);