From a057bb2a8ed75c1d9901f76f0f34fdcb6924f1c7 Mon Sep 17 00:00:00 2001 From: Yueh-Hsuan Chiang Date: Mon, 23 Mar 2015 15:05:58 -0700 Subject: [PATCH] Improve ThreadStatusSingleCompaction Summary: Improve ThreadStatusSingleCompaction in two ways: 1. Use SYNC_POINT to ensure compaction won't happen before the test finishes its "Put Phase" instead of using sleep. 2. In Put Phase, it continues until we have sufficient number of L0 files. Note that during the put phase, there won't be any compaction that consumes L0 files because of item 1. Test Plan: ./db_test --gtest_filter="*ThreadStatusSingleCompaction*" Reviewers: sdong, igor, rven Subscribers: dhruba, leveldb Differential Revision: https://reviews.facebook.net/D35727 --- db/db_impl.cc | 1 + db/db_test.cc | 12 +++++++++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/db/db_impl.cc b/db/db_impl.cc index a6761cadb..826612e3d 100644 --- a/db/db_impl.cc +++ b/db/db_impl.cc @@ -1879,6 +1879,7 @@ void DBImpl::BGWorkFlush(void* db) { void DBImpl::BGWorkCompaction(void* db) { IOSTATS_SET_THREAD_POOL_ID(Env::Priority::LOW); + TEST_SYNC_POINT("DBImpl::BGWorkCompaction"); reinterpret_cast(db)->BackgroundCallCompaction(); } diff --git a/db/db_test.cc b/db/db_test.cc index c373dca07..8624ccf88 100644 --- a/db/db_test.cc +++ b/db/db_test.cc @@ -10216,7 +10216,10 @@ TEST_F(DBTest, ThreadStatusSingleCompaction) { const int kNumL0Files = 4; options.level0_file_num_compaction_trigger = kNumL0Files; + rocksdb::SyncPoint::GetInstance()->LoadDependency({ + {"DBTest::ThreadStatusSingleCompaction:0", + "DBImpl::BGWorkCompaction"}, {"CompactionJob::Run():Start", "DBTest::ThreadStatusSingleCompaction:1"}, {"DBTest::ThreadStatusSingleCompaction:2", @@ -10228,6 +10231,7 @@ TEST_F(DBTest, ThreadStatusSingleCompaction) { DestroyAndReopen(options); Random rnd(301); + // The Put Phase. for (int file = 0; file < kNumL0Files; ++file) { for (int key = 0; key < kEntriesPerBuffer; ++key) { ASSERT_OK(Put(ToString(key + file * kEntriesPerBuffer), @@ -10235,13 +10239,15 @@ TEST_F(DBTest, ThreadStatusSingleCompaction) { } Flush(); } + // This makes sure a compaction won't be scheduled until + // we have done with the above Put Phase. + TEST_SYNC_POINT("DBTest::ThreadStatusSingleCompaction:0"); ASSERT_GE(NumTableFilesAtLevel(0), options.level0_file_num_compaction_trigger); - // wait for compaction to be scheduled - env_->SleepForMicroseconds(250000); - + // This makes sure at least one compaction is running. TEST_SYNC_POINT("DBTest::ThreadStatusSingleCompaction:1"); + if (options.enable_thread_tracking) { // expecting one single L0 to L1 compaction VerifyOperationCount(env_, ThreadStatus::OP_COMPACTION, 1);