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

Merge branch 'timers_speedup' into 'master'

Update zone timers just when server shutdown

Closes #405
parents 85c2ce65 15206f56
......@@ -467,9 +467,12 @@ int main(int argc, char **argv)
/* Teardown server. */
server_stop(&server);
server_wait(&server);
server_deinit(&server);
/* Free configuration. */
log_info("updating zone timers database");
write_timer_db(server.timers_db, server.zone_db);
/* Free server and configuration. */
server_deinit(&server);
conf_free(conf(), false);
/* Unhook from RCU. */
......
......@@ -100,10 +100,6 @@ int notify_process_query(knot_pkt_t *pkt, struct query_data *qdata)
zone_t *zone = (zone_t *)qdata->zone;
zone_set_preferred_master(zone, qdata->param->remote);
zone_events_schedule(zone, ZONE_EVENT_REFRESH, ZONE_EVENT_NOW);
int ret = zone_events_write_persistent(zone);
if (ret != KNOT_EOK) {
return KNOT_STATE_FAIL;
}
return KNOT_STATE_DONE;
}
......
......@@ -423,16 +423,3 @@ void zone_events_replan_ddns(struct zone *zone, const struct zone *old_zone)
replan_update(zone, (zone_t *)old_zone);
}
}
int zone_events_write_persistent(zone_t *zone)
{
if (!zone) {
return KNOT_EINVAL;
}
if (zone->events.timers_db == NULL) {
return KNOT_EOK;
}
return write_zone_timers(zone->events.timers_db, zone);
}
......@@ -202,10 +202,3 @@ void zone_events_update(struct zone *zone, struct zone *old_zone);
* \param old_zone Zone with old config.
*/
void zone_events_replan_ddns(struct zone *zone, const struct zone *old_zone);
/*!
* \brief Write persistent timers to timers database.
*
* \return KNOT_E*
*/
int zone_events_write_persistent(struct zone *zone);
......@@ -358,7 +358,7 @@ int event_reload(zone_t *zone)
log_zone_info(zone->name, "loaded, serial %u -> %u",
old_serial, current_serial);
return zone_events_write_persistent(zone);
return KNOT_EOK;
fail:
zone_contents_deep_free(&contents);
......@@ -407,7 +407,7 @@ int event_refresh(zone_t *zone)
zone_events_schedule(zone, ZONE_EVENT_REFRESH, knot_soa_refresh(soa));
}
return zone_events_write_persistent(zone);
return KNOT_EOK;
}
struct transfer_data {
......
......@@ -64,7 +64,7 @@ static void clear_timers(time_t *timers)
}
/*! \brief Stores timers for persistent events. */
static int store_timers(namedb_txn_t *txn, zone_t *zone)
static int store_timers(zone_t *zone, namedb_txn_t *txn)
{
// Create key
namedb_val_t key = { .len = knot_dname_size(zone->name), .data = zone->name };
......@@ -174,6 +174,10 @@ int read_zone_timers(namedb_t *timer_db, const zone_t *zone, time_t *timers)
return KNOT_EOK;
}
if (zone == NULL || timers == NULL) {
return KNOT_EINVAL;
}
const namedb_api_t *db_api = namedb_lmdb_api();
assert(db_api);
......@@ -192,26 +196,26 @@ int read_zone_timers(namedb_t *timer_db, const zone_t *zone, time_t *timers)
return KNOT_EOK;
}
int write_zone_timers(namedb_t *timer_db, zone_t *zone)
int write_timer_db(namedb_t *timer_db, knot_zonedb_t *zone_db)
{
if (timer_db == NULL) {
return KNOT_EOK;
}
if (zone_db == NULL) {
return KNOT_EINVAL;
}
const namedb_api_t *db_api = namedb_lmdb_api();
assert(db_api);
namedb_txn_t txn;
int ret = db_api->txn_begin(timer_db, &txn, 0);
int ret = db_api->txn_begin(timer_db, &txn, NAMEDB_SORTED);
if (ret != KNOT_EOK) {
return ret;
}
ret = store_timers(&txn, zone);
if (ret != KNOT_EOK) {
db_api->txn_abort(&txn);
return ret;
}
knot_zonedb_foreach(zone_db, store_timers, &txn);
return db_api->txn_commit(&txn);
}
......@@ -222,6 +226,10 @@ int sweep_timer_db(namedb_t *timer_db, knot_zonedb_t *zone_db)
return KNOT_EOK;
}
if (zone_db == NULL) {
return KNOT_EINVAL;
}
const namedb_api_t *db_api = namedb_lmdb_api();
assert(db_api);
......
......@@ -53,14 +53,14 @@ void close_timers_db(namedb_t *timer_db);
int read_zone_timers(namedb_t *timer_db, const zone_t *zone, time_t *timers);
/*!
* \brief Writes zone timers to timers db.
* \brief Writes all zone timers to timers db.
*
* \param timer_db Timer database.
* \param zone Zone to store timers for.
* \param zone_db Zone database.
*
* \return KNOT_E*
*/
int write_zone_timers(namedb_t *timer_db, zone_t *zone);
int write_timer_db(namedb_t *timer_db, knot_zonedb_t *zone_db);
/*!
* \brief Removes stale zones info from timers db.
......
......@@ -154,8 +154,6 @@ static zone_t *create_zone_reload(conf_t *conf, const knot_dname_t *name,
zone->zonefile_serial = old_zone->zonefile_serial;
/* Reuse events from old zone. */
zone_events_update(zone, old_zone);
/* Write updated timers. */
zone_events_write_persistent(zone);
break;
default:
assert(0);
......
......@@ -63,6 +63,8 @@ int main(int argc, char *argv[])
ret = knot_zonedb_insert(zone_db, zone_2);
assert(ret == KNOT_EOK);
knot_zonedb_build_index(zone_db);
namedb_t *db = NULL;
ret = open_timers_db(dbid, &db);
ok(ret == KNOT_EOK && db != NULL, "zone timers: create");
......@@ -79,7 +81,7 @@ int main(int argc, char *argv[])
zone_events_schedule_at(zone_1, ZONE_EVENT_FLUSH, FLUSH_TIME);
// Write the timers.
ret = write_zone_timers(db, zone_1);
ret = write_timer_db(db, zone_db);
ok(ret == KNOT_EOK, "zone timers: write");
// Read the timers.
......
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