diff --git a/db/db_impl/db_impl.cc b/db/db_impl/db_impl.cc index 4a5dcb905..98709dd92 100644 --- a/db/db_impl/db_impl.cc +++ b/db/db_impl/db_impl.cc @@ -1081,7 +1081,6 @@ Status DBImpl::SetOptions( MutableCFOptions new_options; Status s; Status persist_options_status; - persist_options_status.PermitUncheckedError(); // Allow uninitialized access SuperVersionContext sv_context(/* create_superversion */ true); { auto db_options = GetDBOptions(); @@ -1117,9 +1116,11 @@ Status DBImpl::SetOptions( "[%s] SetOptions() succeeded", cfd->GetName().c_str()); new_options.Dump(immutable_db_options_.info_log.get()); if (!persist_options_status.ok()) { + // NOTE: WriteOptionsFile already logs on failure s = persist_options_status; } } else { + persist_options_status.PermitUncheckedError(); // less important ROCKS_LOG_WARN(immutable_db_options_.info_log, "[%s] SetOptions() failed", cfd->GetName().c_str()); } diff --git a/include/rocksdb/db.h b/include/rocksdb/db.h index 2c5217a41..778d64f08 100644 --- a/include/rocksdb/db.h +++ b/include/rocksdb/db.h @@ -1201,20 +1201,44 @@ class DB { return CompactRange(options, DefaultColumnFamily(), begin, end); } - // TODO: documentation needed - // 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. + // Dynamically change column family options or table factory options in a + // running DB, for the specified column family. Only options internally + // marked as "mutable" can be changed. Options not listed in `opts_map` will + // 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( ColumnFamilyHandle* /*column_family*/, - const std::unordered_map& /*new_options*/) { + const std::unordered_map& /*opts_map*/) { return Status::NotSupported("Not implemented"); } + // Shortcut for SetOptions on the default column family handle. virtual Status SetOptions( const std::unordered_map& 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( const std::unordered_map& new_options) = 0; @@ -1299,6 +1323,8 @@ class DB { // Get Env object from the DB virtual Env* GetEnv() const = 0; + // A shortcut for GetEnv()->->GetFileSystem().get(), possibly cached for + // efficiency. virtual FileSystem* GetFileSystem() const; // Get DB Options that we use. During the process of opening the diff --git a/options/db_options.cc b/options/db_options.cc index e6fca527d..2d3902dd8 100644 --- a/options/db_options.cc +++ b/options/db_options.cc @@ -738,11 +738,7 @@ ImmutableDBOptions::ImmutableDBOptions(const DBOptions& options) lowest_used_cache_tier(options.lowest_used_cache_tier), compaction_service(options.compaction_service) { fs = env->GetFileSystem(); - if (env != nullptr) { - clock = env->GetSystemClock().get(); - } else { - clock = SystemClock::Default().get(); - } + clock = env->GetSystemClock().get(); logger = info_log.get(); stats = statistics.get(); }