From 260a702ba983f1bca29d4c8d1e28f3eef46c6699 Mon Sep 17 00:00:00 2001 From: Kefu Chai Date: Wed, 9 Sep 2020 21:03:32 +0800 Subject: [PATCH] crimson/common,cmake: use seastar API Level 5 * cmake: bump Seastar_API_LEVEL to "5" * errorator.h: add invoke() methods to futurize variants, as in seastar API level 5, the future's store type is now either monostate or a single T, instead of tuple. so it'd be simpler to integrate with seastar with invoke() semantic without the boxing-unboxing dance. * errorator.h: drop apply() methods, as they are not used anymore. * errorator.h: rename and revise tuple2future. as the store type is not tuple now, the trait's name is changed accordingly to match seastar::internal::future_stored_type Signed-off-by: Kefu Chai --- src/CMakeLists.txt | 2 +- src/crimson/common/errorator.h | 68 +++++++++++++++++++++++----------- 2 files changed, 47 insertions(+), 23 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 1f8628c8346ed..38d33bac44ac9 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -317,7 +317,7 @@ if(WITH_SEASTAR) _find_package(${ARGV}) endif() endmacro () - set(Seastar_API_LEVEL "4" CACHE STRING "" FORCE) + set(Seastar_API_LEVEL "5" CACHE STRING "" FORCE) set(Seastar_HWLOC OFF CACHE BOOL "" FORCE) set(Seastar_STD_OPTIONAL_VARIANT_STRINGVIEW ON CACHE BOOL "" FORCE) if(Seastar_DPDK) diff --git a/src/crimson/common/errorator.h b/src/crimson/common/errorator.h index 450227d780614..dc36dfc37a0e0 100644 --- a/src/crimson/common/errorator.h +++ b/src/crimson/common/errorator.h @@ -54,7 +54,7 @@ inline auto do_until(AsyncAction action) { while (true) { auto f = futurator::invoke(action); - if (!seastar::need_preempt() && f.available() && std::get<0>(f.get())) { + if (!seastar::need_preempt() && f.available() && f.get()) { return futurator::type::errorator_type::template make_ready_future<>(); } if (!f.available() || seastar::need_preempt()) { @@ -570,8 +570,8 @@ private: // solution here would be mark the `::get_available_state()` // as `protected` and use dedicated `get_value()` exactly as // `::then()` already does. - return futurator_t::apply(std::forward(valfunc), - std::move(future).get()); + return futurator_t::invoke(std::forward(valfunc), + std::move(future).get()); } }); } @@ -835,21 +835,36 @@ private: class futurize { using vanilla_futurize = seastar::futurize; - template - struct tuple2future {}; - template - struct tuple2future > { - using type = future; + template + struct stored_to_future { + using type = future; + }; + template + struct stored_to_future { + using type = future<>; }; public: using type = - typename tuple2future::type; + typename stored_to_future::type; template - static type apply(Func&& func, std::tuple&& args) { - return vanilla_futurize::apply(std::forward(func), - std::forward>(args)); + static type invoke(Func&& func, Args&&... args) { + try { + return vanilla_futurize::invoke(std::forward(func), + std::forward(args)...); + } catch (...) { + return make_exception_future(std::current_exception()); + } + } + + template + static type invoke(Func&& func, seastar::internal::monostate) { + try { + return vanilla_futurize::invoke(std::forward(func)); + } catch (...) { + return make_exception_future(std::current_exception()); + } } template @@ -876,6 +891,25 @@ private: } } + template + static type invoke(Func&& func, Args&&... args) { + try { + return ::seastar::futurize_invoke(std::forward(func), + std::forward(args)...); + } catch (...) { + return make_exception_future(std::current_exception()); + } + } + + template + static type invoke(Func&& func, seastar::internal::monostate) { + try { + return ::seastar::futurize_invoke(std::forward(func)); + } catch (...) { + return make_exception_future(std::current_exception()); + } + } + template static type make_exception_future(Arg&& arg) { return ::crimson::errorator::make_exception_future2(std::forward(arg)); @@ -1044,16 +1078,6 @@ struct futurize>> { template [[gnu::always_inline]] - static inline type apply(Func&& func, std::tuple&& args) noexcept { - try { - return std::apply(std::forward(func), - std::forward>(args)); - } catch (...) { - return make_exception_future(std::current_exception()); - } - } - - template static inline type invoke(Func&& func, FuncArgs&&... args) noexcept { try { return func(std::forward(args)...); -- 2.39.5