summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Adam <obnox@samba.org>2010-12-20 16:31:27 +0100
committerMichael Adam <obnox@samba.org>2011-03-14 13:35:46 +0100
commit3d7bfc7a3ea03d3228cdec326e11aa491a8f574d (patch)
tree910dcb626912b817f31527725e60a7454d4e5ba3
parentee593284d5e489cfa6e7405012b6d4824163c8b1 (diff)
downloadsamba-3d7bfc7a3ea03d3228cdec326e11aa491a8f574d.tar.gz
samba-3d7bfc7a3ea03d3228cdec326e11aa491a8f574d.tar.xz
samba-3d7bfc7a3ea03d3228cdec326e11aa491a8f574d.zip
vacuum: refactor new add_record_to_vacuum_fetch_list() out of vacuum_traverse().
This is the function that fills the list of records to send to each lmaster with the VACUUM_FETCH message. This function will be reused in the traverse function for the delete_queue. (This used to be ctdb commit d4ab790c1f679e833eb97816762fcfcee15ccb10)
-rw-r--r--ctdb/server/ctdb_vacuum.c67
1 files changed, 44 insertions, 23 deletions
diff --git a/ctdb/server/ctdb_vacuum.c b/ctdb/server/ctdb_vacuum.c
index cbc2acbd04..964eeabe74 100644
--- a/ctdb/server/ctdb_vacuum.c
+++ b/ctdb/server/ctdb_vacuum.c
@@ -91,6 +91,46 @@ struct delete_records_list {
struct ctdb_marshall_buffer *records;
};
+/**
+ * Add a record to the list of records to be sent
+ * to their lmaster with VACUUM_FETCH.
+ */
+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;
+
+ lmaster = ctdb_lmaster(ctdb, &key);
+
+ rec = ctdb_marshall_record(vdata->list[lmaster], ctdb->pnn, key, NULL, tdb_null);
+ if (rec == NULL) {
+ DEBUG(DEBUG_ERR,(__location__ " Out of memory\n"));
+ vdata->traverse_error = true;
+ return -1;
+ }
+
+ old_size = talloc_get_size(vdata->list[lmaster]);
+ vdata->list[lmaster] = talloc_realloc_size(NULL, vdata->list[lmaster],
+ old_size + rec->length);
+ if (vdata->list[lmaster] == NULL) {
+ DEBUG(DEBUG_ERR,(__location__ " Failed to expand\n"));
+ vdata->traverse_error = true;
+ return -1;
+ }
+
+ vdata->list[lmaster]->count++;
+ memcpy(old_size+(uint8_t *)vdata->list[lmaster], rec, rec->length);
+ talloc_free(rec);
+
+ vdata->total++;
+
+ return 0;
+}
+
+
static void ctdb_vacuum_event(struct event_context *ev, struct timed_event *te,
struct timeval t, void *private_data);
@@ -105,9 +145,8 @@ static int vacuum_traverse(struct tdb_context *tdb, TDB_DATA key, TDB_DATA data,
struct ctdb_db_context *ctdb_db = vdata->ctdb_db;
uint32_t lmaster;
struct ctdb_ltdb_header *hdr;
- struct ctdb_rec_data *rec;
- size_t old_size;
-
+ int res;
+
lmaster = ctdb_lmaster(ctdb, &key);
if (lmaster >= ctdb->num_nodes) {
DEBUG(DEBUG_CRIT, (__location__
@@ -168,27 +207,9 @@ static int vacuum_traverse(struct tdb_context *tdb, TDB_DATA key, TDB_DATA data,
}
/* add the record to the blob ready to send to the nodes */
- rec = ctdb_marshall_record(vdata->list[lmaster], ctdb->pnn, key, NULL, tdb_null);
- if (rec == NULL) {
- DEBUG(DEBUG_ERR,(__location__ " Out of memory\n"));
- vdata->traverse_error = true;
- return -1;
- }
- old_size = talloc_get_size(vdata->list[lmaster]);
- vdata->list[lmaster] = talloc_realloc_size(NULL, vdata->list[lmaster],
- old_size + rec->length);
- if (vdata->list[lmaster] == NULL) {
- DEBUG(DEBUG_ERR,(__location__ " Failed to expand\n"));
- vdata->traverse_error = true;
- return -1;
- }
- vdata->list[lmaster]->count++;
- memcpy(old_size+(uint8_t *)vdata->list[lmaster], rec, rec->length);
- talloc_free(rec);
+ res = add_record_to_vacuum_fetch_list(vdata, key);
- vdata->total++;
-
- return 0;
+ return res;
}
/*