diff --git a/HISTORY.md b/HISTORY.md index 7382a017f..9a9ce64d3 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -5,7 +5,6 @@ ### New Features * DB::ResetStats() to reset internal stats. -* Support dynamically change `max_open_files` option via SetDBOptions() * Statistics::Reset() to reset user stats. * ldb add option --try_load_options, which will open DB with its own option file. * Support dynamically change `max_open_files` option via SetDBOptions() diff --git a/db/db_impl.cc b/db/db_impl.cc index d4f59d330..f87ea0ace 100644 --- a/db/db_impl.cc +++ b/db/db_impl.cc @@ -193,7 +193,7 @@ DBImpl::DBImpl(const DBOptions& options, const std::string& dbname) // Reserve ten files or so for other uses and give the rest to TableCache. // Give a large number for setting of "infinite" open files. const int table_cache_size = (mutable_db_options_.max_open_files == -1) - ? 0x400000 + ? TableCache::kInfiniteCapacity : mutable_db_options_.max_open_files - 10; table_cache_ = NewLRUCache(table_cache_size, immutable_db_options_.table_cache_numshardbits); @@ -582,7 +582,7 @@ Status DBImpl::SetDBOptions( write_controller_.set_max_delayed_write_rate(new_options.delayed_write_rate); table_cache_.get()->SetCapacity(new_options.max_open_files == -1 - ? 0x400000 + ? TableCache::kInfiniteCapacity : new_options.max_open_files - 10); mutable_db_options_ = new_options; diff --git a/db/table_cache.h b/db/table_cache.h index 6b5314afa..3c7165787 100644 --- a/db/table_cache.h +++ b/db/table_cache.h @@ -117,6 +117,10 @@ class TableCache { // Release the handle from a cache void ReleaseHandle(Cache::Handle* handle); + // Capacity of the backing Cache that indicates inifinite TableCache capacity. + // For example when max_open_files is -1 we set the backing Cache to this. + static const int kInfiniteCapacity = 0x400000; + private: // Build a table reader Status GetTableReader(const EnvOptions& env_options, diff --git a/db/version_set.cc b/db/version_set.cc index 99493daa9..957a88701 100644 --- a/db/version_set.cc +++ b/db/version_set.cc @@ -1123,9 +1123,9 @@ void Version::UpdateAccumulatedStats(bool update_stats) { // already been read, so MaybeInitializeFileMetaData() won't incur // any I/O cost. "max_open_files=-1" means that the table cache passed // to the VersionSet and then to the ColumnFamilySet has a size of - // 0x400000 + // TableCache::kInfiniteCapacity if (vset_->GetColumnFamilySet()->get_table_cache()->GetCapacity() == - 0x400000) { + TableCache::kInfiniteCapacity) { continue; } if (++init_count >= kMaxInitCount) { @@ -2384,7 +2384,7 @@ Status VersionSet::LogAndApply(ColumnFamilyData* column_family_data, TEST_SYNC_POINT("VersionSet::LogAndApply:WriteManifest"); if (!w.edit_list.front()->IsColumnFamilyManipulation() && this->GetColumnFamilySet()->get_table_cache()->GetCapacity() == - 0x400000) { + TableCache::kInfiniteCapacity) { // unlimited table cache. Pre-load table handle now. // Need to do it out of the mutex. builder_guard->version_builder()->LoadTableHandlers( @@ -2830,7 +2830,8 @@ Status VersionSet::Recover( assert(builders_iter != builders.end()); auto* builder = builders_iter->second->version_builder(); - if (GetColumnFamilySet()->get_table_cache()->GetCapacity() == 0x400000) { + if (GetColumnFamilySet()->get_table_cache()->GetCapacity() == + TableCache::kInfiniteCapacity) { // unlimited table cache. Pre-load table handle now. // Need to do it out of the mutex. builder->LoadTableHandlers(