Commit cb78554c authored by Libor Peltan's avatar Libor Peltan Committed by Daniel Salzman

zone load: using new journal implementation

parent 7eb52b63
......@@ -29,6 +29,7 @@
#include "knot/conf/migration.h"
#include "knot/conf/module.h"
#include "knot/dnssec/kasp/kasp_db.h"
#include "knot/journal/journal_basic.h"
#include "knot/server/server.h"
#include "knot/server/udp-handler.h"
#include "knot/server/tcp-handler.h"
......@@ -422,6 +423,7 @@ int server_init(server_t *server, int bg_workers)
conf_val_t journal_mode = conf_default_get(conf(), C_JOURNAL_DB_MODE);
int ret = journal_db_init(&server->journal_db, journal_dir,
conf_int(&journal_size), conf_opt(&journal_mode));
knot_lmdb_init(&server->journaldb, journal_dir, conf_int(&journal_size), journal_env_flags(conf_opt(&journal_mode)));
free(journal_dir);
if (ret != KNOT_EOK) {
worker_pool_destroy(server->workers);
......@@ -472,6 +474,7 @@ void server_deinit(server_t *server)
/* Close journal database if open. */
journal_db_close(&server->journal_db);
knot_lmdb_deinit(&server->journaldb);
/* Close persistent timers database. */
zone_timers_close(server->timers_db);
......
/* Copyright (C) 2018 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
/* Copyright (C) 2019 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
......@@ -21,8 +21,9 @@
#include "knot/conf/conf.h"
#include "knot/common/evsched.h"
#include "knot/common/fdset.h"
#include "knot/server/dthreads.h"
#include "knot/common/ref.h"
#include "knot/journal/knot_lmdb.h"
#include "knot/server/dthreads.h"
#include "knot/worker/pool.h"
#include "knot/zone/zonedb.h"
#include "contrib/ucw/lists.h"
......@@ -85,6 +86,7 @@ typedef struct server {
knot_zonedb_t *zone_db;
knot_db_t *timers_db;
journal_db_t *journal_db;
knot_lmdb_db_t journaldb;
/*! \brief I/O handlers. */
struct {
......
......@@ -583,8 +583,6 @@ int changeset_to_contents(changeset_t *ch, zone_contents_t **out)
}
zone_contents_deep_free(ch->remove);
free(ch->data);
free(ch);
return ret;
}
......
/* Copyright (C) 2017 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
/* Copyright (C) 2019 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
......@@ -16,6 +16,8 @@
#include "knot/common/log.h"
#include "knot/journal/journal.h"
#include "knot/journal/journal_metadata.h"
#include "knot/journal/journal_read.h"
#include "knot/zone/zone-diff.h"
#include "knot/zone/zone-load.h"
#include "knot/zone/zonefile.h"
......@@ -57,41 +59,42 @@ int zone_load_contents(conf_t *conf, const knot_dname_t *zone_name,
return KNOT_EOK;
}
static int apply_one_cb(bool remove, const knot_rrset_t *rr, void *ctx)
{
return remove ? apply_remove_rr(ctx, rr) : apply_add_rr(ctx, rr);
}
int zone_load_journal(conf_t *conf, zone_t *zone, zone_contents_t *contents)
{
if (conf == NULL || zone == NULL || contents == NULL) {
return KNOT_EINVAL;
}
/* Check if journal is used (later in zone_changes_load() and zone is not empty. */
// Check if journal is used (later in zone_changes_load() and zone is not empty.
if (zone_contents_is_empty(contents)) {
return KNOT_EOK;
}
/* Fetch SOA serial. */
uint32_t serial = zone_contents_serial(contents);
/* Load journal */
list_t chgs;
init_list(&chgs);
int ret = zone_changes_load(conf, zone, &chgs, serial);
if (ret != KNOT_EOK && ret != KNOT_ENOENT) {
changesets_free(&chgs);
return ret;
}
if (EMPTY_LIST(chgs)) {
journal_read_t *read = NULL;
int ret = journal_read_begin(zone_journal(zone), false, serial, &read);
switch (ret) {
case KNOT_EOK:
break;
case KNOT_ENOENT:
return KNOT_EOK;
default:
return ret;
}
/* Apply changesets. */
apply_ctx_t a_ctx = { 0 };
ret = apply_init_ctx(&a_ctx, contents, 0);
if (ret != KNOT_EOK) {
changesets_free(&chgs);
journal_read_end(read);
return ret;
}
ret = apply_changesets_directly(&a_ctx, &chgs);
ret = journal_read_rrsets(read, apply_one_cb, &a_ctx);
if (ret == KNOT_EOK) {
log_zone_info(zone->name, "changes from journal applied %u -> %u",
serial, zone_contents_serial(contents));
......@@ -102,7 +105,6 @@ int zone_load_journal(conf_t *conf, zone_t *zone, zone_contents_t *contents)
}
update_cleanup(&a_ctx);
changesets_free(&chgs);
return ret;
}
......@@ -113,30 +115,27 @@ int zone_load_from_journal(conf_t *conf, zone_t *zone, zone_contents_t **content
return KNOT_EINVAL;
}
list_t chgs;
init_list(&chgs);
int ret = zone_in_journal_load(conf, zone, &chgs);
journal_read_t *read = NULL;
int ret = journal_read_begin(zone_journal(zone), true, 0, &read);
if (ret != KNOT_EOK) {
changesets_free(&chgs);
return ret; // include ENOENT, which is normal operation
}
changeset_t *boo_ch = (changeset_t *)HEAD(chgs);
rem_node(&boo_ch->n);
ret = changeset_to_contents(boo_ch, contents);
if (ret != KNOT_EOK) {
changesets_free(&chgs);
return ret;
}
changeset_t zone_in_j;
apply_ctx_t a_ctx = { 0 };
ret = apply_init_ctx(&a_ctx, *contents, 0);
ret = journal_read_changeset(read, &zone_in_j) ? KNOT_EOK : KNOT_ENOENT;
if (ret == KNOT_EOK) {
ret = changeset_to_contents(&zone_in_j, contents);
}
if (ret == KNOT_EOK) {
ret = apply_init_ctx(&a_ctx, *contents, 0);
}
if (ret != KNOT_EOK) {
changesets_free(&chgs);
journal_read_end(read);
return ret;
}
ret = apply_changesets_directly(&a_ctx, &chgs);
ret = journal_read_rrsets(read, apply_one_cb, &a_ctx);
if (ret == KNOT_EOK) {
log_zone_info(zone->name, "zone loaded from journal, serial %u",
zone_contents_serial(*contents));
......@@ -145,7 +144,6 @@ int zone_load_from_journal(conf_t *conf, zone_t *zone, zone_contents_t **content
knot_strerror(ret));
}
update_cleanup(&a_ctx);
changesets_free(&chgs);
return ret;
}
......
/* Copyright (C) 2018 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
/* Copyright (C) 2019 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
......@@ -19,6 +19,7 @@
#include "knot/conf/conf.h"
#include "knot/conf/confio.h"
#include "knot/journal/journal.h"
#include "knot/journal/journal_basic.h"
#include "knot/events/events.h"
#include "knot/zone/contents.h"
#include "knot/zone/timers.h"
......@@ -78,6 +79,7 @@ typedef struct zone
/*! \brief Ptr to journal DB (in struct server) */
journal_db_t **journal_db;
knot_lmdb_db_t *journaldb;
/*! \brief Preferred master lock. */
pthread_mutex_t preferred_lock;
......@@ -114,6 +116,12 @@ void zone_free(zone_t **zone_ptr);
*/
void zone_control_clear(zone_t *zone);
inline static zone_journal_t zone_journal(zone_t *zone)
{
zone_journal_t j = { zone->journaldb, zone->name };
return j;
}
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);
......
/* Copyright (C) 2018 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
/* Copyright (C) 2019 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
......@@ -51,6 +51,7 @@ static zone_t *create_zone_from(const knot_dname_t *name, server_t *server)
}
zone->journal_db = &server->journal_db;
zone->journaldb = &server->journaldb;
int result = zone_events_setup(zone, server->workers, &server->sched,
server->timers_db);
......
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