From 0a42295a248742fe5058492095d4ea59e543aa34 Mon Sep 17 00:00:00 2001 From: Igor Canadi Date: Tue, 9 Sep 2014 11:50:05 -0700 Subject: [PATCH] Fix SimpleWriteTimeoutTest Summary: In column family's SanitizeOptions() [1], we make sure that min_write_buffer_number_to_merge is normal value. However, this test depended on the fact that setting min_write_buffer_number_to_merge to be bigger than max_write_buffer_number will cause a deadlock. I'm not sure how it worked before. This diff fixes it by scheduling sleeping background task, which will actually block any attempts of flushing. [1] https://github.com/facebook/rocksdb/blob/master/db/column_family.cc#L104 Test Plan: the test works now Reviewers: yhchiang, sdong, ljin Reviewed By: ljin Subscribers: leveldb Differential Revision: https://reviews.facebook.net/D23103 --- db/db_test.cc | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/db/db_test.cc b/db/db_test.cc index 92d623468..2c06c241d 100644 --- a/db/db_test.cc +++ b/db/db_test.cc @@ -7832,25 +7832,39 @@ TEST(DBTest, FIFOCompactionTest) { } TEST(DBTest, SimpleWriteTimeoutTest) { + // Block compaction thread, which will also block the flushes because + // max_background_flushes == 0, so flushes are getting executed by the + // compaction thread + env_->SetBackgroundThreads(1, Env::LOW); + SleepingBackgroundTask sleeping_task_low; + env_->Schedule(&SleepingBackgroundTask::DoSleepTask, &sleeping_task_low, + Env::Priority::LOW); + Options options; options.env = env_; options.create_if_missing = true; options.write_buffer_size = 100000; options.max_background_flushes = 0; options.max_write_buffer_number = 2; - options.min_write_buffer_number_to_merge = 3; options.max_total_wal_size = std::numeric_limits::max(); WriteOptions write_opt = WriteOptions(); write_opt.timeout_hint_us = 0; DestroyAndReopen(&options); - // fill the two write buffer + // fill the two write buffers ASSERT_OK(Put(Key(1), Key(1) + std::string(100000, 'v'), write_opt)); ASSERT_OK(Put(Key(2), Key(2) + std::string(100000, 'v'), write_opt)); + // this will switch the previous memtable, but will not cause block because + // DelayWrite() is called before MakeRoomForWrite() + // TODO(icanadi) remove this as part of https://reviews.facebook.net/D23067 + ASSERT_OK(Put(Key(3), Key(3), write_opt)); // As the only two write buffers are full in this moment, the third // Put is expected to be timed-out. write_opt.timeout_hint_us = 50; ASSERT_TRUE( Put(Key(3), Key(3) + std::string(100000, 'v'), write_opt).IsTimedOut()); + + sleeping_task_low.WakeUp(); + sleeping_task_low.WaitUntilDone(); } // Multi-threaded Timeout Test