]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
crimson/osd: use abort_source in stop_signal
authorKefu Chai <tchaikov@gmail.com>
Sat, 1 Oct 2022 09:43:00 +0000 (17:43 +0800)
committerKefu Chai <tchaikov@gmail.com>
Sat, 1 Oct 2022 09:43:00 +0000 (17:43 +0800)
before this change, `stop_signal::wait()` waits until it receives
`SIGTERM` or `SIGINT`, but we also need to stop the service per the
request of monitor or when a serious health condition is detected.

so, an `abort_source` should allow the server to request abort by
itself. also, as the single truth of stop, `stop_signal` will be
able to send the message to its subscribers to abort any "blocking"
calls which might prevent or delay the stop process.

Signed-off-by: Kefu Chai <tchaikov@gmail.com>
src/crimson/osd/stop_signal.h

index ccc340b138682941f5cfb994f0fba729b7e06b11..434156f1fb573a6c0e8d57fd58aecca5b67c2f65 100644 (file)
@@ -22,7 +22,7 @@
 
 #pragma once
 
-#include <seastar/core/sharded.hh>
+#include <seastar/core/abort_source.hh>
 #include <seastar/core/reactor.hh>
 #include <seastar/core/condition-variable.hh>
 
@@ -49,14 +49,15 @@ namespace seastar_apps_lib {
 /// });
 /// \endcode
 class stop_signal {
-    bool _caught = false;
     seastar::condition_variable _cond;
+    seastar::abort_source _abort_source;
+
 private:
     void signaled() {
-        if (_caught) {
+        if (stopping()) {
             return;
         }
-        _caught = true;
+        _abort_source.request_abort();
         _cond.broadcast();
     }
 public:
@@ -70,10 +71,13 @@ public:
         seastar::engine().handle_signal(SIGTERM, [] {});
     }
     seastar::future<> wait() {
-        return _cond.wait([this] { return _caught; });
+        return _cond.wait([this] { return _abort_source.abort_requested(); });
     }
     bool stopping() const {
-        return _caught;
+        return _abort_source.abort_requested();
+    }
+    auto& abort_source() {
+        return _abort_source;
     }
 };
 }