]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
crimson/common/interrupt_future: simplify may_interrupt 47847/head
authorXuehan Xu <xxhdx1985126@gmail.com>
Mon, 29 Aug 2022 08:07:47 +0000 (16:07 +0800)
committerXuehan Xu <xxhdx1985126@gmail.com>
Thu, 1 Sep 2022 01:41:27 +0000 (09:41 +0800)
Signed-off-by: Xuehan Xu <xxhdx1985126@gmail.com>
src/crimson/common/interruptible_future.h
src/crimson/os/seastore/transaction.h
src/crimson/osd/pg_interval_interrupt_condition.h
src/test/crimson/test_interruptible_future.cc

index 61660a217bccddeb42fb21c1324129339a9ef9e4..299f1285046f755dd50fc491dfc44249dbffb90c 100644 (file)
@@ -170,17 +170,17 @@ auto call_with_interruption_impl(
   // global "interrupt_cond" with the interruption condition, and go ahead
   // executing the Func.
   assert(interrupt_condition);
-  auto [interrupt, fut] = interrupt_condition->template may_interrupt<
+  auto fut = interrupt_condition->template may_interrupt<
     typename futurator_t::type>();
   INTR_FUT_DEBUG(
     "call_with_interruption_impl: may_interrupt: {}, "
     "local interrupt_condition: {}, "
     "global interrupt_cond: {},{}",
-    interrupt,
+    (bool)fut,
     (void*)interrupt_condition.get(),
     (void*)interrupt_cond<InterruptCond>.interrupt_cond.get(),
     typeid(InterruptCond).name());
-  if (interrupt) {
+  if (fut) {
     return std::move(*fut);
   }
   interrupt_cond<InterruptCond>.set(interrupt_condition);
@@ -271,15 +271,15 @@ Result non_futurized_call_with_interruption(
   Func&& func, T&&... args)
 {
   assert(interrupt_condition);
-  auto [interrupt, fut] = interrupt_condition->template may_interrupt<seastar::future<>>();
+  auto fut = interrupt_condition->template may_interrupt<seastar::future<>>();
   INTR_FUT_DEBUG(
     "non_futurized_call_with_interruption may_interrupt: {}, "
     "interrupt_condition: {}, interrupt_cond: {},{}",
-    interrupt,
+    (bool)fut,
     (void*)interrupt_condition.get(),
     (void*)interrupt_cond<InterruptCond>.interrupt_cond.get(),
     typeid(InterruptCond).name());
-  if (interrupt) {
+  if (fut) {
     std::rethrow_exception(fut->get_exception());
   }
   interrupt_cond<InterruptCond>.set(interrupt_condition);
index e38d3c56f179c890c4863dd4ca9de0891b747b36..b5508fdb30f5375e3a7384a9c78b6c2c1211c104 100644 (file)
@@ -544,14 +544,12 @@ public:
   TransactionConflictCondition(Transaction &t) : t(t) {}
 
   template <typename Fut>
-  std::pair<bool, std::optional<Fut>> may_interrupt() {
+  std::optional<Fut> may_interrupt() {
     if (t.conflicted) {
-      return {
-       true,
-       seastar::futurize<Fut>::make_exception_future(
-         transaction_conflict())};
+      return seastar::futurize<Fut>::make_exception_future(
+       transaction_conflict());
     } else {
-      return {false, std::optional<Fut>()};
+      return std::optional<Fut>();
     }
   }
 
index a59e479638ca754dee6b0a8f3980325a53c8501d..a3a0a1edbcf5aa90298199ba9f8461a42c9bcf78 100644 (file)
@@ -24,16 +24,16 @@ public:
   bool is_primary();
 
   template <typename Fut>
-  std::pair<bool, std::optional<Fut>> may_interrupt() {
+  std::optional<Fut> may_interrupt() {
     if (new_interval_created()) {
-      return {true, seastar::futurize<Fut>::make_exception_future(
-        ::crimson::common::actingset_changed(is_primary()))};
+      return seastar::futurize<Fut>::make_exception_future(
+        ::crimson::common::actingset_changed(is_primary()));
     }
     if (is_stopping()) {
-      return {true, seastar::futurize<Fut>::make_exception_future(
-        ::crimson::common::system_shutdown_exception())};
+      return seastar::futurize<Fut>::make_exception_future(
+        ::crimson::common::system_shutdown_exception());
     }
-    return {false, std::optional<Fut>()};
+    return std::optional<Fut>();
   }
 
   template <typename T>
index 4e4288686dea6a1cd50709ec410307d80311b307..9032ad3b72d7b4ce87959ec1b8f6be44413065d1 100644 (file)
@@ -19,12 +19,12 @@ public:
     : interrupt(interrupt) {}
 
   template <typename T>
-  std::pair<bool, std::optional<T>> may_interrupt() {
-    if (interrupt)
-      return std::pair<bool, std::optional<T>>(
-         true, seastar::futurize<T>::make_exception_future(test_interruption()));
-    else
-      return std::pair<bool, std::optional<T>>(false, std::optional<T>());
+  std::optional<T> may_interrupt() {
+    if (interrupt) {
+      return seastar::futurize<T>::make_exception_future(test_interruption());
+    } else {
+      return std::optional<T>();
+    }
   }
 
   template <typename T>