Commit 0e8b3c40 authored by Libor Peltan's avatar Libor Peltan

journal: drop when any axfr-like change to zone

parent be10afd0
...@@ -1940,6 +1940,11 @@ void journal_metadata_info(journal_t *j, bool *has_bootstrap, kserial_t *merged_ ...@@ -1940,6 +1940,11 @@ void journal_metadata_info(journal_t *j, bool *has_bootstrap, kserial_t *merged_
txn_abort(txn); txn_abort(txn);
} }
int journal_drop_changesets(journal_t *journal)
{
return drop_journal(journal, NULL);
}
int journal_db_list_zones(journal_db_t **db, list_t *zones) int journal_db_list_zones(journal_db_t **db, list_t *zones)
{ {
uint64_t expected_count; uint64_t expected_count;
......
...@@ -221,6 +221,15 @@ void journal_metadata_info(journal_t *journal, bool *is_empty, kserial_t *merged ...@@ -221,6 +221,15 @@ void journal_metadata_info(journal_t *journal, bool *is_empty, kserial_t *merged
kserial_t *first_serial, kserial_t *last_flushed, kserial_t *first_serial, kserial_t *last_flushed,
kserial_t *serial_to, uint64_t *occupied, uint64_t *occupied_all_zones); kserial_t *serial_to, uint64_t *occupied, uint64_t *occupied_all_zones);
/*!
* \brief Delete all changesets in zone's journal, keeping metadata.
*
* \param journal Journal to clear.
*
* \return KNOT_E*
*/
int journal_drop_changesets(journal_t *journal);
/*! \brief Check the journal consistency, errors to stderr. /*! \brief Check the journal consistency, errors to stderr.
* *
* \param journal Journal to check. * \param journal Journal to check.
......
...@@ -651,14 +651,13 @@ static int commit_full(conf_t *conf, zone_update_t *update, zone_contents_t **co ...@@ -651,14 +651,13 @@ static int commit_full(conf_t *conf, zone_update_t *update, zone_contents_t **co
conf_val_t val = conf_zone_get(conf, C_JOURNAL_CONTENT, update->zone->name); conf_val_t val = conf_zone_get(conf, C_JOURNAL_CONTENT, update->zone->name);
if (conf_opt(&val) == JOURNAL_CONTENT_ALL) { if (conf_opt(&val) == JOURNAL_CONTENT_ALL) {
ret = zone_in_journal_store(conf, update->zone, update->new_cont); ret = zone_in_journal_store(conf, update->zone, update->new_cont);
if (ret != KNOT_EOK) { } else { // zone_in_journal_store does this automatically
return ret; ret = zone_changes_clear(conf, update->zone);
}
} }
*contents_out = update->new_cont; *contents_out = update->new_cont;
return KNOT_EOK; return ret;
} }
/*! \brief Routine for calling call_rcu() easier way. /*! \brief Routine for calling call_rcu() easier way.
......
...@@ -295,6 +295,24 @@ int zone_change_store(conf_t *conf, zone_t *zone, changeset_t *change) ...@@ -295,6 +295,24 @@ int zone_change_store(conf_t *conf, zone_t *zone, changeset_t *change)
return ret; return ret;
} }
int zone_changes_clear(conf_t *conf, zone_t *zone)
{
if (conf == NULL || zone == NULL) {
return KNOT_EINVAL;
}
JOURNAL_LOCK_RW
int ret = open_journal(zone);
if (ret == KNOT_EOK) {
ret = journal_drop_changesets(zone->journal);
}
JOURNAL_UNLOCK_RW
return ret;
}
int zone_changes_load(conf_t *conf, zone_t *zone, list_t *dst, uint32_t from) int zone_changes_load(conf_t *conf, zone_t *zone, list_t *dst, uint32_t from)
{ {
if (conf == NULL || zone == NULL || dst == NULL) { if (conf == NULL || zone == NULL || dst == NULL) {
......
...@@ -115,6 +115,7 @@ void zone_free(zone_t **zone_ptr); ...@@ -115,6 +115,7 @@ void zone_free(zone_t **zone_ptr);
void zone_control_clear(zone_t *zone); void zone_control_clear(zone_t *zone);
int zone_change_store(conf_t *conf, zone_t *zone, changeset_t *change); int zone_change_store(conf_t *conf, zone_t *zone, changeset_t *change);
int zone_changes_clear(conf_t *conf, zone_t *zone);
int zone_changes_load(conf_t *conf, zone_t *zone, list_t *dst, uint32_t from); int zone_changes_load(conf_t *conf, zone_t *zone, list_t *dst, uint32_t from);
int zone_chgset_ctx_load(conf_t *conf, zone_t *zone, chgset_ctx_list_t *dst, uint32_t from); int zone_chgset_ctx_load(conf_t *conf, zone_t *zone, chgset_ctx_list_t *dst, uint32_t from);
int zone_in_journal_load(conf_t *conf, zone_t *zone, list_t *dst); int zone_in_journal_load(conf_t *conf, zone_t *zone, list_t *dst);
......
...@@ -415,8 +415,8 @@ static void test_store_load(void) ...@@ -415,8 +415,8 @@ static void test_store_load(void)
init_list(&l); init_list(&l);
ret = journal_flush(j); ret = journal_flush(j);
is_int(KNOT_EOK, ret, "journal: allways ok journal_flush 0"); is_int(KNOT_EOK, ret, "journal: allways ok journal_flush 0");
ret = drop_journal(j, NULL); /* Clear the journal for the collision test */ ret = journal_drop_changesets(j); /* Clear the journal for the collision test */
is_int(KNOT_EOK, ret, "journal: allways ok drop_journal"); is_int(KNOT_EOK, ret, "journal: allways ok journal_drop_changesets");
/* Test for serial number collision handling. We insert changesets /* Test for serial number collision handling. We insert changesets
* with valid serial sequence that overflows and then collides with itself. * with valid serial sequence that overflows and then collides with itself.
...@@ -468,8 +468,8 @@ static void test_store_load(void) ...@@ -468,8 +468,8 @@ static void test_store_load(void)
init_list(&k); init_list(&k);
/* Check bootstrap changeset */ /* Check bootstrap changeset */
ret = drop_journal(j, NULL); ret = journal_drop_changesets(j);
ok(ret == KNOT_EOK, "journal: drop_journal must be ok"); ok(ret == KNOT_EOK, "journal: journal_drop_changesets must be ok");
changeset_t *m_ch6 = changeset_new(apex); changeset_t *m_ch6 = changeset_new(apex);
init_random_changeset(m_ch6, 0, 1, 128, apex, true); init_random_changeset(m_ch6, 0, 1, 128, apex, true);
...@@ -622,8 +622,8 @@ static void test_merge(void) ...@@ -622,8 +622,8 @@ static void test_merge(void)
set_conf(-1, 512 * 1024); set_conf(-1, 512 * 1024);
ok(journal_merge_allowed(j), "journal: merge allowed"); ok(journal_merge_allowed(j), "journal: merge allowed");
ret = drop_journal(j, NULL); ret = journal_drop_changesets(j);
is_int(KNOT_EOK, ret, "journal: drop_journal must be ok"); is_int(KNOT_EOK, ret, "journal: journal_drop_changesets must be ok");
// insert stuff and check the merge // insert stuff and check the merge
for (i = 0; !merged_present() && i < 40000; i++) { for (i = 0; !merged_present() && i < 40000; i++) {
...@@ -652,7 +652,7 @@ static void test_merge(void) ...@@ -652,7 +652,7 @@ static void test_merge(void)
ok(list_size(&l) == 4, "journal: read short history of merged/unmerged changesets"); ok(list_size(&l) == 4, "journal: read short history of merged/unmerged changesets");
changesets_free(&l); changesets_free(&l);
ret = drop_journal(j, NULL); ret = journal_drop_changesets(j);
assert(ret == KNOT_EOK); assert(ret == KNOT_EOK);
// disallow merge // disallow merge
......
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