Skip to content

Commit 0a42295

Browse files
committed
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
1 parent 06d9862 commit 0a42295

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

db/db_test.cc

+16-2
Original file line numberDiff line numberDiff line change
@@ -7832,25 +7832,39 @@ TEST(DBTest, FIFOCompactionTest) {
78327832
}
78337833

78347834
TEST(DBTest, SimpleWriteTimeoutTest) {
7835+
// Block compaction thread, which will also block the flushes because
7836+
// max_background_flushes == 0, so flushes are getting executed by the
7837+
// compaction thread
7838+
env_->SetBackgroundThreads(1, Env::LOW);
7839+
SleepingBackgroundTask sleeping_task_low;
7840+
env_->Schedule(&SleepingBackgroundTask::DoSleepTask, &sleeping_task_low,
7841+
Env::Priority::LOW);
7842+
78357843
Options options;
78367844
options.env = env_;
78377845
options.create_if_missing = true;
78387846
options.write_buffer_size = 100000;
78397847
options.max_background_flushes = 0;
78407848
options.max_write_buffer_number = 2;
7841-
options.min_write_buffer_number_to_merge = 3;
78427849
options.max_total_wal_size = std::numeric_limits<uint64_t>::max();
78437850
WriteOptions write_opt = WriteOptions();
78447851
write_opt.timeout_hint_us = 0;
78457852
DestroyAndReopen(&options);
7846-
// fill the two write buffer
7853+
// fill the two write buffers
78477854
ASSERT_OK(Put(Key(1), Key(1) + std::string(100000, 'v'), write_opt));
78487855
ASSERT_OK(Put(Key(2), Key(2) + std::string(100000, 'v'), write_opt));
7856+
// this will switch the previous memtable, but will not cause block because
7857+
// DelayWrite() is called before MakeRoomForWrite()
7858+
// TODO(icanadi) remove this as part of https://reviews.facebook.net/D23067
7859+
ASSERT_OK(Put(Key(3), Key(3), write_opt));
78497860
// As the only two write buffers are full in this moment, the third
78507861
// Put is expected to be timed-out.
78517862
write_opt.timeout_hint_us = 50;
78527863
ASSERT_TRUE(
78537864
Put(Key(3), Key(3) + std::string(100000, 'v'), write_opt).IsTimedOut());
7865+
7866+
sleeping_task_low.WakeUp();
7867+
sleeping_task_low.WaitUntilDone();
78547868
}
78557869

78567870
// Multi-threaded Timeout Test

0 commit comments

Comments
 (0)