Commit 45994398 authored by Daniel Salzman's avatar Daniel Salzman

Merge branch 'fix_diff_load' into 'master'

load: fix update from differences with zone-in-journal

See merge request !926
parents ce8d8d99 8544abc2
......@@ -168,7 +168,8 @@ int event_load(conf_t *conf, zone_t *zone)
ret = zone_update_from_contents(&up, zone, journal_conts, UPDATE_INCREMENTAL);
} else {
// load zone-in-journal, compute ZF diff and if success, apply it
ret = zone_update_from_differences(&up, zone, journal_conts, zf_conts, UPDATE_INCREMENTAL, ignore_dnssec);
ret = zone_update_from_differences(&up, zone, journal_conts, zf_conts,
UPDATE_INCREMENTAL | UPDATE_JOURNAL, ignore_dnssec);
zone_contents_deep_free(zf_conts);
zf_conts = NULL;
if (ret == KNOT_ESEMCHECK || ret == KNOT_ERANGE) {
......@@ -177,9 +178,6 @@ int event_load(conf_t *conf, zone_t *zone)
"ignoring zone file and loading from journal",
(ret == KNOT_ESEMCHECK ? "unupdated" : "decreased"));
ret = zone_update_from_contents(&up, zone, journal_conts, UPDATE_INCREMENTAL);
} else {
zone_contents_deep_free(journal_conts);
journal_conts = NULL;
}
}
} else {
......
......@@ -360,7 +360,7 @@ int apply_remove_rr(apply_ctx_t *ctx, const knot_rrset_t *rr)
return ret;
}
} else {
// RRSet is empty now, remove it from node, all data freed.
// RRSet is empty now, remove it from node, all data freed, except additionals.
node_remove_rdataset(node, rr->type);
// If node is empty now, delete it from zone tree.
if (node->rrset_count == 0 && node != contents->apex) {
......
......@@ -26,7 +26,7 @@
#include <urcu.h>
static int init_incremental(zone_update_t *update, zone_t *zone, zone_contents_t *old_contents)
static int init_incremental(zone_update_t *update, zone_t *zone, zone_contents_t *old_contents, bool deep_copy)
{
if (old_contents == NULL) {
return KNOT_EINVAL;
......@@ -37,12 +37,16 @@ static int init_incremental(zone_update_t *update, zone_t *zone, zone_contents_t
return ret;
}
update->new_cont_deep_copy = false;
ret = apply_prepare_zone_copy(old_contents, &update->new_cont);
if (ret != KNOT_EOK) {
changeset_clear(&update->change);
return ret;
if (deep_copy) {
update->new_cont_deep_copy = true;
update->new_cont = old_contents;
} else {
update->new_cont_deep_copy = false;
ret = apply_prepare_zone_copy(old_contents, &update->new_cont);
if (ret != KNOT_EOK) {
changeset_clear(&update->change);
return ret;
}
}
uint32_t apply_flags = update->flags & UPDATE_STRICT ? APPLY_STRICT : 0;
......@@ -116,7 +120,7 @@ int init_base(zone_update_t *update, zone_t *zone, zone_contents_t *old_contents
int ret = KNOT_EINVAL;
if (flags & UPDATE_INCREMENTAL) {
ret = init_incremental(update, zone, old_contents);
ret = init_incremental(update, zone, old_contents, flags & UPDATE_JOURNAL);
} else if (flags & UPDATE_FULL) {
ret = init_full(update, zone);
}
......
......@@ -45,7 +45,7 @@ typedef enum {
UPDATE_FULL = 1 << 0, /*!< Replace the old zone by a complete new one. */
UPDATE_INCREMENTAL = 1 << 1, /*!< Apply changes to the old zone. */
UPDATE_SIGN = 1 << 2, /*!< Sign the resulting zone. */
UPDATE_DIFF = 1 << 3, /*!< In the case of full update, create a diff for journal. */
UPDATE_JOURNAL = 1 << 3, /*!< Using zone-in-journal for a diff update. */
UPDATE_STRICT = 1 << 4, /*!< Apply changes strictly, i.e. fail when removing nonexistent RR. */
} zone_update_flags_t;
......
......@@ -1125,11 +1125,11 @@ void zone_contents_deep_free(zone_contents_t *contents)
}
if (contents != NULL) {
// Delete NSEC3 tree
// Delete NSEC3 tree.
(void)zone_tree_apply(contents->nsec3_nodes,
destroy_node_rrsets_from_tree, NULL);
// Delete normal tree
// Delete the normal tree.
(void)zone_tree_apply(contents->nodes,
destroy_node_rrsets_from_tree, NULL);
}
......
......@@ -203,6 +203,8 @@ void node_remove_rdataset(zone_node_t *node, uint16_t type)
for (int i = 0; i < node->rrset_count; ++i) {
if (node->rrs[i].type == type) {
// We need to free additionals from this rr_data before it gets overwritten.
additional_clear(node->rrs[i].additional);
memmove(node->rrs + i, node->rrs + i + 1,
(node->rrset_count - i - 1) * sizeof(struct rr_data));
--node->rrset_count;
......
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