Skip to content

Commit

Permalink
Dump only changed ColumnFamilyOptions to the LOG
Browse files Browse the repository at this point in the history
  • Loading branch information
mrambacher committed Nov 19, 2023
1 parent 0d12087 commit dfaefb3
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 20 deletions.
18 changes: 9 additions & 9 deletions db/column_family.cc
Original file line number Diff line number Diff line change
Expand Up @@ -635,18 +635,18 @@ ColumnFamilyData::ColumnFamilyData(
compaction_picker_.reset(
new LevelCompactionPicker(ioptions_, &internal_comparator_));
}

if (column_family_set_->NumberOfColumnFamilies() < 10) {
{
// Dump the ColumnFamilyOptions that have changed from the default
// to the logger.
auto cf_cfg = CFOptionsAsConfigurable(ColumnFamilyOptions());
ConfigOptions config_options;
config_options.SetupForLogging(cf_cfg.get());
auto cf_str = initial_cf_options_.ToString(config_options, "Options");
ROCKS_LOG_HEADER(ioptions_.logger,
"--------------- Options for column family [%s]:\n",
name.c_str());
initial_cf_options_.Dump(ioptions_.logger);
} else {
ROCKS_LOG_INFO(ioptions_.logger,
"\t(skipping printing options of [%s])\n", name.c_str());
"--------------- Options for column family [%s]:%s\n",
name.c_str(), cf_str.c_str());
}
}

RecalculateWriteStallConditions(mutable_cf_options_);

if (cf_options.table_factory->IsInstanceOf(
Expand Down
5 changes: 4 additions & 1 deletion include/rocksdb/convenience.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ struct ConfigOptions {
// the input DBOptions. Currently constructs a new object registry.
explicit ConfigOptions(const DBOptions&);

// Initializes the ConfigOptions for use for Dump/Log formats
ConfigOptions& SetupForLogging(const Configurable* compare = nullptr);

// This enum defines the RocksDB options sanity level.
enum SanityLevel : unsigned char {
kSanityLevelNone = 0x01, // Performs no sanity check at all.
Expand Down Expand Up @@ -118,7 +121,7 @@ struct ConfigOptions {
std::shared_ptr<OptionsFormatter> formatter;

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

bool IsShallow() const { return depth == Depth::kDepthShallow; }
bool IsDetailed() const {
Expand Down
4 changes: 4 additions & 0 deletions include/rocksdb/options.h
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,8 @@ struct ColumnFamilyOptions : public AdvancedColumnFamilyOptions {
explicit ColumnFamilyOptions(const Options& options);

void Dump(Logger* log) const;
std::string ToString(ConfigOptions& config_options,
const std::string& prefix) const;
};

enum class WALRecoveryMode : char {
Expand Down Expand Up @@ -1019,6 +1021,8 @@ struct DBOptions {
explicit DBOptions(const Options& options);

void Dump(Logger* log) const;
std::string ToString(ConfigOptions& config_options,
const std::string& prefix) const;

// Allows OS to incrementally sync files to disk while they are being
// written, asynchronously, in the background. This operation can be used
Expand Down
14 changes: 14 additions & 0 deletions options/configurable.cc
Original file line number Diff line number Diff line change
Expand Up @@ -596,6 +596,20 @@ Status ConfigurableHelper::SerializeOptions(const ConfigOptions& config_options,
} else if (!single.empty()) {
props->insert_or_assign(opt_name, single);
}
} else if (compare_to != nullptr && opt_info.ShouldSerialize() &&
opt_info.IsCustomizable() && copy.IsPrintable()) {
// We decided that this object has no difference
// Check if there are any printable options we would otherwise miss
const auto custom = opt_info.AsRawPointer<Customizable>(opt_addr);
if (custom != nullptr) {
OptionProperties printable;
auto nested = OptionTypeInfo::MakePrefix(prefix, opt_name);
s = custom->SerializePrintableOptions(copy, nested, &printable);
if (s.ok() && !printable.empty()) {
props->insert_or_assign(opt_name,
copy.ToString(nested, printable));
}
}
}
}
}
Expand Down
3 changes: 1 addition & 2 deletions options/db_options.cc
Original file line number Diff line number Diff line change
Expand Up @@ -920,8 +920,7 @@ MutableDBOptions::MutableDBOptions(const DBOptions& options)

void MutableDBOptions::Dump(Logger* log) const {
ConfigOptions config_options;
config_options.depth = ConfigOptions::kDepthPrintable;
config_options.formatter = OptionsFormatter::GetLogFormatter();
config_options.SetupForLogging();
auto db_cfg = DBOptionsAsConfigurable(*this);
auto db_str = db_cfg->ToString(config_options, "Options");
ROCKS_LOG_HEADER(log, "%s", db_str.c_str());
Expand Down
23 changes: 15 additions & 8 deletions options/options.cc
Original file line number Diff line number Diff line change
Expand Up @@ -150,22 +150,29 @@ DBOptions::DBOptions(const Options& options)

void DBOptions::Dump(Logger* log) const {
ConfigOptions config_options;
config_options.depth = ConfigOptions::kDepthPrintable;
config_options.formatter = OptionsFormatter::GetLogFormatter();
auto db_cfg = DBOptionsAsConfigurable(*this);
auto db_str = db_cfg->ToString(config_options, "Options");
config_options.SetupForLogging();
auto db_str = ToString(config_options, "Options");
ROCKS_LOG_HEADER(log, "%s", db_str.c_str());
} // DBOptions::Dump

std::string DBOptions::ToString(ConfigOptions& config_options,
const std::string& prefix) const {
auto db_cfg = DBOptionsAsConfigurable(*this);
return db_cfg->ToString(config_options, prefix);
}
void ColumnFamilyOptions::Dump(Logger* log) const {
ConfigOptions config_options;
config_options.depth = ConfigOptions::kDepthPrintable;
config_options.formatter = OptionsFormatter::GetLogFormatter();
auto cf_cfg = CFOptionsAsConfigurable(*this);
auto cf_str = cf_cfg->ToString(config_options, "Options");
config_options.SetupForLogging();
auto cf_str = ToString(config_options, "Options");
ROCKS_LOG_HEADER(log, "%s", cf_str.c_str());
} // ColumnFamilyOptions::Dump

std::string ColumnFamilyOptions::ToString(ConfigOptions& config_options,
const std::string& prefix) const {
auto cf_cfg = CFOptionsAsConfigurable(*this);
return cf_cfg->ToString(config_options, prefix);
}

void Options::Dump(Logger* log) const {
DBOptions::Dump(log);
ColumnFamilyOptions::Dump(log);
Expand Down
7 changes: 7 additions & 0 deletions options/options_helper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,13 @@ ConfigOptions::ConfigOptions(const DBOptions& db_opts) : env(db_opts.env) {
registry = ObjectRegistry::NewInstance();
}

ConfigOptions& ConfigOptions::SetupForLogging(const Configurable* compare) {
depth = ConfigOptions::kDepthPrintable;
formatter = OptionsFormatter::GetLogFormatter();
compare_to = compare;
return *this;
}

std::string ConfigOptions::ToString(const std::string& prefix,
const OptionProperties& props) const {
if (formatter) {
Expand Down

0 comments on commit dfaefb3

Please sign in to comment.