max_open_files dynamic set, follow up

Summary:
Followup to make 0x40000 a TableCache constant that indicates infinite capacity
Closes https://github.com/facebook/rocksdb/pull/2247

Differential Revision: D5001349

Pulled By: lgalanis

fbshipit-source-id: ce7bd2e54b0975bb9f8680fdaa0f8bb0e7ae81a2
This commit is contained in:
Leonidas Galanis 2017-05-04 10:28:22 -07:00 committed by Facebook Github Bot
parent 6b99dbe049
commit a45e98a5b5
4 changed files with 11 additions and 7 deletions

View File

@ -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()

View File

@ -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;

View File

@ -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,

View File

@ -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(