diff --git a/HISTORY.md b/HISTORY.md index cac6c864f..6e9a6578d 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -11,6 +11,7 @@ ### New Features * Added support for pipelined & parallel compression optimization for `BlockBasedTableBuilder`. This optimization makes block building, block compression and block appending a pipeline, and uses multiple threads to accelerate block compression. Users can set `CompressionOptions::parallel_threads` greater than 1 to enable compression parallelism. * Provide an allocator for memkind to be used with block cache. This is to work with memory technologies (Intel DCPMM is one such technology currently available) that require different libraries for allocation and management (such as PMDK and memkind). The high capacities available make it possible to provision large caches (up to several TBs in size) beyond what is achievable with DRAM. +* Option `max_background_flushes` can be set dynamically using DB::SetDBOptions(). ### Bug Fixes * Fix a bug when making options.bottommost_compression, options.compression_opts and options.bottommost_compression_opts dynamically changeable: the modified values are not written to option files or returned back to users when being queried. diff --git a/db/db_impl/db_impl.cc b/db/db_impl/db_impl.cc index 8b4e21c6c..cb033c0cf 100644 --- a/db/db_impl/db_impl.cc +++ b/db/db_impl/db_impl.cc @@ -1010,12 +1010,12 @@ Status DBImpl::SetDBOptions( } if (s.ok()) { const BGJobLimits current_bg_job_limits = - GetBGJobLimits(immutable_db_options_.max_background_flushes, + GetBGJobLimits(mutable_db_options_.max_background_flushes, mutable_db_options_.max_background_compactions, mutable_db_options_.max_background_jobs, /* parallelize_compactions */ true); const BGJobLimits new_bg_job_limits = GetBGJobLimits( - immutable_db_options_.max_background_flushes, + new_options.max_background_flushes, new_options.max_background_compactions, new_options.max_background_jobs, /* parallelize_compactions */ true); diff --git a/db/db_impl/db_impl_compaction_flush.cc b/db/db_impl/db_impl_compaction_flush.cc index 9a6a3c8f2..b772a97ce 100644 --- a/db/db_impl/db_impl_compaction_flush.cc +++ b/db/db_impl/db_impl_compaction_flush.cc @@ -2030,7 +2030,7 @@ void DBImpl::MaybeScheduleFlushOrCompaction() { DBImpl::BGJobLimits DBImpl::GetBGJobLimits() const { mutex_.AssertHeld(); - return GetBGJobLimits(immutable_db_options_.max_background_flushes, + return GetBGJobLimits(mutable_db_options_.max_background_flushes, mutable_db_options_.max_background_compactions, mutable_db_options_.max_background_jobs, write_controller_.NeedSpeedupCompaction()); diff --git a/db/db_options_test.cc b/db/db_options_test.cc index fc404f112..76ee27224 100644 --- a/db/db_options_test.cc +++ b/db/db_options_test.cc @@ -402,6 +402,20 @@ TEST_F(DBOptionsTest, SetBackgroundCompactionThreads) { ASSERT_EQ(3, dbfull()->TEST_BGCompactionsAllowed()); } +TEST_F(DBOptionsTest, SetBackgroundFlushThreads) { + Options options; + options.create_if_missing = true; + options.max_background_flushes = 1; + options.env = env_; + Reopen(options); + ASSERT_EQ(1, dbfull()->TEST_BGFlushesAllowed()); + ASSERT_EQ(1, env_->GetBackgroundThreads(Env::Priority::HIGH)); + ASSERT_OK(dbfull()->SetDBOptions({{"max_background_flushes", "3"}})); + ASSERT_EQ(3, env_->GetBackgroundThreads(Env::Priority::HIGH)); + ASSERT_EQ(3, dbfull()->TEST_BGFlushesAllowed()); +} + + TEST_F(DBOptionsTest, SetBackgroundJobs) { Options options; options.create_if_missing = true; diff --git a/options/db_options.cc b/options/db_options.cc index 227525fc7..d6b95b5c3 100644 --- a/options/db_options.cc +++ b/options/db_options.cc @@ -133,7 +133,8 @@ std::unordered_map offsetof(struct MutableDBOptions, base_background_compactions)}}, {"max_background_flushes", {offsetof(struct DBOptions, max_background_flushes), OptionType::kInt, - OptionVerificationType::kNormal, OptionTypeFlags::kNone, 0}}, + OptionVerificationType::kNormal, OptionTypeFlags::kMutable, + offsetof(struct MutableDBOptions, max_background_flushes)}}, {"max_file_opening_threads", {offsetof(struct DBOptions, max_file_opening_threads), OptionType::kInt, OptionVerificationType::kNormal, @@ -354,7 +355,6 @@ ImmutableDBOptions::ImmutableDBOptions(const DBOptions& options) db_log_dir(options.db_log_dir), wal_dir(options.wal_dir), max_subcompactions(options.max_subcompactions), - max_background_flushes(options.max_background_flushes), max_log_file_size(options.max_log_file_size), log_file_time_to_roll(options.log_file_time_to_roll), keep_log_file_num(options.keep_log_file_num), @@ -472,8 +472,6 @@ void ImmutableDBOptions::Dump(Logger* log) const { ROCKS_LOG_HEADER(log, " Options.max_subcompactions: %" PRIu32, max_subcompactions); - ROCKS_LOG_HEADER(log, " Options.max_background_flushes: %d", - max_background_flushes); ROCKS_LOG_HEADER(log, " Options.WAL_ttl_seconds: %" PRIu64, wal_ttl_seconds); @@ -587,7 +585,8 @@ MutableDBOptions::MutableDBOptions() bytes_per_sync(0), wal_bytes_per_sync(0), strict_bytes_per_sync(false), - compaction_readahead_size(0) {} + compaction_readahead_size(0), + max_background_flushes(-1) {} MutableDBOptions::MutableDBOptions(const DBOptions& options) : max_background_jobs(options.max_background_jobs), @@ -606,7 +605,8 @@ MutableDBOptions::MutableDBOptions(const DBOptions& options) bytes_per_sync(options.bytes_per_sync), wal_bytes_per_sync(options.wal_bytes_per_sync), strict_bytes_per_sync(options.strict_bytes_per_sync), - compaction_readahead_size(options.compaction_readahead_size) {} + compaction_readahead_size(options.compaction_readahead_size), + max_background_flushes(options.max_background_flushes) {} void MutableDBOptions::Dump(Logger* log) const { ROCKS_LOG_HEADER(log, " Options.max_background_jobs: %d", @@ -647,6 +647,8 @@ void MutableDBOptions::Dump(Logger* log) const { ROCKS_LOG_HEADER(log, " Options.compaction_readahead_size: %" ROCKSDB_PRIszt, compaction_readahead_size); + ROCKS_LOG_HEADER(log, " Options.max_background_flushes: %d", + max_background_flushes); } } // namespace ROCKSDB_NAMESPACE diff --git a/options/db_options.h b/options/db_options.h index 66945f912..dc1120740 100644 --- a/options/db_options.h +++ b/options/db_options.h @@ -35,7 +35,6 @@ struct ImmutableDBOptions { std::string db_log_dir; std::string wal_dir; uint32_t max_subcompactions; - int max_background_flushes; size_t max_log_file_size; size_t log_file_time_to_roll; size_t keep_log_file_num; @@ -114,6 +113,7 @@ struct MutableDBOptions { uint64_t wal_bytes_per_sync; bool strict_bytes_per_sync; size_t compaction_readahead_size; + int max_background_flushes; }; } // namespace ROCKSDB_NAMESPACE diff --git a/options/options_helper.cc b/options/options_helper.cc index d844888bf..e86925d5a 100644 --- a/options/options_helper.cc +++ b/options/options_helper.cc @@ -61,7 +61,7 @@ DBOptions BuildDBOptions(const ImmutableDBOptions& immutable_db_options, options.wal_bytes_per_sync = mutable_db_options.wal_bytes_per_sync; options.strict_bytes_per_sync = mutable_db_options.strict_bytes_per_sync; options.max_subcompactions = immutable_db_options.max_subcompactions; - options.max_background_flushes = immutable_db_options.max_background_flushes; + options.max_background_flushes = mutable_db_options.max_background_flushes; options.max_log_file_size = immutable_db_options.max_log_file_size; options.log_file_time_to_roll = immutable_db_options.log_file_time_to_roll; options.keep_log_file_num = immutable_db_options.keep_log_file_num;