diff options
author | Michael Adam <obnox@samba.org> | 2012-12-17 13:03:42 +0100 |
---|---|---|
committer | Amitay Isaacs <amitay@gmail.com> | 2013-04-24 18:46:47 +1000 |
commit | 79fc6c01d8f252b2cc0954f86801b0091cf48afc (patch) | |
tree | c0e10b3d2d6802b13dd024554d2a2908d982d57b | |
parent | 0a77ae018cbe880243c6c418a4da979c3aeb31aa (diff) | |
download | samba-79fc6c01d8f252b2cc0954f86801b0091cf48afc.tar.gz samba-79fc6c01d8f252b2cc0954f86801b0091cf48afc.tar.xz samba-79fc6c01d8f252b2cc0954f86801b0091cf48afc.zip |
vacuum: simplify ctdb_process_delete_list(): reduce indentation
Signed-off-by: Michael Adam <obnox@samba.org>
Reviewed-By: Amitay Isaacs <amitay@gmail.com>
(This used to be ctdb commit f3e6e7f8ef22bd70dd2f101d818e2e5ab5ed3cd8)
-rw-r--r-- | ctdb/server/ctdb_vacuum.c | 227 |
1 files changed, 114 insertions, 113 deletions
diff --git a/ctdb/server/ctdb_vacuum.c b/ctdb/server/ctdb_vacuum.c index 92691c1ee9b..3b6e3262fbc 100644 --- a/ctdb/server/ctdb_vacuum.c +++ b/ctdb/server/ctdb_vacuum.c @@ -714,135 +714,136 @@ static int ctdb_process_delete_list(struct ctdb_db_context *ctdb_db, { int ret, i; struct ctdb_context *ctdb = ctdb_db->ctdb; + struct delete_records_list *recs; + TDB_DATA indata, outdata; + int32_t res; + struct ctdb_node_map *nodemap; + uint32_t *active_nodes; + int num_active_nodes; + + if (vdata->delete_count == 0) { + return 0; + } vdata->delete_left = vdata->delete_count; - if (vdata->delete_count > 0) { - struct delete_records_list *recs; - TDB_DATA indata, outdata; - int32_t res; - struct ctdb_node_map *nodemap; - uint32_t *active_nodes; - int num_active_nodes; - - recs = talloc_zero(vdata, struct delete_records_list); - if (recs == NULL) { - DEBUG(DEBUG_ERR,(__location__ " Out of memory\n")); - return -1; - } - recs->records = (struct ctdb_marshall_buffer *) - talloc_zero_size(vdata, - offsetof(struct ctdb_marshall_buffer, data)); - if (recs->records == NULL) { - DEBUG(DEBUG_ERR,(__location__ " Out of memory\n")); - return -1; - } - recs->records->db_id = ctdb_db->db_id; + recs = talloc_zero(vdata, struct delete_records_list); + if (recs == NULL) { + DEBUG(DEBUG_ERR,(__location__ " Out of memory\n")); + return -1; + } + recs->records = (struct ctdb_marshall_buffer *) + talloc_zero_size(vdata, + offsetof(struct ctdb_marshall_buffer, data)); + if (recs->records == NULL) { + DEBUG(DEBUG_ERR,(__location__ " Out of memory\n")); + return -1; + } + recs->records->db_id = ctdb_db->db_id; - /* - * traverse the tree of all records we want to delete and - * create a blob we can send to the other nodes. - */ - trbt_traversearray32(vdata->delete_list, 1, - delete_marshall_traverse, recs); + /* + * traverse the tree of all records we want to delete and + * create a blob we can send to the other nodes. + */ + trbt_traversearray32(vdata->delete_list, 1, + delete_marshall_traverse, recs); - indata.dsize = talloc_get_size(recs->records); - indata.dptr = (void *)recs->records; + indata.dsize = talloc_get_size(recs->records); + indata.dptr = (void *)recs->records; - /* - * now tell all the active nodes to delete all these records - * (if possible) - */ + /* + * now tell all the active nodes to delete all these records + * (if possible) + */ + + ret = ctdb_ctrl_getnodemap(ctdb, TIMELIMIT(), + CTDB_CURRENT_NODE, + recs, /* talloc context */ + &nodemap); + if (ret != 0) { + DEBUG(DEBUG_ERR,(__location__ " unable to get node map\n")); + return -1; + } - ret = ctdb_ctrl_getnodemap(ctdb, TIMELIMIT(), - CTDB_CURRENT_NODE, - recs, /* talloc context */ - &nodemap); - if (ret != 0) { - DEBUG(DEBUG_ERR,(__location__ " unable to get node map\n")); + active_nodes = list_of_active_nodes(ctdb, nodemap, + nodemap, /* talloc context */ + false /* include self */); + /* yuck! ;-) */ + num_active_nodes = talloc_get_size(active_nodes)/sizeof(*active_nodes); + + for (i = 0; i < num_active_nodes; i++) { + struct ctdb_marshall_buffer *records; + struct ctdb_rec_data *rec; + + ret = ctdb_control(ctdb, active_nodes[i], 0, + CTDB_CONTROL_TRY_DELETE_RECORDS, 0, + indata, recs, &outdata, &res, + NULL, NULL); + if (ret != 0 || res != 0) { + DEBUG(DEBUG_ERR, ("Failed to delete records on " + "node %u: ret[%d] res[%d]\n", + active_nodes[i], ret, res)); return -1; } - active_nodes = list_of_active_nodes(ctdb, nodemap, - nodemap, /* talloc context */ - false /* include self */); - /* yuck! ;-) */ - num_active_nodes = talloc_get_size(active_nodes)/sizeof(*active_nodes); - - for (i = 0; i < num_active_nodes; i++) { - struct ctdb_marshall_buffer *records; - struct ctdb_rec_data *rec; - - ret = ctdb_control(ctdb, active_nodes[i], 0, - CTDB_CONTROL_TRY_DELETE_RECORDS, 0, - indata, recs, &outdata, &res, - NULL, NULL); - if (ret != 0 || res != 0) { - DEBUG(DEBUG_ERR, ("Failed to delete records on " - "node %u: ret[%d] res[%d]\n", - active_nodes[i], ret, res)); + /* + * outdata contains the list of records coming back + * from the node: These are the records that the + * remote node could not delete. + * + * NOTE: There is a problem here: + * + * When a node failed to delete the record, but + * others succeeded, we may have created gaps in the + * history of the record. Hence when a node dies, an + * closed file handle might be resurrected or an open + * file handle might be lost, leading to blocked access + * or data corruption. + * + * TODO: This needs to be fixed! + */ + records = (struct ctdb_marshall_buffer *)outdata.dptr; + rec = (struct ctdb_rec_data *)&records->data[0]; + while (records->count-- > 1) { + TDB_DATA reckey, recdata; + struct ctdb_ltdb_header *rechdr; + struct delete_record_data *dd; + + reckey.dptr = &rec->data[0]; + reckey.dsize = rec->keylen; + recdata.dptr = &rec->data[reckey.dsize]; + recdata.dsize = rec->datalen; + + if (recdata.dsize < sizeof(struct ctdb_ltdb_header)) { + DEBUG(DEBUG_CRIT,(__location__ " bad ltdb record\n")); return -1; } - - /* - * outdata contains the list of records coming back - * from the node: These are the records that the - * remote node could not delete. - * - * NOTE: There is a problem here: - * - * When a node failed to delete the record, but - * others succeeded, we may have created gaps in the - * history of the record. Hence when a node dies, an - * closed file handle might be resurrected or an open - * file handle might be lost, leading to blocked access - * or data corruption. - * - * TODO: This needs to be fixed! - */ - records = (struct ctdb_marshall_buffer *)outdata.dptr; - rec = (struct ctdb_rec_data *)&records->data[0]; - while (records->count-- > 1) { - TDB_DATA reckey, recdata; - struct ctdb_ltdb_header *rechdr; - struct delete_record_data *dd; - - reckey.dptr = &rec->data[0]; - reckey.dsize = rec->keylen; - recdata.dptr = &rec->data[reckey.dsize]; - recdata.dsize = rec->datalen; - - if (recdata.dsize < sizeof(struct ctdb_ltdb_header)) { - DEBUG(DEBUG_CRIT,(__location__ " bad ltdb record\n")); - return -1; - } - rechdr = (struct ctdb_ltdb_header *)recdata.dptr; - recdata.dptr += sizeof(*rechdr); - recdata.dsize -= sizeof(*rechdr); - - dd = (struct delete_record_data *)trbt_lookup32( - vdata->delete_list, - ctdb_hash(&reckey)); - if (dd != NULL) { - /* - * The other node could not delete the - * record and it is the first node that - * failed. So we should remove it from - * the tree and update statistics. - */ - talloc_free(dd); - vdata->delete_remote_error++; - vdata->delete_left--; - } - - rec = (struct ctdb_rec_data *)(rec->length + (uint8_t *)rec); + rechdr = (struct ctdb_ltdb_header *)recdata.dptr; + recdata.dptr += sizeof(*rechdr); + recdata.dsize -= sizeof(*rechdr); + + dd = (struct delete_record_data *)trbt_lookup32( + vdata->delete_list, + ctdb_hash(&reckey)); + if (dd != NULL) { + /* + * The other node could not delete the + * record and it is the first node that + * failed. So we should remove it from + * the tree and update statistics. + */ + talloc_free(dd); + vdata->delete_remote_error++; + vdata->delete_left--; } - } - /* free nodemap and active_nodes */ - talloc_free(nodemap); + rec = (struct ctdb_rec_data *)(rec->length + (uint8_t *)rec); + } } + /* free nodemap and active_nodes */ + talloc_free(nodemap); + if (vdata->delete_left > 0) { /* * The only records remaining in the tree are those |