Commit 19f017ba authored by Libor Peltan's avatar Libor Peltan Committed by Daniel Salzman

switched to COW trie for incremental updates

parent 475a2e80
......@@ -436,6 +436,18 @@ void update_rollback(apply_ctx_t *ctx)
zone_tree_free(&ctx->node_ptrs);
zone_tree_free(&ctx->nsec3_ptrs);
trie_cow_rollback(ctx->contents->nodes->cow, trie_cb_noop, NULL);
if (ctx->contents->nsec3_nodes != NULL) {
trie_cow_rollback(ctx->contents->nsec3_nodes->cow, trie_cb_noop, NULL);
}
free(ctx->contents->nodes);
free(ctx->contents->nsec3_nodes);
dnssec_nsec3_params_free(&ctx->contents->nsec3_params);
free(ctx->contents);
}
void update_free_zone(zone_contents_t *contents)
......@@ -444,8 +456,13 @@ void update_free_zone(zone_contents_t *contents)
return;
}
zone_tree_free(&contents->nodes);
zone_tree_free(&contents->nsec3_nodes);
trie_cow_commit(contents->nodes->cow, trie_cb_noop, NULL);
if (contents->nsec3_nodes != NULL) {
trie_cow_commit(contents->nsec3_nodes->cow, trie_cb_noop, NULL);
}
free(contents->nodes);
free(contents->nsec3_nodes);
dnssec_nsec3_params_free(&contents->nsec3_params);
......
......@@ -328,7 +328,6 @@ void zone_update_clear(zone_update_t *update)
zone_contents_deep_free(update->new_cont);
} else {
update_rollback(update->a_ctx);
update_free_zone(update->new_cont);
}
changeset_clear(&update->change);
} else if (update->flags & UPDATE_FULL) {
......
......@@ -57,10 +57,12 @@ zone_tree_t *zone_tree_create(bool use_binodes)
return t;
}
static void *identity(void *x, knot_mm_t *mm)
void trie_cb_noop(trie_val_t val, const unsigned char *key, size_t len, void *d)
{
UNUSED(mm);
return x;
(void)val;
(void)key;
(void)len;
(void)d;
}
zone_tree_t *zone_tree_dup(zone_tree_t *from)
......@@ -70,7 +72,9 @@ zone_tree_t *zone_tree_dup(zone_tree_t *from)
return to;
}
to->flags = from->flags ^ ZONE_TREE_BINO_SECOND;
to->trie = trie_dup(from->trie, identity, NULL);
from->cow = trie_cow(from->trie, trie_cb_noop, NULL);
to->cow = from->cow;
to->trie = trie_cow_new(to->cow);
if (to->trie == NULL) {
free(to);
to = NULL;
......@@ -91,7 +95,12 @@ int zone_tree_insert(zone_tree_t *tree, zone_node_t **node)
assert((bool)((*node)->flags & NODE_FLAGS_BINODE) == (bool)(tree->flags & ZONE_TREE_USE_BINODES));
*trie_get_ins(tree->trie, lf + 1, *lf) = binode_node(*node, false);
if (tree->cow != NULL) {
*trie_get_cow(tree->cow, lf + 1, *lf) = binode_node(*node, false);
} else {
*trie_get_ins(tree->trie, lf + 1, *lf) = binode_node(*node, false);
}
*node = binode_node(*node, (tree->flags & ZONE_TREE_USE_BINODES) && (tree->flags & ZONE_TREE_BINO_SECOND));
......@@ -188,7 +197,11 @@ void zone_tree_remove_node(zone_tree_t *tree, const knot_dname_t *owner)
trie_val_t *rval = trie_get_try(tree->trie, lf + 1, *lf);
if (rval != NULL) {
trie_del(tree->trie, lf + 1, *lf, NULL);
if (tree->cow != NULL) {
trie_del_cow(tree->cow, lf + 1, *lf, NULL);
} else {
trie_del(tree->trie, lf + 1, *lf, NULL);
}
}
}
......
......@@ -26,6 +26,7 @@ enum {
typedef struct {
trie_t *trie;
trie_cow_t *cow; // non-NULL only during zone update
uint16_t flags;
} zone_tree_t;
......@@ -53,6 +54,8 @@ typedef struct {
*/
zone_tree_t *zone_tree_create(bool use_binodes);
void trie_cb_noop(trie_val_t val, const unsigned char *key, size_t len, void *d);
zone_tree_t *zone_tree_dup(zone_tree_t *from);
/*!
......
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