Skip to content

Commit 8079dd5

Browse files
committed
Merge branch 'master' into performance
2 parents 23576d7 + 0f4a75b commit 8079dd5

File tree

4 files changed

+31
-27
lines changed

4 files changed

+31
-27
lines changed

db/compaction_picker.cc

+15-21
Original file line numberDiff line numberDiff line change
@@ -132,26 +132,16 @@ void CompactionPicker::GetRange(const std::vector<FileMetaData*>& inputs1,
132132
GetRange(all, smallest, largest);
133133
}
134134

135-
// Add more files to the inputs on "level" to make sure that
136-
// no newer version of a key is compacted to "level+1" while leaving an older
137-
// version in a "level". Otherwise, any Get() will search "level" first,
138-
// and will likely return an old/stale value for the key, since it always
139-
// searches in increasing order of level to find the value. This could
140-
// also scramble the order of merge operands. This function should be
141-
// called any time a new Compaction is created, and its inputs_[0] are
142-
// populated.
143-
//
144-
// Will set c to nullptr if it is impossible to apply this compaction.
145-
void CompactionPicker::ExpandWhileOverlapping(Compaction* c) {
135+
bool CompactionPicker::ExpandWhileOverlapping(Compaction* c) {
146136
// If inputs are empty then there is nothing to expand.
147137
if (!c || c->inputs_[0].empty()) {
148-
return;
138+
return true;
149139
}
150140

151141
// GetOverlappingInputs will always do the right thing for level-0.
152142
// So we don't need to do any expansion if level == 0.
153143
if (c->level() == 0) {
154-
return;
144+
return true;
155145
}
156146

157147
const int level = c->level();
@@ -182,9 +172,9 @@ void CompactionPicker::ExpandWhileOverlapping(Compaction* c) {
182172
&parent_index))) {
183173
c->inputs_[0].clear();
184174
c->inputs_[1].clear();
185-
delete c;
186-
c = nullptr;
175+
return false;
187176
}
177+
return true;
188178
}
189179

190180
uint64_t CompactionPicker::ExpandedCompactionByteSizeLimit(int level) {
@@ -341,8 +331,8 @@ Compaction* CompactionPicker::CompactRange(Version* version, int input_level,
341331
MaxGrandParentOverlapBytes(input_level));
342332

343333
c->inputs_[0] = inputs;
344-
ExpandWhileOverlapping(c);
345-
if (c == nullptr) {
334+
if (ExpandWhileOverlapping(c) == false) {
335+
delete c;
346336
Log(options_->info_log, "Could not compact due to expansion failure.\n");
347337
return nullptr;
348338
}
@@ -383,8 +373,10 @@ Compaction* LevelCompactionPicker::PickCompaction(Version* version) {
383373
level = version->compaction_level_[i];
384374
if ((version->compaction_score_[i] >= 1)) {
385375
c = PickCompactionBySize(version, level, version->compaction_score_[i]);
386-
ExpandWhileOverlapping(c);
387-
if (c != nullptr) {
376+
if (ExpandWhileOverlapping(c) == false) {
377+
delete c;
378+
c = nullptr;
379+
} else {
388380
break;
389381
}
390382
}
@@ -408,7 +400,9 @@ Compaction* LevelCompactionPicker::PickCompaction(Version* version) {
408400
c->inputs_[0].push_back(f);
409401
c->parent_index_ = parent_index;
410402
c->input_version_->file_to_compact_ = nullptr;
411-
ExpandWhileOverlapping(c);
403+
if (ExpandWhileOverlapping(c) == false) {
404+
return nullptr;
405+
}
412406
}
413407
}
414408
}
@@ -528,7 +522,7 @@ Compaction* LevelCompactionPicker::PickCompactionBySize(Version* version,
528522
}
529523

530524
// store where to start the iteration in the next call to PickCompaction
531-
c->input_version_->next_file_to_compact_by_size_[level] = nextIndex;
525+
version->next_file_to_compact_by_size_[level] = nextIndex;
532526

533527
return c;
534528
}

db/compaction_picker.h

+11-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,17 @@ class CompactionPicker {
8585
const std::vector<FileMetaData*>& inputs2,
8686
InternalKey* smallest, InternalKey* largest);
8787

88-
void ExpandWhileOverlapping(Compaction* c);
88+
// Add more files to the inputs on "level" to make sure that
89+
// no newer version of a key is compacted to "level+1" while leaving an older
90+
// version in a "level". Otherwise, any Get() will search "level" first,
91+
// and will likely return an old/stale value for the key, since it always
92+
// searches in increasing order of level to find the value. This could
93+
// also scramble the order of merge operands. This function should be
94+
// called any time a new Compaction is created, and its inputs_[0] are
95+
// populated.
96+
//
97+
// Will return false if it is impossible to apply this compaction.
98+
bool ExpandWhileOverlapping(Compaction* c);
8999

90100
uint64_t ExpandedCompactionByteSizeLimit(int level);
91101

db/db_impl.cc

+4-4
Original file line numberDiff line numberDiff line change
@@ -3202,7 +3202,7 @@ void DBImpl::BuildBatchGroup(Writer** last_writer,
32023202
// The goal of this formula is to gradually increase the rate at which writes
32033203
// are slowed. We also tried linear delay (r * 1000), but it seemed to do
32043204
// slightly worse. There is no other particular reason for choosing quadratic.
3205-
uint64_t DBImpl::SlowdownAmount(int n, int top, int bottom) {
3205+
uint64_t DBImpl::SlowdownAmount(int n, double bottom, double top) {
32063206
uint64_t delay;
32073207
if (n >= top) {
32083208
delay = 1000;
@@ -3214,10 +3214,10 @@ uint64_t DBImpl::SlowdownAmount(int n, int top, int bottom) {
32143214
// If we are here, we know that:
32153215
// level0_start_slowdown <= n < level0_slowdown
32163216
// since the previous two conditions are false.
3217-
float how_much =
3218-
(float) (n - bottom) /
3217+
double how_much =
3218+
(double) (n - bottom) /
32193219
(top - bottom);
3220-
delay = how_much * how_much * 1000;
3220+
delay = std::max(how_much * how_much * 1000, 100.0);
32213221
}
32223222
assert(delay <= 1000);
32233223
return delay;

db/db_impl.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ class DBImpl : public DB {
293293
Status WriteLevel0Table(autovector<MemTable*>& mems, VersionEdit* edit,
294294
uint64_t* filenumber);
295295

296-
uint64_t SlowdownAmount(int n, int top, int bottom);
296+
uint64_t SlowdownAmount(int n, double bottom, double top);
297297
// MakeRoomForWrite will return superversion_to_free through an arugment,
298298
// which the caller needs to delete. We do it because caller can delete
299299
// the superversion outside of mutex

0 commit comments

Comments
 (0)