diff --git a/db/column_family.cc b/db/column_family.cc index eb2f21e9f..b10b800b4 100644 --- a/db/column_family.cc +++ b/db/column_family.cc @@ -326,6 +326,13 @@ void ColumnFamilyData::RecalculateWriteStallConditions() { "[%s] Stopping writes because we have %d immutable memtables " "(waiting for flush)", name_.c_str(), imm()->size()); + } else if (current_->NumLevelFiles(0) >= + options_.level0_stop_writes_trigger) { + write_controller_token_ = write_controller->GetStopToken(); + internal_stats_->AddCFStats(InternalStats::LEVEL0_NUM_FILES, 1); + Log(options_.info_log, + "[%s] Stopping writes because we have %d level-0 files", + name_.c_str(), current_->NumLevelFiles(0)); } else if (options_.level0_slowdown_writes_trigger >= 0 && current_->NumLevelFiles(0) >= options_.level0_slowdown_writes_trigger) { @@ -338,13 +345,6 @@ void ColumnFamilyData::RecalculateWriteStallConditions() { "[%s] Stalling writes because we have %d level-0 files (%" PRIu64 "us)", name_.c_str(), current_->NumLevelFiles(0), slowdown); - } else if (current_->NumLevelFiles(0) >= - options_.level0_stop_writes_trigger) { - write_controller_token_ = write_controller->GetStopToken(); - internal_stats_->AddCFStats(InternalStats::LEVEL0_NUM_FILES, 1); - Log(options_.info_log, - "[%s] Stopping writes because we have %d level-0 files", - name_.c_str(), current_->NumLevelFiles(0)); } else if (options_.hard_rate_limit > 1.0 && score > options_.hard_rate_limit) { uint64_t kHardLimitSlowdown = 1000; diff --git a/db/db_test.cc b/db/db_test.cc index 140e87078..96f7e208a 100644 --- a/db/db_test.cc +++ b/db/db_test.cc @@ -7827,6 +7827,26 @@ TEST(DBTest, MTRandomTimeoutTest) { } } +TEST(DBTest, Level0StopWritesTest) { + Options options = CurrentOptions(); + options.level0_slowdown_writes_trigger = 2; + options.level0_stop_writes_trigger = 4; + options.disable_auto_compactions = 4; + options.max_mem_compaction_level = 0; + Reopen(&options); + + // create 4 level0 tables + for (int i = 0; i < 4; ++i) { + Put("a", "b"); + Flush(); + } + + WriteOptions woptions; + woptions.timeout_hint_us = 30 * 1000; // 30 ms + Status s = Put("a", "b", woptions); + ASSERT_TRUE(s.IsTimedOut()); +} + } // anonymous namespace /*