Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change Configurable::SerializeOptions method to return a map #619

Merged
merged 14 commits into from
Oct 19, 2023
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Fix RepeatableThread to work properly with on thread start callback feature (htt

### New Features
* Non-Blocking Manual Compaction (CompactRange()) - Support non-blocking manual compactions by setting a new CompactRangeOptions option (async_completion_cb). When set, the CompactRange() call will return control to the caller immediately. The manual compaction iteslf will be performed in an internally created thread. The manual compaction will ALWAYS call the specified callback upon completion and provide the completion status (#597).
* Change the internal Configurable API SerializeOptions to return UserProperties (instead of the final string representation). Added ToString methods to the ConfigurableOptions class to complete the serialization of Options properties.

### Enhancements
* Unit Testing: Expose the disallow_trivial_move flag in the MoveFilesToLevel testing utility (#677).
Expand Down
20 changes: 16 additions & 4 deletions db/compaction/compaction_service_job.cc
Original file line number Diff line number Diff line change
Expand Up @@ -693,8 +693,8 @@ static std::unordered_map<std::string, OptionTypeInfo> cs_result_type_info = {
const auto status_obj = static_cast<const Status*>(addr);
StatusSerializationAdapter adapter(*status_obj);
std::string result;
Status s = OptionTypeInfo::SerializeType(opts, status_adapter_type_info,
&adapter, &result);
Status s = OptionTypeInfo::TypeToString(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please replace "" with "" /* prefix */ for clarity

opts, "", status_adapter_type_info, &adapter, &result);
*value = "{" + result + "}";
return s;
},
Expand Down Expand Up @@ -770,7 +770,13 @@ Status CompactionServiceInput::Write(std::string* output) {
output->append(buf, sizeof(BinaryFormatVersion));
ConfigOptions cf;
cf.invoke_prepare_options = false;
return OptionTypeInfo::SerializeType(cf, cs_input_type_info, this, output);
OptionProperties props;
Status s =
OptionTypeInfo::SerializeType(cf, "", cs_input_type_info, this, &props);
if (s.ok()) {
output->append(cf.ToString("", props) + cf.delimiter);
}
return s;
}

Status CompactionServiceResult::Read(const std::string& data_str,
Expand Down Expand Up @@ -799,7 +805,13 @@ Status CompactionServiceResult::Write(std::string* output) {
output->append(buf, sizeof(BinaryFormatVersion));
ConfigOptions cf;
cf.invoke_prepare_options = false;
return OptionTypeInfo::SerializeType(cf, cs_result_type_info, this, output);
OptionProperties props;
Status s =
OptionTypeInfo::SerializeType(cf, "", cs_result_type_info, this, &props);
if (s.ok()) {
output->append(cf.ToString("", props) + cf.delimiter);
}
return s;
}

#ifndef NDEBUG
Expand Down
2 changes: 2 additions & 0 deletions db/db_basic_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2197,6 +2197,8 @@ TEST_F(DBBasicTest, DBSetThreadAffinity) {
CPU_ZERO(&cpuset);
CPU_SET(0, &cpuset);
pthread_setaffinity_np(thr, sizeof(cpu_set_t), &cpuset);
#else
(void)thr;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a [[maybe_unused]] attribute

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is here because of a general build issue on Macs. I have fixed this in many PRs now. Hopefully one will take...

#endif
};
options.on_thread_start_callback =
Expand Down
45 changes: 20 additions & 25 deletions env/composite_env.cc
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ Status CompositeEnv::NewDirectory(const std::string& name,

namespace {
static std::unordered_map<std::string, OptionTypeInfo> env_wrapper_type_info = {
{"target",
{Customizable::kTargetPropName(),
OptionTypeInfo(0, OptionType::kUnknown, OptionVerificationType::kByName,
OptionTypeFlags::kDontSerialize)
.SetParseFunc([](const ConfigOptions& opts,
Expand Down Expand Up @@ -482,14 +482,16 @@ Status CompositeEnvWrapper::PrepareOptions(const ConfigOptions& options) {
return Env::PrepareOptions(options);
}

std::string CompositeEnvWrapper::SerializeOptions(
const ConfigOptions& config_options, const std::string& header) const {
auto options = CompositeEnv::SerializeOptions(config_options, header);
Status CompositeEnvWrapper::SerializeOptions(
const ConfigOptions& config_options, const std::string& prefix,
OptionProperties* props) const {
if (target_.env != nullptr && target_.env != Env::Default()) {
options.append("target=");
options.append(target_.env->ToString(config_options));
props->insert({kTargetPropName(),
target_.env->ToString(
config_options,
OptionTypeInfo::MakePrefix(prefix, kTargetPropName()))});
}
return options;
return CompositeEnv::SerializeOptions(config_options, prefix, props);
}

EnvWrapper::EnvWrapper(Env* t) : target_(t) {
Expand All @@ -511,24 +513,17 @@ Status EnvWrapper::PrepareOptions(const ConfigOptions& options) {
return Env::PrepareOptions(options);
}

std::string EnvWrapper::SerializeOptions(const ConfigOptions& config_options,
const std::string& header) const {
auto parent = Env::SerializeOptions(config_options, "");
if (config_options.IsShallow() || target_.env == nullptr ||
target_.env == Env::Default()) {
return parent;
} else {
std::string result = header;
if (!StartsWith(parent, OptionTypeInfo::kIdPropName())) {
result.append(OptionTypeInfo::kIdPropName()).append("=");
}
result.append(parent);
if (!EndsWith(result, config_options.delimiter)) {
result.append(config_options.delimiter);
}
result.append("target=").append(target_.env->ToString(config_options));
return result;
}
Status EnvWrapper::SerializeOptions(const ConfigOptions& config_options,
const std::string& prefix,
OptionProperties* props) const {
if (!config_options.IsShallow() && target_.env != nullptr &&
target_.env != Env::Default()) {
props->insert({kTargetPropName(),
target_.env->ToString(
config_options,
OptionTypeInfo::MakePrefix(prefix, kTargetPropName()))});
}
return Env::SerializeOptions(config_options, prefix, props);
}

} // namespace ROCKSDB_NAMESPACE
5 changes: 3 additions & 2 deletions env/composite_env_wrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -289,8 +289,9 @@ class CompositeEnvWrapper : public CompositeEnv {
const Customizable* Inner() const override { return target_.env; }

Status PrepareOptions(const ConfigOptions& options) override;
std::string SerializeOptions(const ConfigOptions& config_options,
const std::string& header) const override;
Status SerializeOptions(const ConfigOptions& config_options,
const std::string& prefix,
OptionProperties* props) const override;

// Return the target to which this Env forwards all calls
Env* env_target() const { return target_.env; }
Expand Down
47 changes: 22 additions & 25 deletions env/env.cc
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,14 @@ class LegacySystemClock : public SystemClock {
return env_->TimeToString(time);
}

std::string SerializeOptions(const ConfigOptions& /*config_options*/,
const std::string& /*prefix*/) const override {
Status SerializeOptions(const ConfigOptions& /*config_options*/,
const std::string& /*prefix*/,
OptionProperties* /*options*/) const override {
// We do not want the LegacySystemClock to appear in the serialized output.
// This clock is an internal class for those who do not implement one and
// would be part of the Env. As such, do not serialize it here.
return "";
return Status::OK();
;
}
};

Expand Down Expand Up @@ -599,13 +601,15 @@ class LegacyFileSystemWrapper : public FileSystem {
return status_to_io_status(target_->IsDirectory(path, is_dir));
}

std::string SerializeOptions(const ConfigOptions& /*config_options*/,
const std::string& /*prefix*/) const override {
Status SerializeOptions(const ConfigOptions& /*config_options*/,
const std::string& /*prefix*/,
OptionProperties* /*options*/) const override {
// We do not want the LegacyFileSystem to appear in the serialized output.
// This clock is an internal class for those who do not implement one and
// would be part of the Env. As such, do not serialize it here.
return "";
return Status::OK();
}

private:
Env* target_;
};
Expand Down Expand Up @@ -1164,7 +1168,7 @@ const std::shared_ptr<SystemClock>& Env::GetSystemClock() const {
}
namespace {
static std::unordered_map<std::string, OptionTypeInfo> sc_wrapper_type_info = {
{"target",
{Customizable::kTargetPropName(),
OptionTypeInfo::AsCustomSharedPtr<SystemClock>(
0, OptionVerificationType::kByName, OptionTypeFlags::kDontSerialize)},
};
Expand All @@ -1182,24 +1186,17 @@ Status SystemClockWrapper::PrepareOptions(const ConfigOptions& options) {
return SystemClock::PrepareOptions(options);
}

std::string SystemClockWrapper::SerializeOptions(
const ConfigOptions& config_options, const std::string& header) const {
auto parent = SystemClock::SerializeOptions(config_options, "");
if (config_options.IsShallow() || target_ == nullptr ||
target_->IsInstanceOf(SystemClock::kDefaultName())) {
return parent;
} else {
std::string result = header;
if (!StartsWith(parent, OptionTypeInfo::kIdPropName())) {
result.append(OptionTypeInfo::kIdPropName()).append("=");
}
result.append(parent);
if (!EndsWith(result, config_options.delimiter)) {
result.append(config_options.delimiter);
}
result.append("target=").append(target_->ToString(config_options));
return result;
}
Status SystemClockWrapper::SerializeOptions(const ConfigOptions& config_options,
const std::string& prefix,
OptionProperties* props) const {
if (!config_options.IsShallow() && target_ != nullptr &&
!target_->IsInstanceOf(SystemClock::kDefaultName())) {
props->insert(
{kTargetPropName(),
target_->ToString(config_options, OptionTypeInfo::MakePrefix(
prefix, kTargetPropName()))});
}
return SystemClock::SerializeOptions(config_options, prefix, props);
}

static int RegisterBuiltinSystemClocks(ObjectLibrary& library,
Expand Down
29 changes: 11 additions & 18 deletions env/file_system.cc
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ IOStatus ReadFileToString(FileSystem* fs, const std::string& fname,

namespace {
static std::unordered_map<std::string, OptionTypeInfo> fs_wrapper_type_info = {
{"target",
{Customizable::kTargetPropName(),
OptionTypeInfo::AsCustomSharedPtr<FileSystem>(
0, OptionVerificationType::kByName, OptionTypeFlags::kDontSerialize)},
};
Expand All @@ -243,24 +243,17 @@ Status FileSystemWrapper::PrepareOptions(const ConfigOptions& options) {
return FileSystem::PrepareOptions(options);
}

std::string FileSystemWrapper::SerializeOptions(
const ConfigOptions& config_options, const std::string& header) const {
auto parent = FileSystem::SerializeOptions(config_options, "");
if (config_options.IsShallow() || target_ == nullptr ||
target_->IsInstanceOf(FileSystem::kDefaultName())) {
return parent;
} else {
std::string result = header;
if (!StartsWith(parent, OptionTypeInfo::kIdPropName())) {
result.append(OptionTypeInfo::kIdPropName()).append("=");
}
result.append(parent);
if (!EndsWith(result, config_options.delimiter)) {
result.append(config_options.delimiter);
}
result.append("target=").append(target_->ToString(config_options));
return result;
Status FileSystemWrapper::SerializeOptions(const ConfigOptions& config_options,
const std::string& prefix,
OptionProperties* props) const {
if (!config_options.IsShallow() && target_ != nullptr &&
!target_->IsInstanceOf(FileSystem::kDefaultName())) {
props->insert(
{kTargetPropName(),
target_->ToString(config_options, OptionTypeInfo::MakePrefix(
prefix, kTargetPropName()))});
}
return FileSystem::SerializeOptions(config_options, prefix, props);
}

DirFsyncOptions::DirFsyncOptions() { reason = kDefault; }
Expand Down
12 changes: 10 additions & 2 deletions include/rocksdb/configurable.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
namespace ROCKSDB_NAMESPACE {
class Logger;
class ObjectRegistry;
class OptionProperties;
class OptionTypeInfo;

struct ColumnFamilyOptions;
struct ConfigOptions;
struct DBOptions;
Expand Down Expand Up @@ -343,8 +345,14 @@ class Configurable {
std::string* bad_name) const;
// Internal method to serialize options (ToString)
// Classes may override this value to change its behavior.
virtual std::string SerializeOptions(const ConfigOptions& config_options,
const std::string& header) const;
// @param config_options Controls how the options are being matched
// @param prefix A string that may be prepended to every option.
// @param props Filled with the serialized name-value pairs of the options
//
// Returns OK on success or an error status if serialized failed.
virtual Status SerializeOptions(const ConfigOptions& config_options,
const std::string& prefix,
OptionProperties* props) const;

// Given a name (e.g. rocksdb.my.type.opt), returns the short name (opt)
virtual std::string GetOptionName(const std::string& long_name) const;
Expand Down
10 changes: 9 additions & 1 deletion include/rocksdb/convenience.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ namespace ROCKSDB_NAMESPACE {
class Env;
class Logger;
class ObjectRegistry;

class OptionProperties;
struct ColumnFamilyOptions;
struct DBOptions;
struct Options;
Expand Down Expand Up @@ -103,6 +103,14 @@ struct ConfigOptions {
bool IsCheckEnabled(SanityLevel level) const {
return (level > SanityLevel::kSanityLevelNone && level <= sanity_level);
}

// Converts the properties to a single string representation
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How are these 2 methods related to this PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ToString methods are used to convert the UserProperties to their string representation. Prior, the code was "hard-coded" in the various places

std::string ToString(const std::string& prefix,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please document the use / purpose of the prefix parameter. However, I see that the prefix parameter is not actually in use in the implementation. Is it really needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The prefix parameter was there previously (called header) and is needed by some of the formats (like Log format)

const OptionProperties& props) const;

// Converts the vector options to a single string representation
std::string ToString(char separator,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why does the 2nd ToString() receive a separator while the 1st uses delimiter?

const std::vector<std::string>& elems) const;
};


Expand Down
7 changes: 5 additions & 2 deletions include/rocksdb/customizable.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ class Customizable : public Configurable {
public:
~Customizable() override {}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please document the purpose of this method / constants

constexpr static const char* kTargetPropName() { return "target"; }

// Returns the name of this class of Customizable
virtual const char* Name() const = 0;

Expand Down Expand Up @@ -222,8 +224,9 @@ class Customizable : public Configurable {
virtual const char* NickName() const { return ""; }
// Given a name (e.g. rocksdb.my.type.opt), returns the short name (opt)
std::string GetOptionName(const std::string& long_name) const override;
std::string SerializeOptions(const ConfigOptions& options,
const std::string& prefix) const override;
Status SerializeOptions(const ConfigOptions& config_options,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please document this method.
Specifically, please describe prefix & return value (props)

const std::string& prefix,
OptionProperties* props) const override;
};

} // namespace ROCKSDB_NAMESPACE
5 changes: 3 additions & 2 deletions include/rocksdb/env.h
Original file line number Diff line number Diff line change
Expand Up @@ -1658,8 +1658,9 @@ class EnvWrapper : public Env {
target_.env->SanitizeEnvOptions(env_opts);
}
Status PrepareOptions(const ConfigOptions& options) override;
std::string SerializeOptions(const ConfigOptions& config_options,
const std::string& header) const override;
Status SerializeOptions(const ConfigOptions& config_options,
const std::string& prefix,
OptionProperties* props) const override;

private:
Target target_;
Expand Down
5 changes: 3 additions & 2 deletions include/rocksdb/file_system.h
Original file line number Diff line number Diff line change
Expand Up @@ -1528,8 +1528,9 @@ class FileSystemWrapper : public FileSystem {

const Customizable* Inner() const override { return target_.get(); }
Status PrepareOptions(const ConfigOptions& options) override;
std::string SerializeOptions(const ConfigOptions& config_options,
const std::string& header) const override;
Status SerializeOptions(const ConfigOptions& config_options,
const std::string& prefix,
OptionProperties* props) const override;

virtual IOStatus Poll(std::vector<void*>& io_handles,
size_t min_completions) override {
Expand Down
5 changes: 3 additions & 2 deletions include/rocksdb/system_clock.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,9 @@ class SystemClockWrapper : public SystemClock {
}

Status PrepareOptions(const ConfigOptions& options) override;
std::string SerializeOptions(const ConfigOptions& config_options,
const std::string& header) const override;
Status SerializeOptions(const ConfigOptions& config_options,
const std::string& prefix,
OptionProperties* props) const override;
const Customizable* Inner() const override { return target_.get(); }

protected:
Expand Down
Loading
Loading