Commit 934339f2 authored by Daniel Salzman's avatar Daniel Salzman

Merge branch 'journal-bootstrap' into 'master'

journal: refactored boostrap changeset handling

See merge request !791
parents 119af7b8 7429aa95
...@@ -768,7 +768,7 @@ static int normal_iterkeycb(iteration_ctx_t *ctx) ...@@ -768,7 +768,7 @@ static int normal_iterkeycb(iteration_ctx_t *ctx)
/*! \brief Deserialize changeset from chunks (in vals) */ /*! \brief Deserialize changeset from chunks (in vals) */
static int vals_to_changeset(knot_db_val_t *vals, int nvals, 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(uint8_t *, valps, nvals)
local_array(size_t, vallens, nvals) local_array(size_t, vallens, nvals)
...@@ -790,8 +790,7 @@ static int vals_to_changeset(knot_db_val_t *vals, int nvals, ...@@ -790,8 +790,7 @@ static int vals_to_changeset(knot_db_val_t *vals, int nvals,
return KNOT_ENOMEM; return KNOT_ENOMEM;
} }
int ret = is_bootstrap ? changeset_deserialize_bootstrap(t_ch, valps, vallens, nvals) int ret = changeset_deserialize(t_ch, valps, vallens, nvals);
: changeset_deserialize(t_ch, valps, vallens, nvals);
local_array_free(valps) local_array_free(valps)
local_array_free(vallens) local_array_free(vallens)
...@@ -810,7 +809,7 @@ static int load_one_itercb(iteration_ctx_t *ctx) ...@@ -810,7 +809,7 @@ static int load_one_itercb(iteration_ctx_t *ctx)
return KNOT_EINVAL; 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; if (ret == KNOT_EOK) *targ = ch;
return ret; return ret;
} }
...@@ -820,7 +819,7 @@ static int load_list_itercb(iteration_ctx_t *ctx) ...@@ -820,7 +819,7 @@ static int load_list_itercb(iteration_ctx_t *ctx)
changeset_t *ch = NULL; changeset_t *ch = NULL;
list_t *chlist = *(list_t **) ctx->iter_context; 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) { if (ret == KNOT_EOK) {
add_tail(chlist, &ch->n); add_tail(chlist, &ch->n);
...@@ -888,23 +887,11 @@ int load_bootstrap_iterkeycb(iteration_ctx_t *ctx) ...@@ -888,23 +887,11 @@ int load_bootstrap_iterkeycb(iteration_ctx_t *ctx)
return KNOT_EOK; 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) static int load_bootstrap_changeset(journal_t *j, txn_t *_txn, changeset_t **ch)
{ {
reuse_txn(txn, j, _txn, false); reuse_txn(txn, j, _txn, false);
changeset_t *rch = NULL; 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); 0, 0, load_bootstrap_iterkeycb);
unreuse_txn(txn, _txn); unreuse_txn(txn, _txn);
if (txn->ret == KNOT_EOK) { if (txn->ret == KNOT_EOK) {
...@@ -1176,7 +1163,7 @@ static int merge_itercb(iteration_ctx_t *ctx) ...@@ -1176,7 +1163,7 @@ static int merge_itercb(iteration_ctx_t *ctx)
{ {
changeset_t *ch = NULL, *mch = *(changeset_t **)ctx->iter_context; 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) { if (ret == KNOT_EOK) {
ret = changeset_merge(mch, ch); ret = changeset_merge(mch, ch);
changeset_free(ch); changeset_free(ch);
......
...@@ -336,50 +336,13 @@ int changeset_deserialize(changeset_t *ch, uint8_t *src_chunks[], ...@@ -336,50 +336,13 @@ int changeset_deserialize(changeset_t *ch, uint8_t *src_chunks[],
} }
} }
return wire.error; // If there was only one SOA record, we are in the bootstrap changeset.
} if (in_remove_section) {
ch->soa_to = ch->soa_from;
int changeset_deserialize_bootstrap(changeset_t *ch, uint8_t *src_chunks[], ch->soa_from = NULL;
const size_t *chunks_sizes, size_t chunks_count) zone_contents_t *tmp = ch->add;
{ ch->add = ch->remove;
if (ch == NULL || src_chunks == NULL || chunks_sizes == NULL || ch->remove = tmp;
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;
}
} }
return wire.error; 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