]> git.apps.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>
Tue, 26 Nov 2019 18:28:02 +0000 (21:28 +0300)
Signed-off-by: Igor Fedotov <ifedotov@suse.com>
src/kv/RocksDBStore.cc
src/kv/RocksDBStore.h

index 03a265bc34fc65605a41c0597e82b7ded7b17eed..2cb8cf791a970c735951222059c1c1d252596eaf 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 254f6f3afda505c56aeed8e5b930e79cac477408..68b3fe93b763bc2b347db751c40e0eb60d84ec78 100644 (file)
@@ -115,6 +115,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
@@ -126,8 +127,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