From 2d57828d0ecb55eaf7a90b8f13568884d48938c7 Mon Sep 17 00:00:00 2001 From: Igor Canadi Date: Mon, 8 Sep 2014 15:23:58 -0700 Subject: [PATCH] Check stop level trigger-0 before slowdown level-0 trigger Summary: ... Test Plan: Can't repro the test failure, but let's see what jenkins says Reviewers: zagfox, sdong, ljin Reviewed By: sdong, ljin Subscribers: leveldb Differential Revision: https://reviews.facebook.net/D23061 --- db/column_family.cc | 14 +++++++------- db/db_test.cc | 20 ++++++++++++++++++++ 2 files changed, 27 insertions(+), 7 deletions(-) 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 /*