Document SetOptions API (#9778)

Summary:
much needed

Some other minor tweaks also

Pull Request resolved: https://github.com/facebook/rocksdb/pull/9778

Test Plan: existing tests

Reviewed By: ajkr

Differential Revision: D35258195

Pulled By: pdillinger

fbshipit-source-id: 974ddafc23a540aacceb91da72e81593d818f99c
main
Peter Dillinger 3 years ago committed by Facebook GitHub Bot
parent fd66005628
commit 105d7f0c7c
  1. 3
      db/db_impl/db_impl.cc
  2. 36
      include/rocksdb/db.h
  3. 6
      options/db_options.cc

@ -1081,7 +1081,6 @@ Status DBImpl::SetOptions(
MutableCFOptions new_options; MutableCFOptions new_options;
Status s; Status s;
Status persist_options_status; Status persist_options_status;
persist_options_status.PermitUncheckedError(); // Allow uninitialized access
SuperVersionContext sv_context(/* create_superversion */ true); SuperVersionContext sv_context(/* create_superversion */ true);
{ {
auto db_options = GetDBOptions(); auto db_options = GetDBOptions();
@ -1117,9 +1116,11 @@ Status DBImpl::SetOptions(
"[%s] SetOptions() succeeded", cfd->GetName().c_str()); "[%s] SetOptions() succeeded", cfd->GetName().c_str());
new_options.Dump(immutable_db_options_.info_log.get()); new_options.Dump(immutable_db_options_.info_log.get());
if (!persist_options_status.ok()) { if (!persist_options_status.ok()) {
// NOTE: WriteOptionsFile already logs on failure
s = persist_options_status; s = persist_options_status;
} }
} else { } else {
persist_options_status.PermitUncheckedError(); // less important
ROCKS_LOG_WARN(immutable_db_options_.info_log, "[%s] SetOptions() failed", ROCKS_LOG_WARN(immutable_db_options_.info_log, "[%s] SetOptions() failed",
cfd->GetName().c_str()); cfd->GetName().c_str());
} }

@ -1201,20 +1201,44 @@ class DB {
return CompactRange(options, DefaultColumnFamily(), begin, end); return CompactRange(options, DefaultColumnFamily(), begin, end);
} }
// TODO: documentation needed // Dynamically change column family options or table factory options in a
// NOTE: SetOptions is intended only for expert users, and does not apply the // running DB, for the specified column family. Only options internally
// same sanitization to options as the standard DB::Open code path does. Use // marked as "mutable" can be changed. Options not listed in `opts_map` will
// with caution. // keep their current values. See GetColumnFamilyOptionsFromMap() in
// convenience.h for the details of `opts_map`. Not supported in LITE mode.
//
// USABILITY NOTE: SetOptions is intended only for expert users, and does
// not apply the same sanitization to options as the standard DB::Open code
// path does. Use with caution.
//
// RELIABILITY & PERFORMANCE NOTE: SetOptions is not fully stress-tested for
// reliability, and this is a slow call because a new OPTIONS file is
// serialized and persisted for each call. Use only infrequently.
//
// EXAMPLES:
// s = db->SetOptions(cfh, {{"ttl", "36000"}});
// s = db->SetOptions(cfh, {{"block_based_table_factory",
// "{prepopulate_block_cache=kDisable;}"}});
virtual Status SetOptions( virtual Status SetOptions(
ColumnFamilyHandle* /*column_family*/, ColumnFamilyHandle* /*column_family*/,
const std::unordered_map<std::string, std::string>& /*new_options*/) { const std::unordered_map<std::string, std::string>& /*opts_map*/) {
return Status::NotSupported("Not implemented"); return Status::NotSupported("Not implemented");
} }
// Shortcut for SetOptions on the default column family handle.
virtual Status SetOptions( virtual Status SetOptions(
const std::unordered_map<std::string, std::string>& new_options) { const std::unordered_map<std::string, std::string>& new_options) {
return SetOptions(DefaultColumnFamily(), new_options); return SetOptions(DefaultColumnFamily(), new_options);
} }
// Like SetOptions but for DBOptions, including the same caveats for
// usability, reliability, and performance. See GetDBOptionsFromMap() (and
// GetColumnFamilyOptionsFromMap()) in convenience.h for details on
// `opts_map`. Note supported in LITE mode.
//
// EXAMPLES:
// s = db->SetDBOptions({{"max_subcompactions", "2"}});
// s = db->SetDBOptions({{"stats_dump_period_sec", "0"},
// {"stats_persist_period_sec", "0"}});
virtual Status SetDBOptions( virtual Status SetDBOptions(
const std::unordered_map<std::string, std::string>& new_options) = 0; const std::unordered_map<std::string, std::string>& new_options) = 0;
@ -1299,6 +1323,8 @@ class DB {
// Get Env object from the DB // Get Env object from the DB
virtual Env* GetEnv() const = 0; virtual Env* GetEnv() const = 0;
// A shortcut for GetEnv()->->GetFileSystem().get(), possibly cached for
// efficiency.
virtual FileSystem* GetFileSystem() const; virtual FileSystem* GetFileSystem() const;
// Get DB Options that we use. During the process of opening the // Get DB Options that we use. During the process of opening the

@ -738,11 +738,7 @@ ImmutableDBOptions::ImmutableDBOptions(const DBOptions& options)
lowest_used_cache_tier(options.lowest_used_cache_tier), lowest_used_cache_tier(options.lowest_used_cache_tier),
compaction_service(options.compaction_service) { compaction_service(options.compaction_service) {
fs = env->GetFileSystem(); fs = env->GetFileSystem();
if (env != nullptr) { clock = env->GetSystemClock().get();
clock = env->GetSystemClock().get();
} else {
clock = SystemClock::Default().get();
}
logger = info_log.get(); logger = info_log.get();
stats = statistics.get(); stats = statistics.get();
} }

Loading…
Cancel
Save