Commit 7429aa95 authored by Mark Karpilovskij's avatar Mark Karpilovskij Committed by Daniel Salzman

journal: refactored boostrap changeset handling

parent 9041e138
......@@ -768,7 +768,7 @@ static int normal_iterkeycb(iteration_ctx_t *ctx)
/*! \brief Deserialize changeset from chunks (in vals) */
static int vals_to_changeset(knot_db_val_t *vals, int nvals,
const knot_dname_t *zone_name, changeset_t **ch, bool is_bootstrap)
const knot_dname_t *zone_name, changeset_t **ch)
{
local_array(uint8_t *, valps, nvals)
local_array(size_t, vallens, nvals)
......@@ -790,8 +790,7 @@ static int vals_to_changeset(knot_db_val_t *vals, int nvals,
return KNOT_ENOMEM;
}
int ret = is_bootstrap ? changeset_deserialize_bootstrap(t_ch, valps, vallens, nvals)
: changeset_deserialize(t_ch, valps, vallens, nvals);
int ret = changeset_deserialize(t_ch, valps, vallens, nvals);
local_array_free(valps)
local_array_free(vallens)
......@@ -810,7 +809,7 @@ static int load_one_itercb(iteration_ctx_t *ctx)
return KNOT_EINVAL;
}
int ret = vals_to_changeset(ctx->val, ctx->chunk_count, ctx->txn->j->zone, &ch, false);
int ret = vals_to_changeset(ctx->val, ctx->chunk_count, ctx->txn->j->zone, &ch);
if (ret == KNOT_EOK) *targ = ch;
return ret;
}
......@@ -820,7 +819,7 @@ static int load_list_itercb(iteration_ctx_t *ctx)
changeset_t *ch = NULL;
list_t *chlist = *(list_t **) ctx->iter_context;
int ret = vals_to_changeset(ctx->val, ctx->chunk_count, ctx->txn->j->zone, &ch, false);
int ret = vals_to_changeset(ctx->val, ctx->chunk_count, ctx->txn->j->zone, &ch);
if (ret == KNOT_EOK) {
add_tail(chlist, &ch->n);
......@@ -888,23 +887,11 @@ int load_bootstrap_iterkeycb(iteration_ctx_t *ctx)
return KNOT_EOK;
}
static int load_bootstrap_itercb(iteration_ctx_t *ctx)
{
changeset_t *ch = NULL, **targ = ctx->iter_context;
if (*targ != NULL) {
return KNOT_EINVAL;
}
int ret = vals_to_changeset(ctx->val, ctx->chunk_count, ctx->txn->j->zone, &ch, true);
if (ret == KNOT_EOK) *targ = ch;
return ret;
}
static int load_bootstrap_changeset(journal_t *j, txn_t *_txn, changeset_t **ch)
{
reuse_txn(txn, j, _txn, false);
changeset_t *rch = NULL;
iterate(j, txn, load_bootstrap_itercb, JOURNAL_ITERATION_CHANGESETS, &rch,
iterate(j, txn, load_one_itercb, JOURNAL_ITERATION_CHANGESETS, &rch,
0, 0, load_bootstrap_iterkeycb);
unreuse_txn(txn, _txn);
if (txn->ret == KNOT_EOK) {
......@@ -1176,7 +1163,7 @@ static int merge_itercb(iteration_ctx_t *ctx)
{
changeset_t *ch = NULL, *mch = *(changeset_t **)ctx->iter_context;
int ret = vals_to_changeset(ctx->val, ctx->chunk_count, ctx->txn->j->zone, &ch, false);
int ret = vals_to_changeset(ctx->val, ctx->chunk_count, ctx->txn->j->zone, &ch);
if (ret == KNOT_EOK) {
ret = changeset_merge(mch, ch);
changeset_free(ch);
......
......@@ -336,50 +336,13 @@ int changeset_deserialize(changeset_t *ch, uint8_t *src_chunks[],
}
}
return wire.error;
}
int changeset_deserialize_bootstrap(changeset_t *ch, uint8_t *src_chunks[],
const size_t *chunks_sizes, size_t chunks_count)
{
if (ch == NULL || src_chunks == NULL || chunks_sizes == NULL ||
chunks_count == 0) {
return KNOT_EINVAL;
}
size_t cur_chunk = 0;
wire_ctx_t wire = wire_ctx_init_const(src_chunks[0], chunks_sizes[0]);
// Deserialize SOA 'to'.
knot_rrset_t rrset;
int ret = deserialize_rrset_chunks(&wire, &rrset, src_chunks, chunks_sizes,
chunks_count, &cur_chunk);
if (ret != KNOT_EOK) {
return ret;
}
assert(rrset.type == KNOT_RRTYPE_SOA);
ch->soa_from = NULL;
ch->soa_to = knot_rrset_copy(&rrset, NULL);
knot_rrset_clear(&rrset, NULL);
if (ch->soa_to == NULL) {
return KNOT_ENOMEM;
}
// Read remaining RRSets.
while (cur_chunk < chunks_count - 1 || wire_ctx_available(&wire) > 0) {
// Parse next RRSet.
ret = deserialize_rrset_chunks(&wire, &rrset, src_chunks, chunks_sizes,
chunks_count, &cur_chunk);
if (ret != KNOT_EOK) {
break;
}
assert(rrset.type != KNOT_RRTYPE_SOA);
ret = changeset_add_addition(ch, &rrset, 0);
knot_rrset_clear(&rrset, NULL);
if (ret != KNOT_EOK) {
return ret;
}
// If there was only one SOA record, we are in the bootstrap changeset.
if (in_remove_section) {
ch->soa_to = ch->soa_from;
ch->soa_from = NULL;
zone_contents_t *tmp = ch->add;
ch->add = ch->remove;
ch->remove = tmp;
}
return wire.error;
......
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