From: Kefu Chai Date: Sat, 19 Sep 2020 02:32:45 +0000 (+0800) Subject: crimson/common: discard failure of finally() block X-Git-Tag: v16.1.0~1019^2~4 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=5fb318fd25bb00fe78ceb3a98cafa30a1971e43e;p=ceph.git crimson/common: discard failure of finally() block instead of assuming that the function passed to finally() returns an erroratorized future, in this change: * s/safe_then/then_wrapped/ to handle the exception thrown by the finally function. * specialize for the case where the finally function does not return a future, and just call it. note, in seastar's implementation of finally, `finally_body` is used for specializing these two cases. * rename "future" to "result", for better readability. Signed-off-by: Kefu Chai --- diff --git a/src/crimson/common/errorator.h b/src/crimson/common/errorator.h index 16335380192c..ea0ffea4d491 100644 --- a/src/crimson/common/errorator.h +++ b/src/crimson/common/errorator.h @@ -592,23 +592,26 @@ private: return seastar::future::get0(); } - template auto finally(FuncT &&func) { - using func_result_t = std::invoke_result_t; - using func_errorator_t = get_errorator_t; - using return_errorator_t = func_errorator_t; - using futurator_t = - typename return_errorator_t::template futurize; - return this->then_wrapped( - [ func = std::forward(func) - ] (auto&& future) mutable noexcept { - return futurator_t::invoke(std::forward(func)).safe_then( - [future = std::forward(future)]() mutable { - return std::move(future); - }); - }); + [func = std::forward(func)](auto &&result) mutable noexcept { + if constexpr (seastar::is_future>::value) { + return ::seastar::futurize_invoke(std::forward(func)).then_wrapped( + [result = std::move(result)](auto&& f_res) mutable { + // TODO: f_res.failed() + f_res.discard_result(); + return std::move(result); + }); + } else { + try { + func(); + } catch (...) { + // TODO: rethrow + } + return std::move(result); + } + }); } // taking ErrorFuncOne and ErrorFuncTwo separately from ErrorFuncTail