From 967ebacaa42c1f3100f693c808b9d932c9cd2788 Mon Sep 17 00:00:00 2001 From: Pavel Emelyanov Date: Mon, 18 Sep 2023 20:44:01 +0300 Subject: [PATCH] view_update_generator: Move abort kicking to do_abort() When v.u.g. stops is first aborts the generation background fiber by requesting abort on the internal abort source and signalling the fiber in case it's waiting. Right now v.u.g.::stop() is defer-scheduled last in main(), so this move doesn't change much -- when stop_signal fires, it will kick the v.u.g.::do_abort() just a bit earlier, there's nothing that would happen after it before real ::stop() is called that depends on it. Signed-off-by: Pavel Emelyanov --- db/view/view_update_generator.cc | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/db/view/view_update_generator.cc b/db/view/view_update_generator.cc index 23c894cfe2..21cfaa2419 100644 --- a/db/view/view_update_generator.cc +++ b/db/view/view_update_generator.cc @@ -215,13 +215,31 @@ future<> view_update_generator::start() { return make_ready_future<>(); } -void view_update_generator::do_abort() noexcept { -} +// The .do_abort() just kicks the v.u.g. background fiber to wrap up and it +// normally happens when scylla stops upon SIGINT. Doing it that early is safe, +// once the fiber is kicked, no new work can be added to it, see _as check in +// register_staging_sstable(). +// +// The .stop() really stops the sharded service by waiting for the fiber +// to stop using 'this' and thus releasing any resources owned by it. It also +// calls do_abort() to handle the case when subscription didn't shoot which, in +// turn, can happen when main() throws in the middle and doesn't request abort +// via the stop-signal. + +void view_update_generator::do_abort() noexcept { + if (_as.abort_requested()) { + // The below code is re-entrable, but avoid it explicitly to be + // on the safe side in case it suddenly stops being such + return; + } -future<> view_update_generator::stop() { _db.unplug_view_update_generator(); _as.request_abort(); _pending_sstables.signal(); +} + +future<> view_update_generator::stop() { + do_abort(); return std::move(_started).then([this] { _registration_sem.broken(); });