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

Conversation

mrambacher
Copy link
Contributor

@mrambacher mrambacher commented Aug 1, 2023

Changes the Configurable::SerializeOptions method to return a map of options. This map is equivalent to the input map for the ConfigureOptions method. By returning a map, it will be possible in the future to add different output representations (such as DUMP, JSON, Properties) formats to the string representations of the configurable objects.

This PR is a first-step to a few additional changes. For example, is a gateway to:

  • Only serializing changed options;
  • Allowing different string formats for options (e.g. Default, Properties, Log/Dump, JSON, etc)

@mrambacher mrambacher added the enhancement New feature or request label Aug 1, 2023
@mrambacher mrambacher self-assigned this Aug 1, 2023
@udi-speedb
Copy link
Contributor

@mrambacher - Please update when you have completed updating the branch. I will review only once the branch has all of the contents you intend to merge. Thanks

@mrambacher mrambacher changed the title WIP: Allow Serialization of only options that have changed Change the Configurable::SerializeOptions method to return a map Aug 9, 2023
@mrambacher mrambacher changed the title Change the Configurable::SerializeOptions method to return a map Change Configurable::SerializeOptions method to return a map Aug 11, 2023
@mrambacher
Copy link
Contributor Author

A couple of points:

  1. I do not know if it is better to return/use a map or a vector of string pairs. Vectors may be slightly easier to work with in some cases and more efficient. They would also preserve the order if that is important (whereas map order is more random). The Configure methods currently use maps (but perhaps an internal wrapper method should be created to use the same type)
  2. I was going to create something like a typedef/using for the map but could not decide on a good name. Feel free to suggest something as the current type is pretty long to type...

@udi-speedb
Copy link
Contributor

@mrambacher - Do you still have content to push to the PR?

@mrambacher
Copy link
Contributor Author

@mrambacher - Do you still have content to push to the PR?

@udi-speedb I just made an update to use the Properties type. I am done now pending comments.

@udi-speedb
Copy link
Contributor

I may be missing something, but how is the addition of the prefix parameter part of this PR?

@@ -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

@@ -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)

@@ -23,6 +23,8 @@ struct ColumnFamilyOptions;
struct DBOptions;
struct Options;

using Properties = std::unordered_map<std::string, std::string>;
Copy link
Contributor

Choose a reason for hiding this comment

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

The type name (Properties) is too general to be part of the 'rocksdb' namespace. It should be under a more contrained scope or namespace.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Renamed to OptionProperties

@@ -103,6 +105,12 @@ struct ConfigOptions {
bool IsCheckEnabled(SanityLevel level) const {
return (level > SanityLevel::kSanityLevelNone && level <= sanity_level);
}
// Converts the properties to a single string representation
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)

options/options_helper.cc Outdated Show resolved Hide resolved
include/rocksdb/configurable.h Outdated Show resolved Hide resolved
options/cf_options.cc Outdated Show resolved Hide resolved
return OptionTypeInfo::SerializeType(
config_options, cf_mutable_options_type_info, &mutable_opts, opt_string);
return OptionTypeInfo::TypeToString(config_options, "",
cf_mutable_options_type_info,
Copy link
Contributor

Choose a reason for hiding this comment

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

Why have you moved to TypeToString()?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

SerializeType now returns a OptionsProperties set. TypeToString converts the Properties to a string. There were multiple places that needed this functionality, so I put it under a single API/method.

@@ -103,6 +105,12 @@ 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

@@ -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...

@udi-speedb
Copy link
Contributor

And please update HISTORY.md and add the license text in all the existing files you have modified.

Also added/updated comments.
@mrambacher
Copy link
Contributor Author

I may be missing something, but how is the addition of the prefix parameter part of this PR?

The prefix parameter to SerializeOptions was there before -- the variable was called "header"

@udi-speedb udi-speedb self-requested a review October 17, 2023 18:43
@Yuval-Ariel Yuval-Ariel merged commit dc39061 into speedb-io:main Oct 19, 2023
1 check passed
udi-speedb pushed a commit that referenced this pull request Nov 23, 2023
Changes the Configurable::SerializeOptions method to return a map of options. This map is equivalent to the input map for the ConfigureOptions method. By returning a map, it will be possible in the future to add different output representations (such as DUMP, JSON, Properties) formats to the string representations of the configurable objects.

This PR is a first-step to a few additional changes. For example, is a gateway to:

Only serializing changed options;
Allowing different string formats for options (e.g. Default, Properties, Log/Dump, JSON, etc)
udi-speedb pushed a commit that referenced this pull request Dec 6, 2023
Changes the Configurable::SerializeOptions method to return a map of options. This map is equivalent to the input map for the ConfigureOptions method. By returning a map, it will be possible in the future to add different output representations (such as DUMP, JSON, Properties) formats to the string representations of the configurable objects.

This PR is a first-step to a few additional changes. For example, is a gateway to:

Only serializing changed options;
Allowing different string formats for options (e.g. Default, Properties, Log/Dump, JSON, etc)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants