From 38d0ea0916eae1bcdbdb0e2badf9f734081e25e5 Mon Sep 17 00:00:00 2001 From: Pavel Emelyanov Date: Tue, 12 Sep 2023 14:54:15 +0300 Subject: [PATCH] batchlog_manager: Fix drain() reentrability Currently drain() is called twise -- first time from storage_service::drain() (on shutdown), second via batchlog_manager::stop(). The routine is unintentinally re-entrable, because: - explicit check for not aborting the abort source twise - breaking semaphore can be done multiple times - co-await-ing of the _started future works because the future is shared That's not extremely elegant, better to make the drain() bail out early if it was already called. Signed-off-by: Pavel Emelyanov --- db/batchlog_manager.cc | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/db/batchlog_manager.cc b/db/batchlog_manager.cc index ce9c8f38a2..796262bba1 100644 --- a/db/batchlog_manager.cc +++ b/db/batchlog_manager.cc @@ -115,10 +115,12 @@ future<> db::batchlog_manager::start() { } future<> db::batchlog_manager::drain() { - blogger.info("Asked to drain"); - if (!_stop.abort_requested()) { - _stop.request_abort(); + if (_stop.abort_requested()) { + co_return; } + + blogger.info("Asked to drain"); + _stop.request_abort(); if (this_shard_id() == 0) { // Abort do_batch_log_replay if waiting on the semaphore. _sem.broken();