account for L0 size in estimated compaction bytes

Summary:
also changed the `>` in the comparison against `level0_file_num_compaction_trigger` into a `>=` since exactly `level0_file_num_compaction_trigger` can trigger a compaction from L0.
Closes https://github.com/facebook/rocksdb/pull/2179

Differential Revision: D4915772

Pulled By: ajkr

fbshipit-source-id: e38fec6253de6f9a40e61734615c6670d84038aa
main
Andrew Kryczka 8 years ago committed by Facebook Github Bot
parent 0fae3f5dd3
commit 3a8a848a55
  1. 2
      db/compaction_picker_test.cc
  2. 2
      db/db_properties_test.cc
  3. 17
      db/version_set.cc

@ -952,7 +952,7 @@ TEST_F(CompactionPickerTest, NotScheduleL1IfL0WithHigherPri3) {
TEST_F(CompactionPickerTest, EstimateCompactionBytesNeeded1) { TEST_F(CompactionPickerTest, EstimateCompactionBytesNeeded1) {
int num_levels = ioptions_.num_levels; int num_levels = ioptions_.num_levels;
ioptions_.level_compaction_dynamic_level_bytes = false; ioptions_.level_compaction_dynamic_level_bytes = false;
mutable_cf_options_.level0_file_num_compaction_trigger = 3; mutable_cf_options_.level0_file_num_compaction_trigger = 4;
mutable_cf_options_.max_bytes_for_level_base = 1000; mutable_cf_options_.max_bytes_for_level_base = 1000;
mutable_cf_options_.max_bytes_for_level_multiplier = 10; mutable_cf_options_.max_bytes_for_level_multiplier = 10;
NewVersionStorage(num_levels, kCompactionStyleLevel); NewVersionStorage(num_levels, kCompactionStyleLevel);

@ -913,7 +913,7 @@ TEST_F(DBPropertiesTest, EstimatePendingCompBytes) {
Flush(); Flush();
ASSERT_TRUE(dbfull()->GetIntProperty( ASSERT_TRUE(dbfull()->GetIntProperty(
"rocksdb.estimate-pending-compaction-bytes", &int_num)); "rocksdb.estimate-pending-compaction-bytes", &int_num));
ASSERT_EQ(int_num, 0U); ASSERT_GT(int_num, 0U);
ASSERT_OK(dbfull()->Put(writeOpt, "k3", big_value)); ASSERT_OK(dbfull()->Put(writeOpt, "k3", big_value));
Flush(); Flush();

@ -1230,15 +1230,18 @@ void VersionStorageInfo::EstimateCompactionBytesNeeded(
// accumulated bytes. // accumulated bytes.
uint64_t bytes_compact_to_next_level = 0; uint64_t bytes_compact_to_next_level = 0;
uint64_t level_size = 0;
for (auto* f : files_[0]) {
level_size += f->fd.GetFileSize();
}
// Level 0 // Level 0
bool level0_compact_triggered = false; bool level0_compact_triggered = false;
if (static_cast<int>(files_[0].size()) > if (static_cast<int>(files_[0].size()) >=
mutable_cf_options.level0_file_num_compaction_trigger) { mutable_cf_options.level0_file_num_compaction_trigger ||
level_size >= mutable_cf_options.max_bytes_for_level_base) {
level0_compact_triggered = true; level0_compact_triggered = true;
for (auto* f : files_[0]) { estimated_compaction_needed_bytes_ = level_size;
bytes_compact_to_next_level += f->fd.GetFileSize(); bytes_compact_to_next_level = level_size;
}
estimated_compaction_needed_bytes_ = bytes_compact_to_next_level;
} else { } else {
estimated_compaction_needed_bytes_ = 0; estimated_compaction_needed_bytes_ = 0;
} }
@ -1246,7 +1249,7 @@ void VersionStorageInfo::EstimateCompactionBytesNeeded(
// Level 1 and up. // Level 1 and up.
uint64_t bytes_next_level = 0; uint64_t bytes_next_level = 0;
for (int level = base_level(); level <= MaxInputLevel(); level++) { for (int level = base_level(); level <= MaxInputLevel(); level++) {
uint64_t level_size = 0; level_size = 0;
if (bytes_next_level > 0) { if (bytes_next_level > 0) {
#ifndef NDEBUG #ifndef NDEBUG
uint64_t level_size2 = 0; uint64_t level_size2 = 0;

Loading…
Cancel
Save