chunk_dynarray_t dchunks = { 0 };
chunks = 0;
- serialize_ctx_t *sctx;
- serialize_init(&sctx, ch);
- size_t chunk_size;
+ serialize_ctx_t *sctx = serialize_init(ch);
+ if (sctx == NULL) {
+ txn->ret = KNOT_ENOMEM;
+ break;
+ }
bool is_this_merged = (inserting_merged && ch == TAIL(*changesets));
bool is_this_bootstrap = (ch->soa_from == NULL);
uint32_t serial_to = knot_soa_serial(&ch->soa_to->rrs);
while (serialize_unfinished(sctx)) {
+ size_t chunk_size;
serialize_prepare(sctx, CHUNK_MAX - JOURNAL_HEADER_SIZE, &chunk_size);
if (chunk_size == 0) {
break;
serialize_chunk(sctx, txn->val.data + JOURNAL_HEADER_SIZE, chunk_size);
}
- serialize_deinit(&sctx);
+ serialize_deinit(sctx);
dynarray_foreach(chunk, knot_db_val_t, val, dchunks) {
make_header(val, serial_to, chunks);
size_t rrset_buf_size;
};
-void serialize_init(serialize_ctx_t **ctx, const changeset_t *ch)
+serialize_ctx_t *serialize_init(const changeset_t *ch)
{
- *ctx = calloc(1, sizeof(**ctx));
- (*ctx)->ch = ch;
- (*ctx)->changeset_phase = ch->soa_from != NULL ? PHASE_SOA_1 : PHASE_SOA_2;
- (*ctx)->rrset_phase = SERIALIZE_RRSET_INIT;
- (*ctx)->rrset_buf_size = 0;
+ serialize_ctx_t *ctx = calloc(1, sizeof(*ctx));
+ if (ctx == NULL) {
+ return NULL;
+ }
+
+ ctx->ch = ch;
+ ctx->changeset_phase = ch->soa_from != NULL ? PHASE_SOA_1 : PHASE_SOA_2;
+ ctx->rrset_phase = SERIALIZE_RRSET_INIT;
+ ctx->rrset_buf_size = 0;
+
+ return ctx;
}
static const knot_rrset_t get_next_rrset(serialize_ctx_t *ctx)
tmp_phase = SERIALIZE_RRSET_INIT;
}
if (tmp_phase == SERIALIZE_RRSET_INIT) {
- candidate += 3 * sizeof(uint16_t) + knot_dname_size(ctx->rrset_buf[ctx->rrset_buf_size - 1].owner);
+ candidate += 3 * sizeof(uint16_t) +
+ knot_dname_size(ctx->rrset_buf[ctx->rrset_buf_size - 1].owner);
} else {
- candidate += sizeof(uint32_t) + sizeof(uint16_t) + knot_rdataset_at(&ctx->rrset_buf[ctx->rrset_buf_size - 1].rrs, tmp_phase)->len;
+ candidate += sizeof(uint32_t) + sizeof(uint16_t) +
+ knot_rdataset_at(&ctx->rrset_buf[ctx->rrset_buf_size - 1].rrs, tmp_phase)->len;
}
if (candidate > max_size) {
return;
ctx->rrset_phase = SERIALIZE_RRSET_INIT;
}
if (ctx->rrset_phase == SERIALIZE_RRSET_INIT) {
- int size = knot_dname_to_wire(wire.position, ctx->rrset_buf[i].owner, wire_ctx_available(&wire));
+ int size = knot_dname_to_wire(wire.position, ctx->rrset_buf[i].owner,
+ wire_ctx_available(&wire));
if (size < 0 || wire_ctx_available(&wire) < size + 3 * sizeof(uint16_t)) {
break;
}
wire_ctx_write_u16(&wire, ctx->rrset_buf[i].rclass);
wire_ctx_write_u16(&wire, ctx->rrset_buf[i].rrs.rr_count);
} else {
- const knot_rdata_t *rr = knot_rdataset_at(&ctx->rrset_buf[i].rrs, ctx->rrset_phase);
+ const knot_rdata_t *rr = knot_rdataset_at(&ctx->rrset_buf[i].rrs,
+ ctx->rrset_phase);
assert(rr);
uint16_t rdlen = rr->len;
if (wire_ctx_available(&wire) < sizeof(uint32_t) + sizeof(uint16_t) + rdlen) {
return ctx->changeset_phase < PHASE_END;
}
-void serialize_deinit(serialize_ctx_t **ctx)
+void serialize_deinit(serialize_ctx_t *ctx)
{
- if ((*ctx)->it.node != NULL) {
- changeset_iter_clear(&(*ctx)->it);
+ if (ctx->it.node != NULL) {
+ changeset_iter_clear(&ctx->it);
}
- free(*ctx);
+ free(ctx);
}
static int deserialize_rrset(wire_ctx_t *wire, knot_rrset_t *rrset, long *phase)
/*!
* \brief Init serialization context.
*
- * \param ctx Context.
* \param ch Changeset to be serialized.
+ *
+ * \return Context.
*/
-void serialize_init(serialize_ctx_t **ctx, const changeset_t *ch);
+serialize_ctx_t *serialize_init(const changeset_t *ch);
/*!
* \brief Pre-check and space computation before serializing a chunk.
bool serialize_unfinished(serialize_ctx_t *ctx);
/*! \brief Free serialization context. */
-void serialize_deinit(serialize_ctx_t **ctx);
+void serialize_deinit(serialize_ctx_t *ctx);
/*!
* \brief Returns size of changeset in serialized form.