summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Adam <obnox@samba.org>2014-04-19 03:34:05 +0200
committerMichael Adam <obnox@samba.org>2014-06-17 09:33:10 +0200
commitc3cb8c277a02a8a68c11ef8d341c8116172e989b (patch)
tree66f9e4a8171e0f73da768c0378d5e72d368a0b1e
parent3cf018935e057c1748ab44491135c632c023de9f (diff)
downloadsamba-c3cb8c277a02a8a68c11ef8d341c8116172e989b.zip
samba-c3cb8c277a02a8a68c11ef8d341c8116172e989b.tar.gz
samba-c3cb8c277a02a8a68c11ef8d341c8116172e989b.tar.xz
ctdb:vacuum: move init of vdata into init_vdata funcion
This is a small code cleanup. vdata is only used in ctdb_vacuum_db() and not in ctdb_vacuum_and_repack_db() where it is currently initialized. This patch moves creation and all previously scattered initialization of vacuum_data into ctdb_vacuum_init_vacuum_data which is called from ctdb_vacuum_db. Signed-off-by: Michael Adam <obnox@samba.org> Reviewed-by: Amitay Isaacs <amitay@gmail.com>
-rw-r--r--ctdb/server/ctdb_vacuum.c75
1 files changed, 43 insertions, 32 deletions
diff --git a/ctdb/server/ctdb_vacuum.c b/ctdb/server/ctdb_vacuum.c
index cb0d993..46c8c93 100644
--- a/ctdb/server/ctdb_vacuum.c
+++ b/ctdb/server/ctdb_vacuum.c
@@ -1170,11 +1170,29 @@ done:
/**
* initialize the vacuum_data
*/
-static int ctdb_vacuum_init_vacuum_data(struct ctdb_db_context *ctdb_db,
- struct vacuum_data *vdata)
+static struct vacuum_data *ctdb_vacuum_init_vacuum_data(
+ struct ctdb_db_context *ctdb_db,
+ TALLOC_CTX *mem_ctx)
{
int i;
struct ctdb_context *ctdb = ctdb_db->ctdb;
+ struct vacuum_data *vdata;
+
+ vdata = talloc_zero(mem_ctx, struct vacuum_data);
+ if (vdata == NULL) {
+ DEBUG(DEBUG_ERR,(__location__ " Out of memory\n"));
+ return NULL;
+ }
+
+ vdata->ctdb = ctdb_db->ctdb;
+ vdata->ctdb_db = ctdb_db;
+ vdata->delete_list = trbt_create(vdata, 0);
+ if (vdata->delete_list == NULL) {
+ DEBUG(DEBUG_ERR,(__location__ " Out of memory\n"));
+ goto fail;
+ }
+
+ vdata->start = timeval_current();
vdata->count.delete_queue.added_to_delete_list = 0;
vdata->count.delete_queue.added_to_vacuum_fetch_list = 0;
@@ -1199,7 +1217,7 @@ static int ctdb_vacuum_init_vacuum_data(struct ctdb_db_context *ctdb_db,
ctdb->num_nodes);
if (vdata->vacuum_fetch_list == NULL) {
DEBUG(DEBUG_ERR,(__location__ " Out of memory\n"));
- return -1;
+ goto fail;
}
for (i = 0; i < ctdb->num_nodes; i++) {
vdata->vacuum_fetch_list[i] = (struct ctdb_marshall_buffer *)
@@ -1207,12 +1225,17 @@ static int ctdb_vacuum_init_vacuum_data(struct ctdb_db_context *ctdb_db,
offsetof(struct ctdb_marshall_buffer, data));
if (vdata->vacuum_fetch_list[i] == NULL) {
DEBUG(DEBUG_ERR,(__location__ " Out of memory\n"));
- return -1;
+ talloc_free(vdata);
+ return NULL;
}
vdata->vacuum_fetch_list[i]->db_id = ctdb_db->db_id;
}
- return 0;
+ return vdata;
+
+fail:
+ talloc_free(vdata);
+ return NULL;
}
/**
@@ -1248,11 +1271,12 @@ static int ctdb_vacuum_init_vacuum_data(struct ctdb_db_context *ctdb_db,
* This executes in the child context.
*/
static int ctdb_vacuum_db(struct ctdb_db_context *ctdb_db,
- struct vacuum_data *vdata,
bool full_vacuum_run)
{
struct ctdb_context *ctdb = ctdb_db->ctdb;
int ret, pnn;
+ struct vacuum_data *vdata;
+ TALLOC_CTX *tmp_ctx;
DEBUG(DEBUG_INFO, (__location__ " Entering %s vacuum run for db "
"%s db_id[0x%08x]\n",
@@ -1273,9 +1297,16 @@ static int ctdb_vacuum_db(struct ctdb_db_context *ctdb_db,
ctdb->pnn = pnn;
- ret = ctdb_vacuum_init_vacuum_data(ctdb_db, vdata);
- if (ret != 0) {
- return ret;
+ tmp_ctx = talloc_new(ctdb_db);
+ if (tmp_ctx == NULL) {
+ DEBUG(DEBUG_ERR, ("Out of memory!\n"));
+ return -1;
+ }
+
+ vdata = ctdb_vacuum_init_vacuum_data(ctdb_db, tmp_ctx);
+ if (vdata == NULL) {
+ talloc_free(tmp_ctx);
+ return -1;
}
if (full_vacuum_run) {
@@ -1288,6 +1319,8 @@ static int ctdb_vacuum_db(struct ctdb_db_context *ctdb_db,
ctdb_process_delete_list(ctdb_db, vdata);
+ talloc_free(tmp_ctx);
+
/* this ensures we run our event queue */
ctdb_ctrl_getpnn(ctdb, TIMELIMIT(), CTDB_CURRENT_NODE);
@@ -1305,27 +1338,9 @@ static int ctdb_vacuum_and_repack_db(struct ctdb_db_context *ctdb_db,
uint32_t repack_limit = ctdb_db->ctdb->tunable.repack_limit;
const char *name = ctdb_db->db_name;
int freelist_size = 0;
- struct vacuum_data *vdata;
int ret;
- vdata = talloc_zero(mem_ctx, struct vacuum_data);
- if (vdata == NULL) {
- DEBUG(DEBUG_ERR,(__location__ " Out of memory\n"));
- return -1;
- }
-
- vdata->ctdb = ctdb_db->ctdb;
- vdata->delete_list = trbt_create(vdata, 0);
- vdata->ctdb_db = ctdb_db;
- if (vdata->delete_list == NULL) {
- DEBUG(DEBUG_ERR,(__location__ " Out of memory\n"));
- talloc_free(vdata);
- return -1;
- }
-
- vdata->start = timeval_current();
-
- if (ctdb_vacuum_db(ctdb_db, vdata, full_vacuum_run) != 0) {
+ if (ctdb_vacuum_db(ctdb_db, full_vacuum_run) != 0) {
DEBUG(DEBUG_ERR,(__location__ " Failed to vacuum '%s'\n", name));
}
@@ -1333,7 +1348,6 @@ static int ctdb_vacuum_and_repack_db(struct ctdb_db_context *ctdb_db,
freelist_size = tdb_freelist_size(ctdb_db->ltdb->tdb);
if (freelist_size == -1) {
DEBUG(DEBUG_ERR,(__location__ " Failed to get freelist size for '%s'\n", name));
- talloc_free(vdata);
return -1;
}
}
@@ -1343,7 +1357,6 @@ static int ctdb_vacuum_and_repack_db(struct ctdb_db_context *ctdb_db,
*/
if ((repack_limit == 0 || (uint32_t)freelist_size < repack_limit))
{
- talloc_free(vdata);
return 0;
}
@@ -1353,10 +1366,8 @@ static int ctdb_vacuum_and_repack_db(struct ctdb_db_context *ctdb_db,
ret = tdb_repack(ctdb_db->ltdb->tdb);
if (ret != 0) {
DEBUG(DEBUG_ERR,(__location__ " Failed to repack '%s'\n", name));
- talloc_free(vdata);
return -1;
}
- talloc_free(vdata);
return 0;
}