0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-06-02 10:08:56 +02:00

ircd::conf: Add feature to toggle whether conf item is persisted in a db.

This commit is contained in:
Jason Volk 2018-12-08 16:15:22 -08:00
parent 5d3f6bf79e
commit 45bf911952
8 changed files with 37 additions and 7 deletions

View file

@ -51,6 +51,7 @@ namespace ircd::conf
extern callbacks<void (item<> &)> on_init;
bool exists(const string_view &key);
bool persists(const string_view &key);
string_view get(const string_view &key, const mutable_buffer &out);
bool set(const string_view &key, const string_view &value);
bool set(std::nothrow_t, const string_view &key, const string_view &value);

View file

@ -125,6 +125,21 @@ catch(const std::out_of_range &e)
};
}
bool
ircd::conf::persists(const string_view &key)
try
{
const auto &item(*items.at(key));
return item.feature.get("persist", true);
}
catch(const std::out_of_range &e)
{
throw not_found
{
"Conf item '%s' is not available", key
};
}
bool
ircd::conf::exists(const string_view &key)
{

View file

@ -336,6 +336,7 @@ ircd::db::open_check
{
{ "name", "ircd.db.open.check" },
{ "default", false },
{ "persist", false },
};
/// Conf item determines the recovery mode to use when opening any database.
@ -365,6 +366,7 @@ ircd::db::open_recover
{
{ "name", "ircd.db.open.recover" },
{ "default", "absolute" },
{ "persist", false },
};
void

View file

@ -981,6 +981,7 @@ ircd::fs::aio::enable
{
{ "name", "ircd.fs.aio.enable" },
{ "default", true },
{ "persist", false },
};
/// Global stats structure
@ -1049,6 +1050,7 @@ ircd::fs::fd::opts::direct_io_enable
{
{ "name", "ircd.fs.fd.direct_io_enable" },
{ "default", true },
{ "persist", false },
};
#ifdef __linux__

View file

@ -22,6 +22,7 @@ ircd::debugmode
{
{ "name", "ircd.debugmode" },
{ "default", false },
{ "persist", false },
};
/// Sets up the IRCd and its main context, then returns without blocking.

View file

@ -23,6 +23,7 @@ ircd::mods::enable
{
{ "name", "ircd.mods.enable" },
{ "default", true },
{ "persist", false },
};
decltype(ircd::mods::autoload)
@ -30,6 +31,7 @@ ircd::mods::autoload
{
{ "name", "ircd.mods.autoload" },
{ "default", true },
{ "persist", false },
};
//

View file

@ -896,6 +896,7 @@ ircd::net::listen
{
{ "name", "ircd.net.listen" },
{ "default", true },
{ "persist", false },
};
//

View file

@ -132,6 +132,11 @@ noexcept try
if(runlevel == runlevel::START && !conf::exists(key))
return;
// Conf items marked with a persist=false property are not read from
// the conf room into the item, even if the value exists in the room.
if(conf::exists(key) && !conf::persists(key))
return;
log::debug
{
"Updating conf [%s] => %s", key, value
@ -247,13 +252,7 @@ create_conf_room(const m::event &,
m::vm::eval &)
{
m::create(conf_room_id, m::me.user_id);
for(const auto &p : conf::items)
{
const auto &key{p.first};
const auto &item{p.second}; assert(item);
create_conf_item(key, *item);
}
rehash_conf({}, true);
}
const m::hookfn<m::vm::eval &>
@ -283,6 +282,13 @@ rehash_conf(const string_view &prefix,
continue;
const auto &item{p.second}; assert(item);
// Conf items marked with a persist=false property are not written
// to the conf room.
if(!item->feature.get("persist", true))
continue;
// Use the `existing` argument to toggle a force-overwrite
if(!existing)
if(state.has("ircd.conf.item", key))
continue;