Commit a43c0684 authored by Jan Včelák's avatar Jan Včelák 🚀
Browse files

server: adapt to new timer API, drop replaning

parent 1c2e6058
......@@ -407,7 +407,7 @@ void server_deinit(server_t *server)
evsched_deinit(&server->sched);
/* Close persistent timers database. */
close_timers_db(server->timers_db);
zone_timers_close(server->timers_db);
/* Clear the structure. */
memset(server, 0, sizeof(server_t));
......@@ -680,7 +680,7 @@ void server_reconfigure(conf_t *conf, server_t *server)
static void reopen_timers_database(conf_t *conf, server_t *server)
{
close_timers_db(server->timers_db);
zone_timers_close(server->timers_db);
server->timers_db = NULL;
conf_val_t val = conf_default_get(conf, C_STORAGE);
......@@ -689,7 +689,7 @@ static void reopen_timers_database(conf_t *conf, server_t *server)
char *timer_db = conf_abs_path(&val, storage);
free(storage);
int ret = open_timers_db(timer_db, &server->timers_db);
int ret = zone_timers_open(timer_db, &server->timers_db);
if (ret != KNOT_EOK) {
log_warning("cannot open persistent timers DB '%s' (%s)",
timer_db, knot_strerror(ret));
......
......@@ -32,6 +32,7 @@
#include "knot/server/journal.h"
#include "knot/events/events.h"
#include "knot/zone/contents.h"
#include "knot/zone/timers.h"
#include "libknot/dname.h"
#include "libknot/packet/pkt.h"
......@@ -67,8 +68,10 @@ typedef struct zone
} zonefile;
/*! \brief Zone events. */
uint32_t bootstrap_retry; /*!< AXFR/IN bootstrap retry. */
zone_events_t events; /*!< Zone events timers. */
// TODO: remove bootstrap_retry
uint32_t bootstrap_retry; //!< AXFR/IN bootstrap retry.
zone_timers_t timers; //!< Persistent zone timers.
zone_events_t events; //!< Zone events timers.
/*! \brief DDNS queue and lock. */
pthread_mutex_t ddns_lock;
......
......@@ -165,42 +165,6 @@ static zone_t *create_zone_reload(conf_t *conf, const knot_dname_t *name,
return zone;
}
static bool slave_event(zone_event_type_t event)
{
return event == ZONE_EVENT_EXPIRE || event == ZONE_EVENT_REFRESH;
}
static int reuse_events(conf_t *conf, knot_db_t *timer_db, zone_t *zone)
{
// Get persistent timers
time_t timers[ZONE_EVENT_COUNT] = { 0 };
int ret = read_zone_timers(timer_db, zone, timers);
if (ret != KNOT_EOK) {
return ret;
}
for (zone_event_type_t event = 0; event < ZONE_EVENT_COUNT; ++event) {
if (timers[event] == 0) {
// Timer unset.
continue;
}
if (slave_event(event) && !zone_is_slave(conf, zone)) {
// Slave-only event.
continue;
}
if (event == ZONE_EVENT_EXPIRE && timers[event] <= time(NULL)) {
zone->flags |= ZONE_EXPIRED;
continue;
}
zone_events_schedule_at(zone, event, timers[event]);
}
return KNOT_EOK;
}
static zone_t *create_zone_new(conf_t *conf, const knot_dname_t *name,
server_t *server)
{
......@@ -209,14 +173,16 @@ static zone_t *create_zone_new(conf_t *conf, const knot_dname_t *name,
return NULL;
}
int ret = reuse_events(conf, server->timers_db, zone);
if (ret != KNOT_EOK) {
log_zone_error(zone->name, "cannot read zone timers (%s)",
int ret = zone_timers_read(server->timers_db, name, &zone->timers);
if (ret != KNOT_EOK && ret != KNOT_ENOENT) {
log_zone_error(zone->name, "failed to load persistent timers (%s)",
knot_strerror(ret));
zone_free(&zone);
return NULL;
}
// TODO: process the timers
zone_status_t zstatus = zone_file_status(conf, NULL, name);
if (zone->flags & ZONE_EXPIRED) {
assert(zone_is_slave(conf, zone));
......@@ -341,6 +307,16 @@ static void remove_old_zonedb(const knot_zonedb_t *db_new, knot_zonedb_t *db_old
knot_zonedb_deep_free(&db_old);
}
static bool zone_exists(const knot_dname_t *zone, void *data)
{
assert(zone);
assert(data);
knot_zonedb_t *db = data;
return knot_zonedb_find(db, zone) != NULL;
}
void zonedb_reload(conf_t *conf, server_t *server)
{
/* Check parameters */
......@@ -366,7 +342,11 @@ void zonedb_reload(conf_t *conf, server_t *server)
synchronize_rcu();
/* Sweep the timer database. */
sweep_timer_db(server->timers_db, db_new);
int ret = zone_timers_sweep(server->timers_db, zone_exists, db_new);
if (ret != KNOT_EOK) {
log_warning("failed to clear persistent timers for removed zones (%s)",
knot_strerror(ret));
}
/*
* Remove all zones present in the new DB from the old DB.
......
......@@ -363,6 +363,11 @@ static int set_config(const char *confdb, const char *config)
return KNOT_EOK;
}
static void write_timers(const zone_t *zone, zone_timers_t *db)
{
zone_timers_write(db, zone->name, &zone->timers);
}
int main(int argc, char **argv)
{
bool daemonize = false;
......@@ -554,8 +559,9 @@ int main(int argc, char **argv)
server_stop(&server);
server_wait(&server);
// TODO: will be very slow, each write is in separate transation
log_info("updating zone timers database");
write_timer_db(server.timers_db, server.zone_db);
knot_zonedb_foreach(server.zone_db, write_timers, server.timers_db);
/* Cleanup PID file. */
pid_cleanup();
......
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