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

Add OptionsFormatter class and update to allow auto-logging of Options #651

Merged
merged 36 commits into from
Nov 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
6dd7279
Add a SerializeOptions method to Configurable
mrambacher Jul 31, 2023
983f42f
First Pass at serializing only options that are changed
mrambacher Aug 1, 2023
846dd2a
Revert "First Pass at serializing only options that are changed"
mrambacher Aug 8, 2023
8df931c
More use of SerializeOptions
mrambacher Aug 8, 2023
8cec611
Add an OptionsFormatter class
mrambacher Aug 25, 2023
22f6398
Add ToMap function to OptionsFormatter
mrambacher Aug 28, 2023
51ab6a1
Add ToVector to OptionsFormatter
mrambacher Aug 28, 2023
b5e5c31
Eliminate StringToMap function
mrambacher Aug 28, 2023
8a8e3cd
Move NextToken into OptionsFormatter
mrambacher Aug 28, 2023
2357795
Update convenience.h
mrambacher Aug 28, 2023
b373e4f
Fix unnecessary (extra) call
mrambacher Sep 1, 2023
a7fb784
Merge remote-tracking branch 'upstream/main' into ConfigureFromVector
mrambacher Sep 4, 2023
1698f4e
Merge remote-tracking branch 'upstream/main' into DumpOptions
mrambacher Oct 6, 2023
125dc8f
Add class comment
mrambacher Oct 13, 2023
ab1b292
Update license/copyright info
mrambacher Oct 13, 2023
70392c9
Merge remote-tracking branch 'upstream/main' into ConfigureFromVector
mrambacher Oct 13, 2023
7a80d1c
Add prefix to Serialize; Add Properties typedef
mrambacher Oct 14, 2023
bf004d9
Merge branch 'ConfigureFromVector' into DumpOptions
mrambacher Oct 14, 2023
ffa0162
Change to use Properties
mrambacher Oct 14, 2023
d940e3e
Merge remote-tracking branch 'upstream/main' into DumpOptions
mrambacher Oct 19, 2023
38cd958
Merge remote-tracking branch 'upstream/main' into DumpOptions
mrambacher Oct 19, 2023
924cfec
Update to main
mrambacher Oct 19, 2023
39d85ec
Fix test failure from merge
mrambacher Oct 19, 2023
7391214
Merge remote-tracking branch 'upstream/main' into DumpOptions
mrambacher Oct 30, 2023
2276b06
Merge remote-tracking branch 'upstream/main' into DumpOptions
mrambacher Oct 31, 2023
ffa5671
Update tests. Add history
mrambacher Nov 1, 2023
9276608
Merge remote-tracking branch 'upstream/main' into DumpOptions
mrambacher Nov 2, 2023
e266cf4
Address comments
mrambacher Nov 8, 2023
baccc69
Merge remote-tracking branch 'upstream/main' into DumpOptions
mrambacher Nov 8, 2023
c8bd2ec
Merge remote-tracking branch 'upstream/main' into DumpOptions
mrambacher Nov 9, 2023
bebed76
Add missing Speedb license
mrambacher Nov 9, 2023
8ffc265
Test adding using for fixing compilation issues
mrambacher Nov 9, 2023
d00c5d0
Merge branch 'main' into DumpOptions
ofriedma Nov 12, 2023
03df854
Merge remote-tracking branch 'upstream/main' into DumpOptions
mrambacher Nov 13, 2023
c2cf852
Add using for ToString
mrambacher Nov 13, 2023
86c1d86
Fix compiler warnings
mrambacher Nov 15, 2023
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 CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -842,6 +842,7 @@ set(SOURCES
options/customizable.cc
options/db_options.cc
options/options.cc
options/options_formatter.cc
options/options_helper.cc
options/options_parser.cc
port/mmap.cc
Expand Down
3 changes: 3 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ Based on RocksDB 8.1.1

### 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.
* Added ConfigOptions::compare_to. When set, this value causes only values that have been changed to be part of the serialized output.
* Add OptionsFormatter class. This class allows options to be serialized and configured in different formats.
* 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 (#619).

### Enhancements
Expand Down
2 changes: 2 additions & 0 deletions TARGETS
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ cpp_library_wrapper(name="rocksdb_lib", srcs=[
"options/customizable.cc",
"options/db_options.cc",
"options/options.cc",
"options/options_formatter.cc",
"options/options_helper.cc",
"options/options_parser.cc",
"port/mmap.cc",
Expand Down Expand Up @@ -519,6 +520,7 @@ cpp_library_wrapper(name="rocksdb_whole_archive_lib", srcs=[
"options/customizable.cc",
"options/db_options.cc",
"options/options.cc",
"options/options_formatter.cc",
"options/options_helper.cc",
"options/options_parser.cc",
"port/mmap.cc",
Expand Down
23 changes: 9 additions & 14 deletions db/db_options_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include "rocksdb/convenience.h"
#include "rocksdb/rate_limiter.h"
#include "rocksdb/stats_history.h"
#include "rocksdb/utilities/options_type.h"
#include "test_util/sync_point.h"
#include "test_util/testutil.h"
#include "util/random.h"
Expand All @@ -50,35 +51,30 @@ class DBOptionsTest : public DBTestBase {
SyncPoint::GetInstance()->ClearAllCallBacks();
}

std::unordered_map<std::string, std::string> GetMutableDBOptionsMap(
const DBOptions& options) {
OptionProperties GetMutableDBOptionsMap(const DBOptions& options) {
std::string options_str;
std::unordered_map<std::string, std::string> mutable_map;
OptionProperties mutable_map;
ConfigOptions config_options(options);
config_options.delimiter = "; ";

EXPECT_OK(GetStringFromMutableDBOptions(
config_options, MutableDBOptions(options), &options_str));
EXPECT_OK(StringToMap(options_str, &mutable_map));
EXPECT_OK(config_options.ToProps(options_str, &mutable_map));

return mutable_map;
}

std::unordered_map<std::string, std::string> GetMutableCFOptionsMap(
const ColumnFamilyOptions& options) {
OptionProperties GetMutableCFOptionsMap(const ColumnFamilyOptions& options) {
std::string options_str;
ConfigOptions config_options;
config_options.delimiter = "; ";

std::unordered_map<std::string, std::string> mutable_map;
OptionProperties mutable_map;
EXPECT_OK(GetStringFromMutableCFOptions(
config_options, MutableCFOptions(options), &options_str));
EXPECT_OK(StringToMap(options_str, &mutable_map));
EXPECT_OK(config_options.ToProps(options_str, &mutable_map));
return mutable_map;
}

std::unordered_map<std::string, std::string> GetRandomizedMutableCFOptionsMap(
Random* rnd) {
OptionProperties GetRandomizedMutableCFOptionsMap(Random* rnd) {
Options options = CurrentOptions();
options.env = env_;
ImmutableDBOptions db_options(options);
Expand All @@ -89,8 +85,7 @@ class DBOptionsTest : public DBTestBase {
return opt_map;
}

std::unordered_map<std::string, std::string> GetRandomizedMutableDBOptionsMap(
Random* rnd) {
OptionProperties GetRandomizedMutableDBOptionsMap(Random* rnd) {
DBOptions db_options;
test::RandomInitDBOptions(&db_options, rnd);
auto sanitized_options = SanitizeOptions(dbname_, db_options);
Expand Down
6 changes: 3 additions & 3 deletions env/env.cc
Original file line number Diff line number Diff line change
Expand Up @@ -676,10 +676,10 @@ Status Env::CreateFromString(const ConfigOptions& config_options,

Env* env = *result;
std::string id;
std::unordered_map<std::string, std::string> opt_map;
OptionProperties props;

Status status =
Customizable::GetOptionsMap(config_options, env, value, &id, &opt_map);
Customizable::GetOptionsMap(config_options, env, value, &id, &props);
if (!status.ok()) { // GetOptionsMap failed
return status;
}
Expand All @@ -695,7 +695,7 @@ Status Env::CreateFromString(const ConfigOptions& config_options,
if (config_options.ignore_unsupported_options && status.IsNotSupported()) {
status = Status::OK();
} else if (status.ok()) {
status = Customizable::ConfigureNewObject(config_options, env, opt_map);
status = Customizable::ConfigureNewObject(config_options, env, props);
}
if (status.ok()) {
guard->reset(uniq.release());
Expand Down
7 changes: 4 additions & 3 deletions include/rocksdb/configurable.h
Original file line number Diff line number Diff line change
Expand Up @@ -285,9 +285,10 @@ class Configurable {
// found.
// @return InvalidArgument if the value could not be converted to a map or
// there was or there is no id property in the map.
static Status GetOptionsMap(
const std::string& opt_value, const std::string& default_id,
std::string* id, std::unordered_map<std::string, std::string>* options);
static Status GetOptionsMap(const ConfigOptions& config_options,
const std::string& opt_value,
const std::string& default_id, std::string* id,
OptionProperties* options);

protected:
// Returns the raw pointer for the associated named option.
Expand Down
25 changes: 17 additions & 8 deletions include/rocksdb/convenience.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ namespace ROCKSDB_NAMESPACE {
class Env;
class Logger;
class ObjectRegistry;
class OptionsFormatter;
class OptionProperties;

struct ColumnFamilyOptions;
struct DBOptions;
struct Options;
Expand Down Expand Up @@ -90,6 +92,7 @@ struct ConfigOptions {
bool mutable_options_only = false;

// The separator between options when converting to a string
// This option is now deprecated and replaced by the formatter field
std::string delimiter = ";";

// Controls how to traverse options during print/match stages
Expand All @@ -107,6 +110,9 @@ struct ConfigOptions {
// The object registry to use for this options
std::shared_ptr<ObjectRegistry> registry;

// Helper class for printing and parsing options to/from strings.
std::shared_ptr<OptionsFormatter> formatter;

// If set, only changes from this reference version will be serialized.
Configurable* compare_to = nullptr;

Expand All @@ -125,9 +131,17 @@ struct ConfigOptions {
std::string ToString(const std::string& prefix,
const OptionProperties& props) const;

// Converts the string representation into name/value properties
Status ToProps(const std::string& opts_str, OptionProperties* props) const;

// Converts the vector options to a single string representation
std::string ToString(char separator,
std::string ToString(const std::string& prefix, char separator,
const std::vector<std::string>& elems) const;

// Converts the string representation into vector of elements based on the
// separator
Status ToVector(const std::string& opts_str, char separator,
std::vector<std::string>* elems) const;
};


Expand Down Expand Up @@ -420,15 +434,13 @@ Status GetStringFromDBOptions(const ConfigOptions& config_options,
std::string* opts_str);

Status GetStringFromDBOptions(std::string* opts_str,
const DBOptions& db_options,
const std::string& delimiter = "; ");
const DBOptions& db_options);

Status GetStringFromColumnFamilyOptions(const ConfigOptions& config_options,
const ColumnFamilyOptions& cf_options,
std::string* opts_str);
Status GetStringFromColumnFamilyOptions(std::string* opts_str,
const ColumnFamilyOptions& cf_options,
const std::string& delimiter = "; ");
const ColumnFamilyOptions& cf_options);
Status GetStringFromCompressionType(std::string* compression_str,
CompressionType compression_type);

Expand All @@ -454,9 +466,6 @@ Status GetOptionsFromString(const ConfigOptions& config_options,
const Options& base_options,
const std::string& opts_str, Options* new_options);

Status StringToMap(const std::string& opts_str,
std::unordered_map<std::string, std::string>* opts_map);

// Request stopping background work, if wait is true wait until it's done
void CancelAllBackgroundWork(DB* db, bool wait = false);

Expand Down
10 changes: 5 additions & 5 deletions include/rocksdb/customizable.h
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ class Customizable : public Configurable {
// options for use in potentially creating a new Customizable object (this
// method is primarily a support method for LoadSharedObject et al for new
// Customizable objects). The opt_value may be either name-value pairs
// separated by ";" (a=b; c=d), or a simple name (a). In order to create a new
// or a simple name (a). In order to create a new
// Customizable, the ID is determined by:
// - If the value is a simple name (e.g. "BlockBasedTable"), the id is this
// name;
Expand All @@ -196,10 +196,10 @@ class Customizable : public Configurable {
//
// This method returns non-OK if the ID could not be found, or if the
// opt_value could not be parsed into name-value pairs.
static Status GetOptionsMap(
const ConfigOptions& config_options, const Customizable* custom,
const std::string& opt_value, std::string* id,
std::unordered_map<std::string, std::string>* options);
static Status GetOptionsMap(const ConfigOptions& config_options,
const Customizable* custom,
const std::string& opt_value, std::string* id,
OptionProperties* options);

// Helper method to configure a new object with the supplied options.
// If the object is not null and invoke_prepare_options=true, the object
Expand Down
Loading
Loading