From d75b6f060361580f6f3cef519f027e02bda38f82 Mon Sep 17 00:00:00 2001 From: Kefu Chai Date: Fri, 7 Aug 2020 16:54:04 +0800 Subject: [PATCH] crimson/common: read conf file in async otherwise seastar's stall detector could complain, if the task takes too long to complete. Signed-off-by: Kefu Chai --- src/crimson/common/config_proxy.cc | 52 +++++++++++++++++++++++++----- 1 file changed, 44 insertions(+), 8 deletions(-) diff --git a/src/crimson/common/config_proxy.cc b/src/crimson/common/config_proxy.cc index 39d6842d78bc8..520909d70c43e 100644 --- a/src/crimson/common/config_proxy.cc +++ b/src/crimson/common/config_proxy.cc @@ -3,6 +3,20 @@ #include "config_proxy.h" +#if __has_include() +#include +#else +#include +#endif + +#include "crimson/common/buffer_io.h" + +#if defined(__cpp_lib_filesystem) +namespace fs = std::filesystem; +#elif defined(__cpp_lib_experimental_filesystem) +namespace fs = std::experimental::filesystem; +#endif + namespace crimson::common { ConfigProxy::ConfigProxy(const EntityName& name, std::string_view cluster) @@ -48,14 +62,36 @@ void ConfigProxy::show_config(ceph::Formatter* f) const { seastar::future<> ConfigProxy::parse_config_files(const std::string& conf_files) { - return do_change([this, conf_files](ConfigValues& values) { - const char* conf_file_paths = - conf_files.empty() ? nullptr : conf_files.c_str(); - get_config().parse_config_files(values, - obs_mgr, - conf_file_paths, - &std::cerr, - CODE_ENVIRONMENT_DAEMON); + auto conffile_paths = + get_config().get_conffile_paths(*values, + conf_files.empty() ? nullptr : conf_files.c_str(), + &std::cerr, + CODE_ENVIRONMENT_DAEMON); + return seastar::do_with(std::move(conffile_paths), [this] (auto& paths) { + return seastar::repeat([path=paths.begin(), e=paths.end(), this]() mutable { + if (path == e) { + // tried all conffile, none of them works + return seastar::make_ready_future( + seastar::stop_iteration::yes); + } + return crimson::read_file(*path++).then([this](auto&& buf) { + return do_change([buf=std::move(buf), this](ConfigValues& values) { + if (get_config().parse_buffer(values, obs_mgr, buf.get(), buf.size(), &std::cerr)) { + throw std::invalid_argument("parse error"); + } + }).then([] { + // this one works! + return seastar::make_ready_future( + seastar::stop_iteration::yes); + }); + }).handle_exception_type([] (const fs::filesystem_error&) { + return seastar::make_ready_future( + seastar::stop_iteration::no); + }).handle_exception_type([] (const std::invalid_argument&) { + return seastar::make_ready_future( + seastar::stop_iteration::no); + }); + }); }); } -- 2.39.5