]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
kv/RocksDB: Use for_each_substr under with_val
authorAdam C. Emerson <aemerson@redhat.com>
Mon, 20 Nov 2017 21:08:27 +0000 (16:08 -0500)
committerAdam C. Emerson <aemerson@redhat.com>
Thu, 7 Dec 2017 20:46:11 +0000 (15:46 -0500)
Minimize the number of copies we make.

Signed-off-by: Adam C. Emerson <aemerson@redhat.com>
src/kv/RocksDBStore.cc

index b8b259208a1846578f5a499e69d315993b0064b9..767b4720bb1335a98babbd9aeaceae7f2a060597 100644 (file)
@@ -342,27 +342,38 @@ int RocksDBStore::load_rocksdb_options(bool create_if_missing, rocksdb::Options&
   if (g_conf->rocksdb_separate_wal_dir) {
     opt.wal_dir = path + ".wal";
   }
-  if (g_conf->get_val<std::string>("rocksdb_db_paths").length()) {
-    list<string> paths;
-    get_str_list(g_conf->get_val<std::string>("rocksdb_db_paths"), "; \t", paths);
-    for (auto& p : paths) {
-      size_t pos = p.find(',');
-      if (pos == std::string::npos) {
-       derr << __func__ << " invalid db path item " << p << " in "
-            << g_conf->get_val<std::string>("rocksdb_db_paths") << dendl;
-       return -EINVAL;
-      }
-      string path = p.substr(0, pos);
-      string size_str = p.substr(pos + 1);
-      uint64_t size = atoll(size_str.c_str());
-      if (!size) {
-       derr << __func__ << " invalid db path item " << p << " in "
-            << g_conf->get_val<std::string>("rocksdb_db_paths") << dendl;
-       return -EINVAL;
-      }
-      opt.db_paths.push_back(rocksdb::DbPath(path, size));
-      dout(10) << __func__ << " db_path " << path << " size " << size << dendl;
-    }
+
+  // Since ceph::for_each_substr doesn't return a value and
+  // std::stoull does throw, we may as well just catch everything here.
+  try {
+    g_conf->with_val<std::string>(
+      "rocksdb_db_paths", [&opt, this](const std::string& paths) {
+       ceph::for_each_substr(
+         paths, "; \t",
+         [&paths, &opt, this](boost::string_view s) {
+           size_t pos = s.find(',');
+           if (pos == std::string::npos) {
+             derr << __func__ << " invalid db path item " << s << " in "
+                  << paths << dendl;
+             throw std::system_error(std::make_error_code(
+                                       std::errc::invalid_argument));
+           }
+           // And we have to use string because RocksDB doesn't know any better.
+           auto path = string(s.substr(0, pos));
+           auto size = std::stoull(string(s.substr(pos + 1)));
+           if (!size) {
+             derr << __func__ << " invalid db path item " << s << " in "
+                  << g_conf->get_val<std::string>("rocksdb_db_paths") << dendl;
+             throw std::system_error(std::make_error_code(
+                                       std::errc::invalid_argument));
+           }
+           opt.db_paths.push_back(rocksdb::DbPath(path, size));
+           dout(10) << __func__ << " db_path " << path << " size " << size
+                    << dendl;
+         });
+      });
+  } catch (const std::system_error& e) {
+    return -e.code().value();
   }
 
   if (g_conf->rocksdb_log_to_ceph_log) {