Commit 21fa0abd authored by Daniel Salzman's avatar Daniel Salzman

ctl: purge also zone timers with zone-purge

parent 428a030f
......@@ -135,7 +135,7 @@ requires a ttl value specified.
Remove zone data within the transaction.
.TP
\fBzone\-purge\fP \fIzone\fP\&...
Purge zone data, zone file, and zone journal.
Purge zone data, file, journal, and timers.
.TP
\fBconf\-init\fP
Initialize the configuration database. (*)
......
......@@ -112,7 +112,7 @@ Actions
Remove zone data within the transaction.
**zone-purge** *zone*...
Purge zone data, zone file, and zone journal.
Purge zone data, file, journal, and timers.
**conf-init**
Initialize the configuration database. (*)
......
......@@ -22,6 +22,7 @@
#include "knot/ctl/commands.h"
#include "knot/events/handlers.h"
#include "knot/updates/zone-update.h"
#include "knot/zone/timers.h"
#include "libknot/libknot.h"
#include "libknot/yparser/yptrafo.h"
#include "contrib/macros.h"
......@@ -915,7 +916,9 @@ static int zone_purge(zone_t *zone, ctl_args_t *args)
(void)unlink(journalfile);
free(journalfile);
// TODO: Purge the zone timers (after zone events refactoring).
// Purge the zone timers.
(void)remove_timer_db(args->server->timers_db, args->server->zone_db,
zone->name);
return KNOT_EOK;
}
......
......@@ -219,6 +219,40 @@ int write_timer_db(knot_db_t *timer_db, knot_zonedb_t *zone_db)
return db_api->txn_commit(&txn);
}
int remove_timer_db(knot_db_t *timer_db, knot_zonedb_t *zone_db,
const knot_dname_t *zone_name)
{
if (timer_db == NULL) {
return KNOT_EOK;
}
if (zone_db == NULL || zone_name == NULL) {
return KNOT_EINVAL;
}
const knot_db_api_t *db_api = knot_db_lmdb_api();
assert(db_api);
knot_db_txn_t txn;
int ret = db_api->txn_begin(timer_db, &txn, KNOT_DB_SORTED);
if (ret != KNOT_EOK) {
return ret;
}
knot_db_val_t key = {
.data = (void *)zone_name,
.len = knot_dname_size(zone_name)
};
ret = db_api->del(&txn, &key);
if (ret != KNOT_EOK) {
db_api->txn_abort(&txn);
return ret;
}
return db_api->txn_commit(&txn);
}
int sweep_timer_db(knot_db_t *timer_db, knot_zonedb_t *zone_db)
{
if (timer_db == NULL) {
......
......@@ -62,6 +62,18 @@ int read_zone_timers(knot_db_t *timer_db, const zone_t *zone, time_t *timers);
*/
int write_timer_db(knot_db_t *timer_db, knot_zonedb_t *zone_db);
/*!
* \brief Removes specific zone timers from timers db.
*
* \param timer_db Timer database.
* \param zone_db Zone database.
* \param zone_name Zone name.
*
* \return KNOT_E*
*/
int remove_timer_db(knot_db_t *timer_db, knot_zonedb_t *zone_db,
const knot_dname_t *zone_name);
/*!
* \brief Removes stale zones info from timers db.
*
......
......@@ -930,7 +930,7 @@ static const cmd_help_t cmd_help_table[] = {
{ CMD_ZONE_GET, "<zone> [<owner> [<type>]]", "Get zone data within the transaction." },
{ CMD_ZONE_SET, "<zone> <owner> [<ttl>] <type> <rdata>", "Add zone record within the transaction." },
{ CMD_ZONE_UNSET, "<zone> <owner> [<type> [<rdata>]]", "Remove zone data within the transaction." },
{ CMD_ZONE_PURGE, "<zone>...", "Purge zone data, zone file, and zone journal." },
{ CMD_ZONE_PURGE, "<zone>...", "Purge zone data, file, journal, and timers." },
{ "", "", "" },
{ CMD_CONF_INIT, "", "Initialize the confdb. (*)" },
{ CMD_CONF_CHECK, "", "Check the server configuration. (*)" },
......
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