Commit b35c18d0 authored by Jan Kadlec's avatar Jan Kadlec
Browse files

changesets: First commit with trie changesets, walk done.

parent a341c2ce
...@@ -888,34 +888,37 @@ static void hattrie_iter_nextnode(hattrie_iter_t* i) ...@@ -888,34 +888,37 @@ static void hattrie_iter_nextnode(hattrie_iter_t* i)
hattrie_iter_t* hattrie_iter_begin(const hattrie_t* T, bool sorted) hattrie_iter_t* hattrie_iter_begin(const hattrie_t* T, bool sorted)
{ {
hattrie_iter_t* i = malloc(sizeof(hattrie_iter_t)); hattrie_iter_t* i = NULL;
i->T = T; if (T) {
i->sorted = sorted; i = malloc(sizeof(hattrie_iter_t));
i->i = NULL; i->T = T;
i->keysize = 16; i->sorted = sorted;
i->key = malloc(i->keysize * sizeof(char)); i->i = NULL;
i->level = 0; i->keysize = 16;
i->has_nil_key = false; i->key = malloc(i->keysize * sizeof(char));
i->nil_val = 0; i->level = 0;
i->has_nil_key = false;
i->stack = malloc(sizeof(hattrie_node_stack_t)); i->nil_val = 0;
i->stack->next = NULL;
i->stack->node = T->root;
i->stack->c = '\0';
i->stack->level = 0;
i->stack = malloc(sizeof(hattrie_node_stack_t));
i->stack->next = NULL;
i->stack->node = T->root;
i->stack->c = '\0';
i->stack->level = 0;
while (((i->i == NULL || hhash_iter_finished(i->i)) && !i->has_nil_key) &&
i->stack != NULL ) {
free(i->i); while (((i->i == NULL || hhash_iter_finished(i->i)) && !i->has_nil_key) &&
i->i = NULL; i->stack != NULL ) {
hattrie_iter_nextnode(i);
}
if (i->i != NULL && hhash_iter_finished(i->i)) { free(i->i);
free(i->i); i->i = NULL;
i->i = NULL; hattrie_iter_nextnode(i);
}
if (i->i != NULL && hhash_iter_finished(i->i)) {
free(i->i);
i->i = NULL;
}
} }
return i; return i;
......
...@@ -24,7 +24,7 @@ enum ixfr_states { ...@@ -24,7 +24,7 @@ enum ixfr_states {
/*! \brief Extended structure for IXFR-in/IXFR-out processing. */ /*! \brief Extended structure for IXFR-in/IXFR-out processing. */
struct ixfr_proc { struct ixfr_proc {
struct xfr_proc proc; /* Generic transfer processing context. */ struct xfr_proc proc; /* Generic transfer processing context. */
ptrnode_t *cur; hattrie_iter_t *cur; /* Current changeset iteration state.*/
int state; /* IXFR-in state. */ int state; /* IXFR-in state. */
knot_rrset_t *final_soa; /* First SOA received via IXFR. */ knot_rrset_t *final_soa; /* First SOA received via IXFR. */
list_t changesets; /* Processed changesets. */ list_t changesets; /* Processed changesets. */
...@@ -53,6 +53,8 @@ static int ixfr_put_rrlist(knot_pkt_t *pkt, struct ixfr_proc *ixfr, list_t *list ...@@ -53,6 +53,8 @@ static int ixfr_put_rrlist(knot_pkt_t *pkt, struct ixfr_proc *ixfr, list_t *list
assert(ixfr); assert(ixfr);
assert(list); assert(list);
hattrie_iter_begin()
/* If at the beginning, fetch first RR. */ /* If at the beginning, fetch first RR. */
int ret = KNOT_EOK; int ret = KNOT_EOK;
if (ixfr->cur == NULL) { if (ixfr->cur == NULL) {
......
...@@ -158,8 +158,108 @@ void changesets_free(list_t *chgs, mm_ctx_t *rr_mm) ...@@ -158,8 +158,108 @@ void changesets_free(list_t *chgs, mm_ctx_t *rr_mm)
changeset_t *chg, *nxt; changeset_t *chg, *nxt;
WALK_LIST_DELSAFE(chg, nxt, *chgs) { WALK_LIST_DELSAFE(chg, nxt, *chgs) {
changeset_clear(chg, rr_mm); changeset_clear(chg, rr_mm);
free(chg);
} }
} }
} }
enum {
CHANGESET_NODE_DONE = -1,
};
typedef struct {
hattrie_iter_t *normal_it;
hattrie_iter_t *nsec3_it;
const zone_node_t *node;
int32_t node_pos;
} changeset_iter_t;
static changeset_iter_t *changeset_iter_begin(const changeset_t *ch, hattrie_t *tr,
hattrie_t *nsec3_tr, bool sorted)
{
#warning emptiness check
changeset_iter_t *ret = mm_alloc(ch->mm, sizeof(changeset_iter_t));
if (ret == NULL) {
ERR_ALLOC_FAILED;
return NULL;
}
memset(ret, 0, sizeof(*ret));
ret->node_pos = CHANGESET_NODE_DONE;
ret->normal_it = hattrie_iter_begin(tr, sorted);
ret->nsec3_it = hattrie_iter_begin(nsec3_tr, sorted);
if (ret->normal_it == NULL || ret->nsec3_it == NULL) {
hattrie_iter_free(ret->normal_it);
hattrie_iter_free(ret->nsec3_it);
mm_free(ch->mm, ret);
}
return ret;
}
changeset_iter_t *changeset_iter_add(const changeset_t *ch, bool sorted)
{
return changeset_iter_begin(ch, ch->add->nodes, ch->add->nsec3_nodes, sorted);
}
changeset_iter_t *changeset_iter_rem(const changeset_t *ch, bool sorted)
{
return changeset_iter_begin(ch, ch->remove->nodes, ch->remove->nsec3_nodes, sorted);
}
bool changeset_iter_finished(const changeset_iter_t *it)
{
return it->normal_it == NULL && it->nsec3_it == NULL;
}
void get_next_rr(knot_rrset_t *rr, changeset_iter_t *ch_it, hattrie_iter_t *t_it) // pun intented
{
if (it->node_pos == CHANGESET_NODE_DONE) {
// Get next node.
if (it->node) {
// Do not get next for very first node.
hattrie_iter_next(ch_it->normal_it);
}
if (hattrie_iter_finished(ch_it->normal_it)) {
hattrie_iter_free(&t_it->normal_it);
ch_it->normal_it = NULL;
ch_it->node = NULL;
return;
}
ch_it->node = (zone_node_t *)*hattrie_iter_val(t_it);
ch_it->node_pos = 0;
}
++it->node_pos;
if (ch_it->node_pos < ch_it->node->rrset_count) {
*rr = node_rrset_at(it->node, it->node_pos);
} else {
it->node_pos = CHANGESET_NODE_DONE;
}
}
knot_rrset_t changeset_iter_next(changeset_iter_t *it)
{
knot_rrset_t ret;
knot_rrset_init_empty(&ret);
if (it->normal_it) {
get_next_rr(&ret, it, it->normal_it);
} else if (it->nsec3_it) {
get_next_rr(&ret, it, it->normal_it);
}
return ret;
}
void changeset_iter_free(changeset_iter_t *it, mm_ctx_t *mm)
{
if (it->normal_it) {
hattrie_iter_free(it->normal_it);
}
if (it->nsec3_it) {
hattrie_iter_free(it->nsec3_it);
}
mm_free(mm, it);
}
...@@ -27,21 +27,20 @@ ...@@ -27,21 +27,20 @@
#pragma once #pragma once
#include "libknot/rrset.h" #include "libknot/rrset.h"
#include "knot/zone/node.h" #include "knot/zone/contents.h"
#include "common/lists.h" #include "common/lists.h"
#include "common/mempattern.h" #include "common/mempattern.h"
/*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/
#warning purge lists, data, add commit functionality
/*! \brief One zone change, from 'soa_from' to 'soa_to'. */ /*! \brief One zone change, from 'soa_from' to 'soa_to'. */
typedef struct changeset { typedef struct changeset {
node_t n; /*!< List node. */ node_t n; /*!< List node. */
mm_ctx_t *mm; /*!< Memory context */ mm_ctx_t *mm; /*!< Memory context */
knot_rrset_t *soa_from; /*!< Start SOA. */ knot_rrset_t *soa_from; /*!< Start SOA. */
list_t remove; /*!< List of RRs to remove. */ zone_contents_t *add;
zone_contents_t *remove;
knot_rrset_t *soa_to; /*!< Destination SOA. */ knot_rrset_t *soa_to; /*!< Destination SOA. */
list_t add; /*!< List of RRs to add. */
uint8_t *data; /*!< Serialized changeset. */ uint8_t *data; /*!< Serialized changeset. */
size_t size; /*!< Size of serialized changeset. */ size_t size; /*!< Size of serialized changeset. */
list_t old_data; /*!< Old data, to be freed after succesfull update. */ list_t old_data; /*!< Old data, to be freed after succesfull update. */
...@@ -50,7 +49,6 @@ typedef struct changeset { ...@@ -50,7 +49,6 @@ typedef struct changeset {
/*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/
#warning get rid of this
typedef enum { typedef enum {
CHANGESET_ADD, /*!< Put RR into 'add' section. */ CHANGESET_ADD, /*!< Put RR into 'add' section. */
CHANGESET_REMOVE /*!< Put RR into 'remove' section. */ CHANGESET_REMOVE /*!< Put RR into 'remove' section. */
...@@ -113,7 +111,6 @@ size_t changeset_size(const changeset_t *ch); ...@@ -113,7 +111,6 @@ size_t changeset_size(const changeset_t *ch);
* \retval KNOT_EINVAL if \a changeset or \a func is NULL. * \retval KNOT_EINVAL if \a changeset or \a func is NULL.
* \retval Other error code if the applied function failed. * \retval Other error code if the applied function failed.
*/ */
#warning get rid of this
int changeset_apply(changeset_t *ch, changeset_part_t part, int changeset_apply(changeset_t *ch, changeset_part_t part,
int (*func)(knot_rrset_t *, void *), void *data); int (*func)(knot_rrset_t *, void *), void *data);
......
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