Commit 9e99c527 authored by Libor Peltan's avatar Libor Peltan Committed by Daniel Salzman

zone-in-journal: load journal directly into zone contents

parent 072e09f8
......@@ -503,23 +503,6 @@ bool changeset_differs_just_serial(const changeset_t *ch)
return ret;
}
int changeset_to_contents(changeset_t *ch, zone_contents_t **out)
{
assert(ch->soa_from == NULL);
assert(zone_contents_is_empty(ch->remove));
assert(out != NULL);
*out = ch->add;
int ret = add_rr_to_contents(*out, ch->soa_to);
knot_rrset_free(ch->soa_to, NULL);
if (ret != KNOT_EOK) {
zone_contents_deep_free(*out);
}
zone_contents_deep_free(ch->remove);
return ret;
}
changeset_t *changeset_from_contents(const zone_contents_t *contents)
{
zone_contents_t *copy = NULL;
......
......@@ -192,16 +192,6 @@ int changeset_cancelout(changeset_t *ch);
*/
bool changeset_differs_just_serial(const changeset_t *ch);
/*!
* \brief Loads zone contents from botstrap changeset.
*
* \param ch Changeset to load from, will be freed!
* \param out Zone contents.
*
* \return KNOT_E*
*/
int changeset_to_contents(changeset_t *ch, zone_contents_t **out);
/*!
* \brief Creates a bootstrap changeset from zone.
*
......
......@@ -114,35 +114,46 @@ int zone_load_from_journal(conf_t *conf, zone_t *zone, zone_contents_t **content
return KNOT_EINVAL;
}
*contents = zone_contents_new(zone->name);
if (*contents == NULL) {
return KNOT_ENOMEM;
}
journal_read_t *read = NULL;
int ret = journal_read_begin(zone_journal(zone), true, 0, &read);
if (ret != KNOT_EOK) {
if (ret == KNOT_ENOENT) {
zone_contents_free(*contents);
return ret;
}
changeset_t zone_in_j;
apply_ctx_t a_ctx = { 0 };
ret = journal_read_changeset(read, &zone_in_j) ? KNOT_EOK : KNOT_ENOENT;
if (ret == KNOT_EOK) {
ret = changeset_to_contents(&zone_in_j, contents);
knot_rrset_t rr = { 0 };
while (ret == KNOT_EOK && journal_read_rrset(read, &rr, false)) {
zone_node_t *unused = NULL;
ret = zone_contents_add_rr(*contents, &rr, &unused);
journal_read_clear_rrset(&rr);
}
apply_ctx_t a_ctx = { 0 };
if (ret == KNOT_EOK) {
ret = apply_init_ctx(&a_ctx, *contents, 0);
}
if (ret != KNOT_EOK) {
if (ret == KNOT_EOK) {
ret = journal_read_rrsets(read, apply_one_cb, &a_ctx);
} else {
journal_read_end(read);
return ret;
}
if (a_ctx.contents != NULL) {
update_cleanup(&a_ctx);
}
ret = journal_read_rrsets(read, apply_one_cb, &a_ctx);
if (ret == KNOT_EOK) {
log_zone_info(zone->name, "zone loaded from journal, serial %u",
zone_contents_serial(*contents));
} else {
log_zone_error(zone->name, "failed to load zone from journal (%s)",
knot_strerror(ret));
zone_contents_deep_free(*contents);
}
update_cleanup(&a_ctx);
return 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