From: Igor Fedotov Date: Mon, 8 Jul 2019 14:32:10 +0000 (+0300) Subject: os/kv: add static method to parse RocksDB options X-Git-Tag: v14.2.10~148^2~5 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=b66560d3b274eb3108a6a2abb14fb80fcbb34461;p=ceph.git os/kv: add static method to parse RocksDB options Signed-off-by: Igor Fedotov (cherry picked from commit 518faf426ddd3142813963901d31e5675ee34eec) --- diff --git a/src/kv/RocksDBStore.cc b/src/kv/RocksDBStore.cc index 4eac1e7c3037..24c8384fd22c 100644 --- a/src/kv/RocksDBStore.cc +++ b/src/kv/RocksDBStore.cc @@ -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 interp) { map str_map; int r = get_str_map(opt_str, &str_map, ",\n;"); if (r < 0) return r; map::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; } diff --git a/src/kv/RocksDBStore.h b/src/kv/RocksDBStore.h index ea7c77d3c767..c6385f53663c 100644 --- a/src/kv/RocksDBStore.h +++ b/src/kv/RocksDBStore.h @@ -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 interp); static int _test_init(const string& dir); int init(string options_str) override; /// compact rocksdb for all keys with a given prefix