ctdb-vacuum: Use ctdb_marshall_add to add a record to marshall buffer
authorAmitay Isaacs <amitay@gmail.com>
Tue, 6 May 2014 08:39:25 +0000 (18:39 +1000)
committerAmitay Isaacs <amitay@samba.org>
Wed, 23 Jul 2014 05:18:11 +0000 (07:18 +0200)
This avoids duplicate code and extra talloc in ctdb_marshall_record.

Signed-off-by: Amitay Isaacs <amitay@gmail.com>
Reviewed-by: Volker Lendecke <vl@samba.org>
ctdb/server/ctdb_vacuum.c

index 491103f8c3465d309f2d8e6a88cea30ea3d8fbbe..fe59a83fcfac13dcb26bfe7ae9047f26d3683e70 100644 (file)
@@ -181,35 +181,23 @@ static int add_record_to_vacuum_fetch_list(struct vacuum_data *vdata,
                                           TDB_DATA key)
 {
        struct ctdb_context *ctdb = vdata->ctdb;
-       struct ctdb_rec_data *rec;
        uint32_t lmaster;
-       size_t old_size;
        struct ctdb_marshall_buffer *vfl;
 
        lmaster = ctdb_lmaster(ctdb, &key);
 
        vfl = vdata->vacuum_fetch_list[lmaster];
 
-       rec = ctdb_marshall_record(vfl, ctdb->pnn, key, NULL, tdb_null);
-       if (rec == NULL) {
+       vfl = ctdb_marshall_add(ctdb, vfl, vfl->db_id, ctdb->pnn,
+                               key, NULL, tdb_null);
+       if (vfl == NULL) {
                DEBUG(DEBUG_ERR,(__location__ " Out of memory\n"));
                vdata->traverse_error = true;
                return -1;
        }
 
-       old_size = talloc_get_size(vfl);
-       vfl = talloc_realloc_size(NULL, vfl, old_size + rec->length);
-       if (vfl == NULL) {
-               DEBUG(DEBUG_ERR,(__location__ " Failed to expand\n"));
-               vdata->traverse_error = true;
-               return -1;
-       }
        vdata->vacuum_fetch_list[lmaster] = vfl;
 
-       vfl->count++;
-       memcpy(old_size+(uint8_t *)vfl, rec, rec->length);
-       talloc_free(rec);
-
        return 0;
 }
 
@@ -294,23 +282,17 @@ static int delete_marshall_traverse(void *param, void *data)
 {
        struct delete_record_data *dd = talloc_get_type(data, struct delete_record_data);
        struct delete_records_list *recs = talloc_get_type(param, struct delete_records_list);
-       struct ctdb_rec_data *rec;
-       size_t old_size;
+       struct ctdb_marshall_buffer *m;
 
-       rec = ctdb_marshall_record(dd, recs->records->db_id, dd->key, &dd->hdr, tdb_null);
-       if (rec == NULL) {
+       m = ctdb_marshall_add(recs, recs->records, recs->records->db_id,
+                             recs->records->db_id,
+                             dd->key, &dd->hdr, tdb_null);
+       if (m == NULL) {
                DEBUG(DEBUG_ERR, (__location__ " failed to marshall record\n"));
-               return 0;
-       }
-
-       old_size = talloc_get_size(recs->records);
-       recs->records = talloc_realloc_size(recs, recs->records, old_size + rec->length);
-       if (recs->records == NULL) {
-               DEBUG(DEBUG_ERR,(__location__ " Failed to expand\n"));
                return -1;
        }
-       recs->records->count++;
-       memcpy(old_size+(uint8_t *)(recs->records), rec, rec->length);
+
+       recs->records = m;
        return 0;
 }