From 7ec7390211b2d27720be23a2ea9f786775aa5314 Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Fri, 4 Oct 2019 14:34:46 -0700 Subject: [PATCH] ircd::m::init::backfill: Fix interface; reenable for primary. --- include/ircd/m/init.h | 7 ++++++- include/ircd/m/m.h | 1 + matrix/homeserver.cc | 6 ++++++ matrix/init_backfill.cc | 45 ++++++++++------------------------------- matrix/matrix.cc | 1 - 5 files changed, 24 insertions(+), 36 deletions(-) diff --git a/include/ircd/m/init.h b/include/ircd/m/init.h index 7c1f01768..28651afb6 100644 --- a/include/ircd/m/init.h +++ b/include/ircd/m/init.h @@ -14,10 +14,15 @@ namespace ircd::m::init { struct modules; - struct backfill; struct bootstrap; } +/// Internal use only; do not call +namespace ircd::m::init::backfill +{ + void init(), fini() noexcept; +} + /// Internal use only; do not call struct ircd::m::init::modules { diff --git a/include/ircd/m/m.h b/include/ircd/m/m.h index 1bdb386b1..676ebea3e 100644 --- a/include/ircd/m/m.h +++ b/include/ircd/m/m.h @@ -51,6 +51,7 @@ namespace ircd #include "error.h" #include "id.h" #include "self.h" +#include "init.h" #include "event/event.h" #include "get.h" #include "query.h" diff --git a/matrix/homeserver.cc b/matrix/homeserver.cc index 064a69539..657d7bd0e 100644 --- a/matrix/homeserver.cc +++ b/matrix/homeserver.cc @@ -235,11 +235,17 @@ ircd::m::homeserver::homeserver(const struct opts *const &opts) m::keys::cache::set(key->verify_keys); signon(*this); + + if(primary == this) + m::init::backfill::init(); } ircd::m::homeserver::~homeserver() noexcept { + if(primary == this) + m::init::backfill::fini(); + signoff(*this); vm.reset(); diff --git a/matrix/init_backfill.cc b/matrix/init_backfill.cc index 2f30d2e86..79d93c107 100644 --- a/matrix/init_backfill.cc +++ b/matrix/init_backfill.cc @@ -8,27 +8,17 @@ // copyright notice and this permission notice is present in all copies. The // full license for this software is available in the LICENSE file. -namespace ircd::m::init +namespace ircd::m::init::backfill { - struct backfill; -} + bool handle_event(const room::id &, const event::id &, const string_view &hint, const bool &ask_one); + void handle_missing(const room::id &); + void handle_room(const room::id &); + void worker(); -/// This should be a namespace but we're stuck in struct m::init for now, so -/// this code should be portable for a future when m::init is unstructured. -struct ircd::m::init::backfill -{ - static bool handle_event(const room::id &, const event::id &, const string_view &hint, const bool &ask_one); - static void handle_missing(const room::id &); - static void handle_room(const room::id &); - static void worker(); - static void fini(); - static void init(); - - static run::changed worker_terminator; - static std::unique_ptr worker_context; - static conf::item enable; - static conf::item pool_size; - static log::log log; + extern std::unique_ptr worker_context; + extern conf::item enable; + extern conf::item pool_size; + extern log::log log; }; decltype(ircd::m::init::backfill::log) @@ -54,14 +44,6 @@ ircd::m::init::backfill::pool_size decltype(ircd::m::init::backfill::worker_context) ircd::m::init::backfill::worker_context; -decltype(ircd::m::init::backfill::worker_terminator) -ircd::m::init::backfill::worker_terminator{[] -(const auto &level) -{ - if(level == run::level::QUIT && worker_context) - worker_context->terminate(); -}}; - void ircd::m::init::backfill::init() { @@ -99,6 +81,7 @@ ircd::m::init::backfill::init() void ircd::m::init::backfill::fini() +noexcept { if(!worker_context) return; @@ -115,17 +98,11 @@ void ircd::m::init::backfill::worker() try { - // The common case is that we're in runlevel START when this context is - // entered; we don't want to start this operation until we're in RUN. run::changed::dock.wait([] { - return run::level != run::level::START; + return run::level == run::level::RUN; }); - // If some other level is observed here we shouldn't run this operation. - if(run::level != run::level::RUN) - return; - // Prepare to iterate all of the rooms this server is aware of which // contain at least one member from another server in any state, and // one member from our server in a joined state. diff --git a/matrix/matrix.cc b/matrix/matrix.cc index 23542923e..6d69b9a74 100644 --- a/matrix/matrix.cc +++ b/matrix/matrix.cc @@ -226,7 +226,6 @@ ircd::m::on_unload() noexcept try { //mods::imports.erase("m_listen"s); - if(m::sync::pool.size()) m::sync::pool.join();