Avoid sleep in DBTest.GroupCommitTest to fix flakiness

Summary:
DBTest.GroupCommitTest would often fail when run under valgrind because its sleeps were insufficient to guarantee a group commit had multiple entries. Instead we can use sync point to force a leader to wait until a non-leader thread has enqueued its work, thus guaranteeing a leader can do group commit work for multiple threads.
Closes https://github.com/facebook/rocksdb/pull/3883

Differential Revision: D8079429

Pulled By: ajkr

fbshipit-source-id: 61dc50fad29d2c85547842f681288de60fa29049
main
Andrew Kryczka 7 years ago committed by Facebook Github Bot
parent fcb31016e9
commit 7db721b9a6
  1. 1
      db/db_impl_write.cc
  2. 14
      db/db_test.cc
  3. 1
      db/write_thread.cc

@ -211,6 +211,7 @@ Status DBImpl::WriteImpl(const WriteOptions& write_options,
// and protects against concurrent loggers and concurrent writes // and protects against concurrent loggers and concurrent writes
// into memtables // into memtables
TEST_SYNC_POINT("DBImpl::WriteImpl:BeforeLeaderEnters");
last_batch_group_size_ = last_batch_group_size_ =
write_thread_.EnterAsBatchGroupLeader(&w, &write_group); write_thread_.EnterAsBatchGroupLeader(&w, &write_group);

@ -2153,10 +2153,14 @@ TEST_F(DBTest, GroupCommitTest) {
do { do {
Options options = CurrentOptions(); Options options = CurrentOptions();
options.env = env_; options.env = env_;
env_->log_write_slowdown_.store(100);
options.statistics = rocksdb::CreateDBStatistics(); options.statistics = rocksdb::CreateDBStatistics();
Reopen(options); Reopen(options);
rocksdb::SyncPoint::GetInstance()->LoadDependency(
{{"WriteThread::JoinBatchGroup:BeganWaiting",
"DBImpl::WriteImpl:BeforeLeaderEnters"}});
rocksdb::SyncPoint::GetInstance()->EnableProcessing();
// Start threads // Start threads
GCThread thread[kGCNumThreads]; GCThread thread[kGCNumThreads];
for (int id = 0; id < kGCNumThreads; id++) { for (int id = 0; id < kGCNumThreads; id++) {
@ -2165,13 +2169,7 @@ TEST_F(DBTest, GroupCommitTest) {
thread[id].done = false; thread[id].done = false;
env_->StartThread(GCThreadBody, &thread[id]); env_->StartThread(GCThreadBody, &thread[id]);
} }
env_->WaitForJoin();
for (int id = 0; id < kGCNumThreads; id++) {
while (thread[id].done == false) {
env_->SleepForMicroseconds(100000);
}
}
env_->log_write_slowdown_.store(0);
ASSERT_GT(TestGetTickerCount(options, WRITE_DONE_BY_OTHER), 0); ASSERT_GT(TestGetTickerCount(options, WRITE_DONE_BY_OTHER), 0);

@ -318,6 +318,7 @@ void WriteThread::JoinBatchGroup(Writer* w) {
* 3.2) an existing memtable writer group leader tell us to finish memtable * 3.2) an existing memtable writer group leader tell us to finish memtable
* writes in parallel. * writes in parallel.
*/ */
TEST_SYNC_POINT_CALLBACK("WriteThread::JoinBatchGroup:BeganWaiting", w);
AwaitState(w, STATE_GROUP_LEADER | STATE_MEMTABLE_WRITER_LEADER | AwaitState(w, STATE_GROUP_LEADER | STATE_MEMTABLE_WRITER_LEADER |
STATE_PARALLEL_MEMTABLE_WRITER | STATE_COMPLETED, STATE_PARALLEL_MEMTABLE_WRITER | STATE_COMPLETED,
&jbg_ctx); &jbg_ctx);

Loading…
Cancel
Save