]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
crimson/net: fix execution_done wait mechanism
authorYingxin Cheng <yingxin.cheng@intel.com>
Fri, 25 Nov 2022 02:05:18 +0000 (10:05 +0800)
committerYingxin Cheng <yingxin.cheng@intel.com>
Wed, 8 Feb 2023 06:07:41 +0000 (14:07 +0800)
* prepare the execution_done before the function is invoked, not after.
* execution_done future doesn't need to be shared.

Signed-off-by: Yingxin Cheng <yingxin.cheng@intel.com>
src/crimson/net/ProtocolV2.cc
src/crimson/net/ProtocolV2.h

index 3f24fa0925daf0601e912305743ee64b4c643aef..083978dd96ff4eb640f8c0c794f80958dc3bc6c4 100644 (file)
@@ -1640,7 +1640,9 @@ void ProtocolV2::trigger_replacing(bool reconnect,
     return wait_out_exit_dispatching(
     ).then([this] {
       protocol_timer.cancel();
-      return execution_done.get_future();
+      auto done = std::move(execution_done);
+      execution_done = seastar::now();
+      return done;
     }).then([this,
              reconnect,
              do_reset,
index 3c2b5e67434a94762be35147e2b94674d75c2395..d9216570b7ace11b846b863582e005399deec843 100644 (file)
@@ -108,13 +108,27 @@ class ProtocolV2 final : public Protocol {
   uint64_t peer_global_seq = 0;
   uint64_t connect_seq = 0;
 
-  seastar::shared_future<> execution_done = seastar::now();
+  seastar::future<> execution_done = seastar::now();
 
   template <typename Func>
   void gated_execute(const char* what, Func&& func) {
     gate.dispatch_in_background(what, *this, [this, &func] {
-      execution_done = seastar::futurize_invoke(std::forward<Func>(func));
-      return execution_done.get_future();
+      if (!execution_done.available()) {
+        // discard the unready future
+        gate.dispatch_in_background(
+          "gated_execute_abandon",
+          *this,
+          [fut=std::move(execution_done)]() mutable {
+            return std::move(fut);
+          }
+        );
+      }
+      seastar::promise<> pr;
+      execution_done = pr.get_future();
+      return seastar::futurize_invoke(std::forward<Func>(func)
+      ).finally([pr=std::move(pr)]() mutable {
+        pr.set_value();
+      });
     });
   }