Skip to content
Snippets Groups Projects
Commit 5e7a9244 authored by Jan Včelák's avatar Jan Včelák :rocket:
Browse files

Merge branch 'conf_timer_db' into 'master'

Configurable timer database location.
parents 50c236f0 8fff90fa
No related branches found
No related tags found
No related merge requests found
......@@ -484,6 +484,7 @@ if a zone doesn\(aqt have another template specified.
.ft C
template:
\- id: STR
timer\-db: STR
global\-module: STR/STR ...
# All zone options (excluding \(aqtemplate\(aq item)
.ft P
......@@ -493,12 +494,20 @@ template:
.SS id
.sp
A template identifier.
.SS timer\-db
.sp
Specifies a path of the persistent timer database. The path can be specified
as a relative path to the \fIdefault\fP template \fI\%storage\fP\&.
.sp
\fICaution:\fP This option is only available in the \fIdefault\fP template.
.sp
\fIDefault:\fP \fI\%storage\fP/timers
.SS global\-module
.sp
An ordered list of references to query modules in the form
\fImodule_name/module_id\fP\&. These modules apply to all queries.
.sp
\fICaution:\fP This option is available only for the \fIdefault\fP template.
\fICaution:\fP This option is only available in the \fIdefault\fP template.
.sp
\fIDefault:\fP not set
.SH ZONE SECTION
......
......@@ -552,6 +552,7 @@ if a zone doesn't have another template specified.
template:
- id: STR
timer-db: STR
global-module: STR/STR ...
# All zone options (excluding 'template' item)
......@@ -562,6 +563,18 @@ id
A template identifier.
.. _template_timer-db:
timer-db
--------
Specifies a path of the persistent timer database. The path can be specified
as a relative path to the *default* template :ref:`storage<zone_storage>`.
*Caution:* This option is only available in the *default* template.
*Default:* :ref:`storage<zone_storage>`/timers
.. _template_global-module:
global-module
......@@ -570,7 +583,7 @@ global-module
An ordered list of references to query modules in the form
*module_name/module_id*. These modules apply to all queries.
*Caution:* This option is available only for the *default* template.
*Caution:* This option is only available in the *default* template.
*Default:* not set
......
......@@ -156,6 +156,7 @@ static const yp_item_t desc_remote[] = {
static const yp_item_t desc_template[] = {
{ C_ID, YP_TSTR, YP_VNONE },
ZONE_ITEMS
{ C_TIMER_DB, YP_TSTR, YP_VSTR = { "timers" } }, \
{ C_GLOBAL_MODULE, YP_TDATA, YP_VDATA = { 0, NULL, mod_id_to_bin, mod_id_to_txt }, \
YP_FMULTI, { check_modref } }, \
{ NULL }
......
......@@ -76,6 +76,7 @@
#define C_TCP_IDLE_TIMEOUT "\x10""tcp-idle-timeout"
#define C_TCP_REPLY_TIMEOUT "\x11""tcp-reply-timeout"
#define C_TCP_WORKERS "\x0B""tcp-workers"
#define C_TIMER_DB "\x08""timer-db"
#define C_TPL "\x08""template"
#define C_UDP_WORKERS "\x0B""udp-workers"
#define C_USER "\x04""user"
......
......@@ -295,8 +295,6 @@ int addr_range_to_txt(
int check_ref(
conf_check_t *args)
{
const char *err_str = "invalid reference";
const yp_item_t *ref = args->item->var.r.ref;
// Try to find a referenced block with the id.
......@@ -304,7 +302,8 @@ int check_ref(
int ret = conf_db_get(args->conf, args->txn, ref->name, NULL,
args->data, args->data_len, NULL);
if (ret != KNOT_EOK) {
args->err_str = err_str;
args->err_str = "invalid reference";
}
return ret;
......@@ -313,8 +312,6 @@ int check_ref(
int check_modref(
conf_check_t *args)
{
const char *err_str = "invalid module reference";
const yp_name_t *mod_name = (const yp_name_t *)args->data;
const uint8_t *id = args->data + 1 + args->data[0];
size_t id_len = args->data_len - 1 - args->data[0];
......@@ -324,7 +321,8 @@ int check_modref(
int ret = conf_db_get(args->conf, args->txn, mod_name, NULL, id, id_len,
NULL);
if (ret != KNOT_EOK) {
args->err_str = err_str;
args->err_str = "invalid module reference";
}
return ret;
......@@ -333,12 +331,10 @@ int check_modref(
int check_remote(
conf_check_t *args)
{
const char *err_str = "no remote address defined";
conf_val_t addr = conf_rawid_get_txn(args->conf, args->txn, C_RMT,
C_ADDR, args->id, args->id_len);
if (conf_val_count(&addr) == 0) {
args->err_str = err_str;
args->err_str = "no remote address defined";
return KNOT_EINVAL;
}
......@@ -348,19 +344,28 @@ int check_remote(
int check_template(
conf_check_t *args)
{
const char *err_str = "global module is only allowed with the default template";
// Ignore the default template.
if (args->id_len == CONF_DEFAULT_ID[0] &&
memcmp(args->id, CONF_DEFAULT_ID + 1, args->id_len) == 0) {
return KNOT_EOK;
}
// Check global-module.
conf_val_t g_module = conf_rawid_get_txn(args->conf, args->txn, C_TPL,
C_GLOBAL_MODULE, args->id,
args->id_len);
if (g_module.code == KNOT_EOK) {
args->err_str = err_str;
args->err_str = "global module in non-default template";
return KNOT_EINVAL;
}
// Check timer-db.
conf_val_t timer_db = conf_rawid_get_txn(args->conf, args->txn, C_TPL,
C_TIMER_DB, args->id, args->id_len);
if (timer_db.code == KNOT_EOK) {
args->err_str = "timer database location in non-default template";
return KNOT_EINVAL;
}
......@@ -370,8 +375,6 @@ int check_template(
int check_zone(
conf_check_t *args)
{
const char *err_str = "slave zone with DNSSEC signing";
conf_val_t master = conf_zone_get_txn(args->conf, args->txn,
C_MASTER, args->id);
conf_val_t dnssec = conf_zone_get_txn(args->conf, args->txn,
......@@ -379,7 +382,7 @@ int check_zone(
// DNSSEC signing is not possible with slave zone.
if (conf_val_count(&master) > 0 && conf_bool(&dnssec)) {
args->err_str = err_str;
args->err_str = "slave zone with DNSSEC signing";
return KNOT_EINVAL;
}
......
......@@ -660,8 +660,12 @@ static void reopen_timers_database(conf_t *conf, server_t *server)
conf_val_t val = conf_default_get(conf, C_STORAGE);
char *storage = conf_abs_path(&val, NULL);
int ret = open_timers_db(storage, &server->timers_db);
val = conf_default_get(conf, C_TIMER_DB);
char *timer_db = conf_abs_path(&val, storage);
free(storage);
int ret = open_timers_db(timer_db, &server->timers_db);
free(timer_db);
if (ret != KNOT_EOK && ret != KNOT_ENOTSUP) {
log_warning("cannot open persistent timers DB (%s)",
knot_strerror(ret));
......
......@@ -143,28 +143,21 @@ static int read_timers(namedb_txn_t *txn, const zone_t *zone, time_t *timers)
/* -------- API ------------------------------------------------------------- */
int open_timers_db(const char *storage, namedb_t **db_ptr)
int open_timers_db(const char *path, namedb_t **timer_db)
{
if (storage == NULL || db_ptr == NULL) {
if (path == NULL || timer_db == NULL) {
return KNOT_EINVAL;
}
struct namedb_lmdb_opts opts = NAMEDB_LMDB_OPTS_INITIALIZER;
const namedb_api_t *db_api = namedb_lmdb_api();
if (db_api == NULL) {
return KNOT_ENOTSUP;
}
opts.path = sprintf_alloc("%s/timers", storage);
if (opts.path == NULL) {
return KNOT_ENOMEM;
}
int ret = db_api->init(db_ptr, NULL, &opts);
free((char *)opts.path);
struct namedb_lmdb_opts opts = NAMEDB_LMDB_OPTS_INITIALIZER;
opts.path = path;
return ret;
return db_api->init(timer_db, NULL, &opts);
}
void close_timers_db(namedb_t *timer_db)
......
......@@ -21,14 +21,14 @@
#include "knot/zone/zonedb.h"
/*!
* \brief Opens zone timers db. No-op without LMDB support.
* \brief Opens zone timers db.
*
* \param[in] storage Path to storage directory.
* \param[in] path Path to a directory with the database.
* \param[out] timer_db Created database.
*
* \return KNOT_E*
*/
int open_timers_db(const char *storage, namedb_t **timer_db);
int open_timers_db(const char *path, namedb_t **timer_db);
/*!
* \brief Closes zone timers db.
......
This diff is collapsed.
......@@ -82,6 +82,7 @@ version { lval.t = yytext; return SVERSION; }
nsid { lval.t = yytext; return NSID; }
max-udp-payload { lval.t = yytext; return MAX_UDP_PAYLOAD; }
storage { lval.t = yytext; return STORAGE; }
timer-db { lval.t = yytext; return TIMER_DB; }
key { lval.t = yytext; return KEY; }
keys { lval.t = yytext; return KEYS; }
remotes { lval.t = yytext; return REMOTES; }
......
This diff is collapsed.
......@@ -92,25 +92,26 @@ extern int cf_debug;
RATE_LIMIT_SLIP = 302,
TRANSFERS = 303,
STORAGE = 304,
DNSSEC_ENABLE = 305,
DNSSEC_KEYDIR = 306,
SIGNATURE_LIFETIME = 307,
SERIAL_POLICY = 308,
SERIAL_POLICY_VAL = 309,
QUERY_MODULE = 310,
INTERFACES = 311,
ADDRESS = 312,
PORT = 313,
IPA = 314,
IPA6 = 315,
VIA = 316,
CONTROL = 317,
ALLOW = 318,
LISTEN_ON = 319,
LOG = 320,
LOG_DEST = 321,
LOG_SRC = 322,
LOG_LEVEL = 323
TIMER_DB = 305,
DNSSEC_ENABLE = 306,
DNSSEC_KEYDIR = 307,
SIGNATURE_LIFETIME = 308,
SERIAL_POLICY = 309,
SERIAL_POLICY_VAL = 310,
QUERY_MODULE = 311,
INTERFACES = 312,
ADDRESS = 313,
PORT = 314,
IPA = 315,
IPA6 = 316,
VIA = 317,
CONTROL = 318,
ALLOW = 319,
LISTEN_ON = 320,
LOG = 321,
LOG_DEST = 322,
LOG_SRC = 323,
LOG_LEVEL = 324
};
#endif
......@@ -127,7 +128,7 @@ union YYSTYPE
size_t l;
} tok;
#line 131 "cf-parse.tab.h" /* yacc.c:1909 */
#line 132 "cf-parse.tab.h" /* yacc.c:1909 */
};
# define YYSTYPE_IS_TRIVIAL 1
# define YYSTYPE_IS_DECLARED 1
......
......@@ -408,6 +408,7 @@ static void grp_add(void *scanner, const char *value)
%token <tok> RATE_LIMIT_SLIP
%token <tok> TRANSFERS
%token <TOK> STORAGE
%token <TOK> TIMER_DB
%token <tok> DNSSEC_ENABLE
%token <tok> DNSSEC_KEYDIR
%token <tok> SIGNATURE_LIFETIME
......@@ -707,6 +708,7 @@ zones:
| zones DBSYNC_TIMEOUT NUM ';' { f_int(scanner, R_ZONE_TPL, C_ZONEFILE_SYNC, $3.i); }
| zones DBSYNC_TIMEOUT INTERVAL ';' { f_int(scanner, R_ZONE_TPL, C_ZONEFILE_SYNC, $3.i); }
| zones STORAGE TEXT ';' { f_quote(scanner, R_ZONE_TPL, C_STORAGE, $3.t); free($3.t); }
| zones TIMER_DB TEXT ';' { f_quote(scanner, R_ZONE_TPL, C_TIMER_DB, $3.t); free($3.t); }
| zones DNSSEC_ENABLE BOOL ';' { f_bool(scanner, R_ZONE_TPL, C_DNSSEC_SIGNING, $3.i); }
| zones DNSSEC_KEYDIR TEXT ';' { f_quote(scanner, R_ZONE_TPL, C_KASP_DB, $3.t); free($3.t); }
| zones SERIAL_POLICY SERIAL_POLICY_VAL ';' { f_str(scanner, R_ZONE_TPL, C_SERIAL_POLICY, $3.t); }
......
......@@ -95,6 +95,7 @@ typedef enum {
#define C_TCP_IDLE_TIMEOUT "\x10""tcp-idle-timeout"
#define C_TCP_REPLY_TIMEOUT "\x11""tcp-reply-timeout"
#define C_TCP_WORKERS "\x0B""tcp-workers"
#define C_TIMER_DB "\x08""timer-db"
#define C_TPL "\x08""template"
#define C_UDP_WORKERS "\x0B""udp-workers"
#define C_USER "\x04""user"
......
......@@ -125,20 +125,17 @@ int main(int argc, char *argv[])
close_timers_db(db);
// Cleanup temporary DB.
char *timers_dir = sprintf_alloc("%s/timers", dbid);
DIR *dir = opendir(timers_dir);
DIR *dir = opendir(dbid);
struct dirent *dp;
while ((dp = readdir(dir)) != NULL) {
if (dp->d_name[0] == '.') {
continue;
}
char *file = sprintf_alloc("%s/%s", timers_dir, dp->d_name);
char *file = sprintf_alloc("%s/%s", dbid, dp->d_name);
remove(file);
free(file);
}
closedir(dir);
remove(timers_dir);
free(timers_dir);
remove(dbid);
return EXIT_SUCCESS;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment