]> git.proxmox.com Git - ceph.git/blob - ceph/src/rocksdb/options/customizable.cc
import quincy beta 17.1.0
[ceph.git] / ceph / src / rocksdb / options / customizable.cc
1 // Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
2 // This source code is licensed under both the GPLv2 (found in the
3 // COPYING file in the root directory) and Apache 2.0 License
4 // (found in the LICENSE.Apache file in the root directory).
5
6 #include "rocksdb/customizable.h"
7
8 #include "options/configurable_helper.h"
9 #include "rocksdb/convenience.h"
10 #include "rocksdb/status.h"
11 #include "util/string_util.h"
12
13 namespace ROCKSDB_NAMESPACE {
14
15 std::string Customizable::GetOptionName(const std::string& long_name) const {
16 const std::string& name = Name();
17 size_t name_len = name.size();
18 if (long_name.size() > name_len + 1 &&
19 long_name.compare(0, name_len, name) == 0 &&
20 long_name.at(name_len) == '.') {
21 return long_name.substr(name_len + 1);
22 } else {
23 return Configurable::GetOptionName(long_name);
24 }
25 }
26
27 #ifndef ROCKSDB_LITE
28 Status Customizable::GetOption(const ConfigOptions& config_options,
29 const std::string& opt_name,
30 std::string* value) const {
31 if (opt_name == ConfigurableHelper::kIdPropName) {
32 *value = GetId();
33 return Status::OK();
34 } else {
35 return Configurable::GetOption(config_options, opt_name, value);
36 }
37 }
38
39 std::string Customizable::SerializeOptions(const ConfigOptions& config_options,
40 const std::string& prefix) const {
41 std::string result;
42 std::string parent;
43 if (!config_options.IsShallow()) {
44 parent = Configurable::SerializeOptions(config_options, "");
45 }
46 if (parent.empty()) {
47 result = GetId();
48 } else {
49 result.append(prefix + ConfigurableHelper::kIdPropName + "=" + GetId() +
50 config_options.delimiter);
51 result.append(parent);
52 }
53 return result;
54 }
55
56 #endif // ROCKSDB_LITE
57
58 bool Customizable::AreEquivalent(const ConfigOptions& config_options,
59 const Configurable* other,
60 std::string* mismatch) const {
61 if (config_options.sanity_level > ConfigOptions::kSanityLevelNone &&
62 this != other) {
63 const Customizable* custom = reinterpret_cast<const Customizable*>(other);
64 if (GetId() != custom->GetId()) {
65 *mismatch = ConfigurableHelper::kIdPropName;
66 return false;
67 } else if (config_options.sanity_level >
68 ConfigOptions::kSanityLevelLooselyCompatible) {
69 bool matches =
70 Configurable::AreEquivalent(config_options, other, mismatch);
71 return matches;
72 }
73 }
74 return true;
75 }
76
77 } // namespace ROCKSDB_NAMESPACE