From c3c73fcbe7dfac10abaf51bdc1d57858d396b85b Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Sun, 19 Mar 2023 12:41:45 -0700 Subject: [PATCH] ircd: Promote slave-mode to a non-maintenance mode allowing listeners. --- construct/construct.cc | 2 +- include/ircd/db/database.h | 1 - include/ircd/ircd.h | 5 ++-- ircd/db_database.cc | 13 +--------- ircd/ircd.cc | 20 +++++++++++++++ modules/m_listen.cc | 51 ++++++++++++++++++++++++-------------- 6 files changed, 58 insertions(+), 34 deletions(-) diff --git a/construct/construct.cc b/construct/construct.cc index 77ae2ea56..e19b114d6 100644 --- a/construct/construct.cc +++ b/construct/construct.cc @@ -571,7 +571,7 @@ applyargs() if(slave) { - ircd::db::open_slave.set("true"); + ircd::slave.set("true"); read_only = true; // slave implies read_only } diff --git a/include/ircd/db/database.h b/include/ircd/db/database.h index a821c0d50..08fb5c9e7 100644 --- a/include/ircd/db/database.h +++ b/include/ircd/db/database.h @@ -18,7 +18,6 @@ namespace ircd::db // Broad conf items extern conf::item open_recover; extern conf::item open_repair; - extern conf::item open_slave; extern conf::item auto_compact; extern conf::item auto_deletion; extern conf::item open_stats; diff --git a/include/ircd/ircd.h b/include/ircd/ircd.h index 50fbb2d4a..5e423432f 100644 --- a/include/ircd/ircd.h +++ b/include/ircd/ircd.h @@ -129,9 +129,10 @@ namespace ircd // Operating Mode Selectors extern conf::item debugmode; - extern conf::item maintenance; extern conf::item soft_assert; - extern conf::item read_only; // implies write_avoid + extern conf::item maintenance; + extern conf::item slave; + extern conf::item read_only; extern conf::item defaults; } diff --git a/ircd/db_database.cc b/ircd/db_database.cc index 266fafb69..8e0a395c6 100644 --- a/ircd/db_database.cc +++ b/ircd/db_database.cc @@ -81,17 +81,6 @@ ircd::db::auto_deletion { "persist", false }, }; -/// Conf item dictates whether databases will be opened in slave mode; this -/// is a recent feature of RocksDB which may not be available. It allows two -/// instances of a database, so long as only one is not opened as a slave. -decltype(ircd::db::open_slave) -ircd::db::open_slave -{ - { "name", "ircd.db.open.slave" }, - { "default", false }, - { "persist", false }, -}; - /// Gather statistics about files on open to inform the compaction algorithm. /// This can be disabled to prevent touching a lot of files on open, but it's /// unclear when/if that information will be gathered to ever inform compactor. @@ -940,7 +929,7 @@ try } ,slave { - db::open_slave + ircd::slave } ,read_only { diff --git a/ircd/ircd.cc b/ircd/ircd.cc index 482383df4..f2a75fdc2 100644 --- a/ircd/ircd.cc +++ b/ircd/ircd.cc @@ -107,6 +107,22 @@ ircd::maintenance } }; +/// Conf item dictates whether databases will be opened in slave mode; this +/// is a recent feature of RocksDB which may not be available. It allows +/// multiple processes to open the same database in a single-writer multiple +/// reader configuration. +/// +/// Originally this was intended as a maintenance mode to explore another live +/// running server's database. However it now allows listeners which can serve +/// as load-balanced mirrors and caches over a database shared at the fs level +/// locally or with nfs/ceph/intermezzo etc. +decltype(ircd::slave) +ircd::slave +{ + { "name", "ircd.slave" }, + { "default", false }, + { "persist", false }, +}; /// Coarse mode declaration for read-only behavior. All subsystems and feature /// modules respect this indicator by preventing any writes and persistence @@ -125,6 +141,10 @@ ircd::read_only if(!read_only) return; + // Not implict maintenance mode when slave mode is set. + if(slave) + return; + maintenance.set("true"); } }; diff --git a/modules/m_listen.cc b/modules/m_listen.cc index f2f935ae0..2e546c6e8 100644 --- a/modules/m_listen.cc +++ b/modules/m_listen.cc @@ -63,6 +63,11 @@ on_load() init_conf_listeners(); init_room_listeners(); + if(listeners.empty()) + log::warning + { + "No listening sockets configured; can't hear anyone." + }; } void @@ -145,7 +150,7 @@ init_conf_listeners() { "Listener '%s' configured for %s:%s by environment", p.first, - p.second["host"], + unquote(p.second["host"]), p.second["port"], }; } @@ -167,12 +172,6 @@ init_room_listeners() { load_listener(event); }); - - if(listeners.empty()) - log::warning - { - "No listening sockets configured; can't hear anyone." - }; } // @@ -265,19 +264,35 @@ load_listener(const m::event &event) json::get<"content"_>(event) }; - if(!load_listener(name, opts)) - return false; - - log::notice + if(ircd::slave) { - "Listener '%s' configured for %s:%s by %s", - name, - opts["host"], - opts["port"], - string_view{event.event_id}, - }; + log::warning + { + "Listener '%s' configured for %s:%s by %s ignored in slave mode.", + name, + unquote(opts["host"]), + opts["port"], + string_view{event.event_id}, + }; - return true; + return false; + } + + if(load_listener(name, opts)) + { + log::notice + { + "Listener '%s' configured for %s:%s by %s", + name, + unquote(opts["host"]), + opts["port"], + string_view{event.event_id}, + }; + + return true; + } + + return false; } ctx::context