Commit 0e54f5e6 authored by Lubos Slovak's avatar Lubos Slovak

Fixed cleanup after IXFR/IN.

Changes cannot be freed before all steps of IXFR/IN are
successfully finished. There are now two cleanup functions -
for successful and unsucessful update.
parent f5d43c32
......@@ -315,11 +315,13 @@ static int xfr_xfrin_finalize(xfrworker_t *w, knot_ns_xfr_t *data)
ret == KNOTD_EOK ? "finished" : "failed");
break;
case XFR_TYPE_IIN:
chs = (knot_changesets_t *)data->data;
/* First, try to apply the changesets to the zone. */
/* Update zone. */
ret = xfrin_apply_changesets(data->zone,
(knot_changesets_t *)data->data,
&data->new_contents);
ret = xfrin_apply_changesets(data->zone, chs,
&data->new_contents);
if (ret != KNOT_EOK) {
log_zone_error("IXFR failed to "
"apply changesets to "
......@@ -337,9 +339,12 @@ static int xfr_xfrin_finalize(xfrworker_t *w, knot_ns_xfr_t *data)
zorigin, knotd_strerror(ret));
// Cleanup old and new contents
xfrin_cleanup_failed_update(
data->zone->contents,
&data->new_contents);
xfrin_rollback_update(data->zone->contents,
&data->new_contents,
&chs->changes);
// xfrin_cleanup_failed_update(
// data->zone->contents,
// &data->new_contents);
} else {
/* Switch zone contents. */
ret = xfrin_switch_zone(data->zone,
......@@ -348,15 +353,21 @@ static int xfr_xfrin_finalize(xfrworker_t *w, knot_ns_xfr_t *data)
if (ret != KNOT_EOK) {
// Cleanup old and new contents
xfrin_cleanup_failed_update(
data->zone->contents,
&data->new_contents);
xfrin_rollback_update(
data->zone->contents,
&data->new_contents,
&chs->changes);
// xfrin_cleanup_failed_update(
// data->zone->contents,
// &data->new_contents);
} else {
xfrin_cleanup_successful_update(
&chs->changes);
}
}
}
/* Free changesets, but not the data. */
chs = (knot_changesets_t *)data->data;
knot_free_changesets(&chs);
/* CLEANUP */
// free(chs->sets);
......
......@@ -1191,14 +1191,18 @@ static int zones_journal_apply(knot_zone_t *zone)
ret = KNOTD_ERROR;
// Cleanup old and new contents
xfrin_cleanup_failed_update(zone->contents,
&contents);
xfrin_rollback_update(zone->contents,
&contents,
&chsets->changes);
}
/* Switch zone immediately. */
apply_ret = xfrin_switch_zone(zone, contents,
XFR_TYPE_IIN);
if (apply_ret != KNOT_EOK) {
if (apply_ret == KNOT_EOK) {
xfrin_cleanup_successful_update(
&chsets->changes);
} else {
log_server_error("Failed to apply changesets to"
" '%s' - Switch failed: %s\n",
zd->conf->name,
......@@ -1206,8 +1210,9 @@ static int zones_journal_apply(knot_zone_t *zone)
ret = KNOTD_ERROR;
// Cleanup old and new contents
xfrin_cleanup_failed_update(zone->contents,
&contents);
xfrin_rollback_update(zone->contents,
&contents,
&chsets->changes);
}
}
} else {
......
......@@ -287,6 +287,8 @@ void knot_free_changesets(knot_changesets_t **changesets)
knot_rrset_deep_free(&(*changesets)->first_soa, 1, 1, 1);
assert((*changesets)->changes == NULL);
free(*changesets);
*changesets = NULL;
}
......
......@@ -28,6 +28,7 @@
#define _KNOT_CHANGESETS_H_
#include "rrset.h"
#include "zone/node.h"
/*! \todo Changeset must be serializable/deserializable, so
* all data and pointers have to be changeset-exclusive,
......@@ -56,11 +57,59 @@ typedef struct {
/*----------------------------------------------------------------------------*/
typedef struct {
/*!
* Deleted (without owners and RDATA) after successful update.
*/
knot_rrset_t **old_rrsets;
int old_rrsets_count;
int old_rrsets_allocated;
/*!
* Deleted after successful update.
*/
knot_rdata_t **old_rdata;
unsigned *old_rdata_types;
int old_rdata_count;
int old_rdata_allocated;
/*!
* \brief Copied RRSets (i.e. modified by the update).
*
* Deleted (without owners and RDATA) after failed update.
*/
knot_rrset_t **new_rrsets;
int new_rrsets_count;
int new_rrsets_allocated;
/*!
* Deleted after failed update.
*/
knot_rdata_t **new_rdata;
unsigned *new_rdata_types;
int new_rdata_count;
int new_rdata_allocated;
// /*!
// * Deleted (without contents) after successful update.
// */
knot_node_t **old_nodes;
int old_nodes_count;
int old_nodes_allocated;
knot_node_t **old_nsec3;
int old_nsec3_count;
int old_nsec3_allocated;
} knot_changes_t;
/*----------------------------------------------------------------------------*/
typedef struct {
knot_changeset_t *sets;
size_t count;
size_t allocated;
knot_rrset_t *first_soa;
knot_changes_t *changes;
} knot_changesets_t;
/*----------------------------------------------------------------------------*/
......
This diff is collapsed.
......@@ -189,8 +189,14 @@ int xfrin_switch_zone(knot_zone_t *zone,
knot_zone_contents_t *new_contents,
int deep_free);
void xfrin_cleanup_failed_update(knot_zone_contents_t *old_contents,
knot_zone_contents_t **new_contents);
//void xfrin_cleanup_failed_update(knot_zone_contents_t *old_contents,
// knot_zone_contents_t **new_contents);
void xfrin_cleanup_successful_update(knot_changes_t **changes);
void xfrin_rollback_update(knot_zone_contents_t *old_contents,
knot_zone_contents_t **new_contents,
knot_changes_t **changes);
#endif /* _KNOTXFR_IN_H_ */
......
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