]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
crimson/common: read conf file in async
authorKefu Chai <kchai@redhat.com>
Fri, 7 Aug 2020 08:54:04 +0000 (16:54 +0800)
committerKefu Chai <kchai@redhat.com>
Mon, 10 Aug 2020 14:51:17 +0000 (22:51 +0800)
otherwise seastar's stall detector could complain, if the task takes too
long to complete.

Signed-off-by: Kefu Chai <kchai@redhat.com>
src/crimson/common/config_proxy.cc

index 39d6842d78bc8c372b821a857741eda07bc52d1f..520909d70c43e826505f6116b51687b4ac6bbbcc 100644 (file)
@@ -3,6 +3,20 @@
 
 #include "config_proxy.h"
 
+#if __has_include(<filesystem>)
+#include <filesystem>
+#else
+#include <experimental/filesystem>
+#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>(
+          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>(
+            seastar::stop_iteration::yes);
+        });
+      }).handle_exception_type([] (const fs::filesystem_error&) {
+        return seastar::make_ready_future<seastar::stop_iteration>(
+          seastar::stop_iteration::no);
+      }).handle_exception_type([] (const std::invalid_argument&) {
+        return seastar::make_ready_future<seastar::stop_iteration>(
+         seastar::stop_iteration::no);
+      });
+    });
   });
 }