Commit 7e9d4851 authored by Libor Peltan's avatar Libor Peltan Committed by Daniel Salzman

events: reconf zone db, wait for event queue instead drop...

...forcedly dropping planned events from worker pool
queue causes zone_events_t->running "true" forever,
causing deadlock for this zone veents processing.
Instead, we wait for queue being processed by workers.
parent 1c27f80b
/* 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
......@@ -70,7 +70,7 @@ static int evsched_run(dthread_t *thread)
/* Run event loop. */
pthread_mutex_lock(&sched->heap_lock);
while (!dt_is_cancelled(thread)) {
if (!!EMPTY_HEAP(&sched->heap)) {
if (!!EMPTY_HEAP(&sched->heap) || sched->paused) {
pthread_cond_wait(&sched->notify, &sched->heap_lock);
continue;
}
......@@ -250,3 +250,18 @@ void evsched_join(evsched_t *sched)
{
dt_join(sched->thread);
}
void evsched_pause(evsched_t *sched)
{
pthread_mutex_lock(&sched->heap_lock);
sched->paused = true;
pthread_mutex_unlock(&sched->heap_lock);
}
void evsched_resume(evsched_t *sched)
{
pthread_mutex_lock(&sched->heap_lock);
sched->paused = false;
pthread_cond_signal(&sched->notify);
pthread_mutex_unlock(&sched->heap_lock);
}
/* 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
......@@ -61,7 +61,7 @@ typedef struct event {
* \brief Event scheduler structure.
*/
typedef struct evsched {
volatile bool running; /*!< True if running. */
volatile bool paused; /*!< Temporarily stop processing events. */
pthread_mutex_t heap_lock; /*!< Event heap locking. */
pthread_cond_t notify; /*!< Event heap notification. */
struct heap heap; /*!< Event heap. */
......@@ -137,6 +137,17 @@ int evsched_schedule(event_t *ev, uint32_t dt);
*/
int evsched_cancel(event_t *ev);
/*! \brief Start event processing threads. */
void evsched_start(evsched_t *sched);
/*! \brief Stop event processing threads. */
void evsched_stop(evsched_t *sched);
/*! \brief Join event processing threads. */
void evsched_join(evsched_t *sched);
/*! \brief Temporarily stop processing events. */
void evsched_pause(evsched_t *sched);
/*! \brief Resume processing events. */
void evsched_resume(evsched_t *sched);
/* 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
......@@ -881,9 +881,8 @@ void server_update_zones(conf_t *conf, server_t *server)
knot_zonedb_foreach(server->zone_db, zone_events_freeze);
}
/* Suspend workers, clear wating events, finish running events. */
worker_pool_suspend(server->workers);
worker_pool_clear(server->workers);
/* Suspend adding events to worker pool queue, wait for queued events. */
evsched_pause(&server->sched);
worker_pool_wait(server->workers);
/* Reload zone database and free old zones. */
......@@ -893,8 +892,8 @@ void server_update_zones(conf_t *conf, server_t *server)
/* Trim extra heap. */
mem_trim();
/* Resume workers and allow events on new zones. */
worker_pool_resume(server->workers);
/* Resume processing events on new zones. */
evsched_resume(&server->sched);
if (server->zone_db) {
knot_zonedb_foreach(server->zone_db, zone_events_start);
}
......
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