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).
6 #include "rocksdb/customizable.h"
8 #include "options/configurable_helper.h"
9 #include "rocksdb/convenience.h"
10 #include "rocksdb/status.h"
11 #include "util/string_util.h"
13 namespace ROCKSDB_NAMESPACE
{
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);
23 return Configurable::GetOptionName(long_name
);
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
) {
35 return Configurable::GetOption(config_options
, opt_name
, value
);
39 std::string
Customizable::SerializeOptions(const ConfigOptions
& config_options
,
40 const std::string
& prefix
) const {
43 if (!config_options
.IsShallow()) {
44 parent
= Configurable::SerializeOptions(config_options
, "");
49 result
.append(prefix
+ ConfigurableHelper::kIdPropName
+ "=" + GetId() +
50 config_options
.delimiter
);
51 result
.append(parent
);
56 #endif // ROCKSDB_LITE
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
&&
63 const Customizable
* custom
= reinterpret_cast<const Customizable
*>(other
);
64 if (GetId() != custom
->GetId()) {
65 *mismatch
= ConfigurableHelper::kIdPropName
;
67 } else if (config_options
.sanity_level
>
68 ConfigOptions::kSanityLevelLooselyCompatible
) {
70 Configurable::AreEquivalent(config_options
, other
, mismatch
);
77 } // namespace ROCKSDB_NAMESPACE