Commit 61816111 authored by Libor Peltan's avatar Libor Peltan

adjusting: don't measure size redundantly (takes time)

parent 62f4d7df
......@@ -179,7 +179,7 @@ int knot_dnssec_zone_sign(zone_update_t *update,
goto done;
}
result = zone_adjust_contents(update->new_cont, adjust_cb_flags, NULL);
result = zone_adjust_contents(update->new_cont, adjust_cb_flags, NULL, false);
if (result != KNOT_EOK) {
return result;
};
......
......@@ -613,12 +613,12 @@ static int commit_incremental(conf_t *conf, zone_update_t *update)
}
}
ret = zone_adjust_contents(new_contents, adjust_cb_flags, adjust_cb_nsec3_flags);
ret = zone_adjust_contents(new_contents, adjust_cb_flags, adjust_cb_nsec3_flags, true);
if (ret == KNOT_EOK) {
ret = zone_adjust_update(update, adjust_cb_point_to_nsec3, NULL);
}
if (ret == KNOT_EOK) {
ret = zone_adjust_contents(new_contents, adjust_cb_nsec3wc_and_additionals, NULL);
ret = zone_adjust_contents(new_contents, adjust_cb_nsec3wc_and_additionals, NULL, false);
}
if (ret != KNOT_EOK) {
zone_update_clear(update);
......
......@@ -258,6 +258,7 @@ typedef struct {
uint32_t zone_max_ttl;
adjust_cb_t adjust_cb;
bool adjust_prevs;
bool measure_size;
} zone_adjust_arg_t;
static int adjust_single(zone_node_t **tnode, void *data)
......@@ -283,14 +284,16 @@ static int adjust_single(zone_node_t **tnode, void *data)
args->previous_node = node;
}
node_size(node, &args->zone_size);
if (args->measure_size) {
node_size(node, &args->zone_size);
}
node_max_ttl(node, &args->zone_max_ttl);
return args->adjust_cb(node, args->zone);
}
static int zone_adjust_tree(zone_tree_t *tree, const zone_contents_t *zone, adjust_cb_t adjust_cb,
size_t *tree_size, uint32_t *tree_max_ttl, bool adjust_prevs)
size_t *tree_size, uint32_t *tree_max_ttl, bool adjust_prevs, bool measure_size)
{
if (zone_tree_is_empty(tree)) {
return KNOT_EOK;
......@@ -299,7 +302,8 @@ static int zone_adjust_tree(zone_tree_t *tree, const zone_contents_t *zone, adju
zone_adjust_arg_t arg = {
.zone = zone,
.adjust_cb = adjust_cb,
.adjust_prevs = adjust_prevs
.adjust_prevs = adjust_prevs,
.measure_size = measure_size,
};
int ret = zone_tree_apply(tree, adjust_single, &arg);
......@@ -352,7 +356,7 @@ static int load_nsec3param(zone_contents_t *contents)
return KNOT_EOK;
}
int zone_adjust_contents(zone_contents_t *zone, adjust_cb_t nodes_cb, adjust_cb_t nsec3_cb)
int zone_adjust_contents(zone_contents_t *zone, adjust_cb_t nodes_cb, adjust_cb_t nsec3_cb, bool measure_size)
{
int ret = load_nsec3param(zone);
if (ret != KNOT_EOK) {
......@@ -367,10 +371,10 @@ int zone_adjust_contents(zone_contents_t *zone, adjust_cb_t nodes_cb, adjust_cb_
uint32_t nodes_max_ttl = 0, nsec3_max_ttl = 0;
if (nsec3_cb != NULL) {
ret = zone_adjust_tree(zone->nsec3_nodes, zone, nsec3_cb, &nsec3_size, &nsec3_max_ttl, true);
ret = zone_adjust_tree(zone->nsec3_nodes, zone, nsec3_cb, &nsec3_size, &nsec3_max_ttl, true, measure_size && (nodes_cb != NULL));
}
if (ret == KNOT_EOK && nodes_cb != NULL) {
ret = zone_adjust_tree(zone->nodes, zone, nodes_cb, &nodes_size, &nodes_max_ttl, true);
ret = zone_adjust_tree(zone->nodes, zone, nodes_cb, &nodes_size, &nodes_max_ttl, true, measure_size);
}
if (ret == KNOT_EOK && nodes_cb != NULL && nsec3_cb != NULL) {
zone->size = nodes_size + nsec3_size;
......@@ -383,19 +387,19 @@ int zone_adjust_update(zone_update_t *update, adjust_cb_t nodes_cb, adjust_cb_t
{
int ret = KNOT_EOK;
if (nsec3_cb != NULL) {
ret = zone_adjust_tree(update->a_ctx->nsec3_ptrs, update->new_cont, nsec3_cb, NULL, NULL, false);
ret = zone_adjust_tree(update->a_ctx->nsec3_ptrs, update->new_cont, nsec3_cb, NULL, NULL, false, false);
}
if (ret == KNOT_EOK && nodes_cb != NULL) {
ret = zone_adjust_tree(update->a_ctx->node_ptrs, update->new_cont, nodes_cb, NULL, NULL, false);
ret = zone_adjust_tree(update->a_ctx->node_ptrs, update->new_cont, nodes_cb, NULL, NULL, false, false);
}
return ret;
}
int zone_adjust_full(zone_contents_t *zone)
{
int ret = zone_adjust_contents(zone, adjust_cb_flags, adjust_cb_nsec3_flags);
int ret = zone_adjust_contents(zone, adjust_cb_flags, adjust_cb_nsec3_flags, true);
if (ret == KNOT_EOK) {
ret = zone_adjust_contents(zone, adjust_cb_nsec3_and_additionals, NULL);
ret = zone_adjust_contents(zone, adjust_cb_nsec3_and_additionals, NULL, false);
}
return ret;
}
......@@ -69,7 +69,7 @@ int adjust_cb_void(zone_node_t *node, const zone_contents_t *zone);
*
* \return KNOT_E*
*/
int zone_adjust_contents(zone_contents_t *zone, adjust_cb_t nodes_cb, adjust_cb_t nsec3_cb);
int zone_adjust_contents(zone_contents_t *zone, adjust_cb_t nodes_cb, adjust_cb_t nsec3_cb, bool measure_size);
/*!
* \brief Apply callback to nodes affected by the zone update.
......
......@@ -226,7 +226,7 @@ zone_contents_t *zonefile_load(zloader_t *loader)
goto fail;
}
ret = zone_adjust_contents(zc->z, adjust_cb_flags_and_nsec3, adjust_cb_nsec3_flags);
ret = zone_adjust_contents(zc->z, adjust_cb_flags_and_nsec3, adjust_cb_nsec3_flags, true);
if (ret != KNOT_EOK) {
ERROR(zname, "failed to finalize zone contents (%s)",
knot_strerror(ret));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment