]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
os/kv: add static method to parse RocksDB options
authorIgor Fedotov <ifedotov@suse.com>
Mon, 8 Jul 2019 14:32:10 +0000 (17:32 +0300)
committerIgor Fedotov <ifedotov@suse.com>
Wed, 11 Mar 2020 12:41:38 +0000 (15:41 +0300)
Signed-off-by: Igor Fedotov <ifedotov@suse.com>
(cherry picked from commit 518faf426ddd3142813963901d31e5675ee34eec)

src/kv/RocksDBStore.cc
src/kv/RocksDBStore.h

index 4eac1e7c30372a0cfa353cc4d2ee24d1da3b36b2..24c8384fd22c9ab9d7b65aa0b9f4a6db7976bc07 100644 (file)
@@ -241,25 +241,38 @@ int RocksDBStore::tryInterpret(const string &key, const string &val, rocksdb::Op
 }
 
 int RocksDBStore::ParseOptionsFromString(const string &opt_str, rocksdb::Options &opt)
+{
+  return ParseOptionsFromStringStatic(cct, opt_str, opt,
+    [&](const string& k, const string& v, rocksdb::Options& o) {
+      return tryInterpret(k, v, o);
+    }
+  );
+}
+
+int RocksDBStore::ParseOptionsFromStringStatic(
+  CephContext *cct,
+  const string& opt_str,
+  rocksdb::Options& opt,
+  function<int(const string&, const string&, rocksdb::Options&)> interp)
 {
   map<string, string> str_map;
   int r = get_str_map(opt_str, &str_map, ",\n;");
   if (r < 0)
     return r;
   map<string, string>::iterator it;
-  for(it = str_map.begin(); it != str_map.end(); ++it) {
+  for (it = str_map.begin(); it != str_map.end(); ++it) {
     string this_opt = it->first + "=" + it->second;
-    rocksdb::Status status = rocksdb::GetOptionsFromString(opt, this_opt , &opt); 
+    rocksdb::Status status =
+      rocksdb::GetOptionsFromString(opt, this_opt, &opt);
     if (!status.ok()) {
-      //unrecognized by rocksdb, try to interpret by ourselves.
-      r = tryInterpret(it->first, it->second, opt);
+      r = interp != nullptr ? interp(it->first, it->second, opt) : -1;
       if (r < 0) {
-       derr << status.ToString() << dendl;
-       return -EINVAL;
+        derr << status.ToString() << dendl;
+        return -EINVAL;
       }
     }
     lgeneric_dout(cct, 0) << " set rocksdb option " << it->first
-                         << " = " << it->second << dendl;
+      << " = " << it->second << dendl;
   }
   return 0;
 }
index ea7c77d3c767ed01c955ba51f2ab3b4db761a911..c6385f53663ca61e015556a86f61e534e1908e5b 100644 (file)
@@ -114,6 +114,7 @@ class RocksDBStore : public KeyValueDB {
 
   void compact_range(const string& start, const string& end);
   void compact_range_async(const string& start, const string& end);
+  int tryInterpret(const string& key, const string& val, rocksdb::Options& opt);
 
 public:
   /// compact the underlying rocksdb store
@@ -127,8 +128,12 @@ public:
     compact_range_async(string(), string());
   }
 
-  int tryInterpret(const string& key, const string& val, rocksdb::Options &opt);
-  int ParseOptionsFromString(const string& opt_str, rocksdb::Options &opt);
+  int ParseOptionsFromString(const string& opt_str, rocksdb::Options& opt);
+  static int ParseOptionsFromStringStatic(
+    CephContext* cct,
+    const string& opt_str,
+    rocksdb::Options &opt,
+    function<int(const string&, const string&, rocksdb::Options&)> interp);
   static int _test_init(const string& dir);
   int init(string options_str) override;
   /// compact rocksdb for all keys with a given prefix