Skip to content

Commit 65a8a52

Browse files
committed
Decrease reliance on VersionSet::NumberLevels()
Summary: With column families VersionSet will not have a constant number of levels (each CF can have different options), so we'll need to eliminate call to VersionSet::NumberLevels() This diff decreases number of callsites, but we're not there yet. It associates number of levels with Version (each version is associated with single CF) instead of VersionSet. I have also slightly changed how VersionSet keeps track of manifest size. This diff also modifies constructor of Compaction such that it takes input_version and automatically Ref()s it. Before this was done outside of constructor. In next diffs I will continue to decrease number of callsites of VersionSet::NumberLevels() and also references to current_ Test Plan: make check Reviewers: haobo, dhruba, kailiu, sdong Reviewed By: sdong Differential Revision: https://reviews.facebook.net/D15171
1 parent c8f1622 commit 65a8a52

6 files changed

+153
-166
lines changed

db/db_impl.cc

+14-12
Original file line numberDiff line numberDiff line change
@@ -1316,7 +1316,7 @@ int DBImpl::FindMinimumEmptyLevelFitting(int level) {
13161316
int minimum_level = level;
13171317
for (int i = level - 1; i > 0; --i) {
13181318
// stop if level i is not empty
1319-
if (versions_->NumLevelFiles(i) > 0) break;
1319+
if (versions_->current()->NumLevelFiles(i) > 0) break;
13201320

13211321
// stop if level i is too small (cannot fit the level files)
13221322
if (versions_->MaxBytesForLevel(i) < versions_->NumLevelBytes(level)) break;
@@ -2233,7 +2233,7 @@ Status DBImpl::DoCompactionWork(CompactionState* compact,
22332233
compact->compaction->Summary(scratch, sizeof(scratch));
22342234
Log(options_.info_log, "Compaction start summary: %s\n", scratch);
22352235

2236-
assert(versions_->NumLevelFiles(compact->compaction->level()) > 0);
2236+
assert(versions_->current()->NumLevelFiles(compact->compaction->level()) > 0);
22372237
assert(compact->builder == nullptr);
22382238
assert(!compact->outfile);
22392239

@@ -3207,7 +3207,7 @@ Status DBImpl::MakeRoomForWrite(bool force,
32073207
{
32083208
StopWatch sw(env_, options_.statistics.get(), STALL_L0_SLOWDOWN_COUNT);
32093209
env_->SleepForMicroseconds(
3210-
SlowdownAmount(versions_->NumLevelFiles(0),
3210+
SlowdownAmount(versions_->current()->NumLevelFiles(0),
32113211
options_.level0_slowdown_writes_trigger,
32123212
options_.level0_stop_writes_trigger)
32133213
);
@@ -3242,7 +3242,7 @@ Status DBImpl::MakeRoomForWrite(bool force,
32423242
STALL_MEMTABLE_COMPACTION_MICROS, stall);
32433243
stall_memtable_compaction_ += stall;
32443244
stall_memtable_compaction_count_++;
3245-
} else if (versions_->NumLevelFiles(0) >=
3245+
} else if (versions_->current()->NumLevelFiles(0) >=
32463246
options_.level0_stop_writes_trigger) {
32473247
// There are too many level-0 files.
32483248
DelayLoggingAndReset();
@@ -3372,6 +3372,7 @@ bool DBImpl::GetProperty(const Slice& property, std::string* value) {
33723372
value->clear();
33733373

33743374
MutexLock l(&mutex_);
3375+
Version* current = versions_->current();
33753376
Slice in = property;
33763377
Slice prefix("rocksdb.");
33773378
if (!in.starts_with(prefix)) return false;
@@ -3386,7 +3387,7 @@ bool DBImpl::GetProperty(const Slice& property, std::string* value) {
33863387
} else {
33873388
char buf[100];
33883389
snprintf(buf, sizeof(buf), "%d",
3389-
versions_->NumLevelFiles(static_cast<int>(level)));
3390+
current->NumLevelFiles(static_cast<int>(level)));
33903391
*value = buf;
33913392
return true;
33923393
}
@@ -3401,7 +3402,7 @@ bool DBImpl::GetProperty(const Slice& property, std::string* value) {
34013402
snprintf(buf, sizeof(buf),
34023403
"%3d %8d %8.0f\n",
34033404
level,
3404-
versions_->NumLevelFiles(level),
3405+
current->NumLevelFiles(level),
34053406
versions_->NumLevelBytes(level) / 1048576.0);
34063407
value->append(buf);
34073408
}
@@ -3446,7 +3447,7 @@ bool DBImpl::GetProperty(const Slice& property, std::string* value) {
34463447
);
34473448
value->append(buf);
34483449
for (int level = 0; level < NumberLevels(); level++) {
3449-
int files = versions_->NumLevelFiles(level);
3450+
int files = current->NumLevelFiles(level);
34503451
if (stats_[level].micros > 0 || files > 0) {
34513452
int64_t bytes_read = stats_[level].bytes_readn +
34523453
stats_[level].bytes_readnp1;
@@ -3728,7 +3729,7 @@ Status DBImpl::DeleteFile(std::string name) {
37283729
// This is to make sure that any deletion tombstones are not
37293730
// lost. Check that the level passed is the last level.
37303731
for (int i = level + 1; i < maxlevel; i++) {
3731-
if (versions_->NumLevelFiles(i) != 0) {
3732+
if (versions_->current()->NumLevelFiles(i) != 0) {
37323733
Log(options_.info_log,
37333734
"DeleteFile %s FAILED. File not in last level\n", name.c_str());
37343735
return Status::InvalidArgument("File not in last level");
@@ -3853,12 +3854,11 @@ Status DB::Open(const Options& options, const std::string& dbname, DB** dbptr) {
38533854
impl->MaybeScheduleLogDBDeployStats();
38543855
}
38553856
}
3856-
impl->mutex_.Unlock();
38573857

3858-
if (impl->options_.compaction_style == kCompactionStyleUniversal) {
3859-
int num_files;
3858+
if (s.ok() && impl->options_.compaction_style == kCompactionStyleUniversal) {
3859+
Version* current = impl->versions_->current();
38603860
for (int i = 1; i < impl->NumberLevels(); i++) {
3861-
num_files = impl->versions_->NumLevelFiles(i);
3861+
int num_files = current->NumLevelFiles(i);
38623862
if (num_files > 0) {
38633863
s = Status::InvalidArgument("Not all files are at level 0. Cannot "
38643864
"open with universal compaction style.");
@@ -3867,6 +3867,8 @@ Status DB::Open(const Options& options, const std::string& dbname, DB** dbptr) {
38673867
}
38683868
}
38693869

3870+
impl->mutex_.Unlock();
3871+
38703872
if (s.ok()) {
38713873
*dbptr = impl;
38723874
} else {

db/db_stats_logger.cc

+3-2
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,9 @@ void DBImpl::LogDBDeployStats() {
6565

6666
uint64_t file_total_size = 0;
6767
uint32_t file_total_num = 0;
68-
for (int i = 0; i < versions_->NumberLevels(); i++) {
69-
file_total_num += versions_->NumLevelFiles(i);
68+
Version* current = versions_->current();
69+
for (int i = 0; i < current->NumberLevels(); i++) {
70+
file_total_num += current->NumLevelFiles(i);
7071
file_total_size += versions_->NumLevelBytes(i);
7172
}
7273

0 commit comments

Comments
 (0)