diff --git a/db/column_family_test.cc b/db/column_family_test.cc index fddbaf518..1fe7601b1 100644 --- a/db/column_family_test.cc +++ b/db/column_family_test.cc @@ -2542,6 +2542,36 @@ TEST_F(ColumnFamilyTest, CompactionSpeedupTwoColumnFamilies) { cfd->RecalculateWriteStallConditions(mutable_cf_options); ASSERT_EQ(2, dbfull()->BGCompactionsAllowed()); } + +TEST_F(ColumnFamilyTest, LogSyncConflictFlush) { + Open(); + CreateColumnFamiliesAndReopen({"one", "two"}); + + Put(0, "", ""); + Put(1, "foo", "bar"); + + rocksdb::SyncPoint::GetInstance()->LoadDependency( + {{"DBImpl::SyncWAL:BeforeMarkLogsSynced:1", + "ColumnFamilyTest::LogSyncConflictFlush:1"}, + {"ColumnFamilyTest::LogSyncConflictFlush:2", + "DBImpl::SyncWAL:BeforeMarkLogsSynced:2"}}); + + rocksdb::SyncPoint::GetInstance()->EnableProcessing(); + + std::thread thread([&] { db_->SyncWAL(); }); + + TEST_SYNC_POINT("ColumnFamilyTest::LogSyncConflictFlush:1"); + Flush(1); + Put(1, "foo", "bar"); + Flush(1); + + TEST_SYNC_POINT("ColumnFamilyTest::LogSyncConflictFlush:2"); + + thread.join(); + + rocksdb::SyncPoint::GetInstance()->DisableProcessing(); + Close(); +} } // namespace rocksdb int main(int argc, char** argv) { diff --git a/db/db_impl.cc b/db/db_impl.cc index d29df88c1..683006388 100644 --- a/db/db_impl.cc +++ b/db/db_impl.cc @@ -2202,6 +2202,9 @@ Status DBImpl::SyncWAL() { status = directories_.GetWalDir()->Fsync(); } + TEST_SYNC_POINT("DBImpl::SyncWAL:BeforeMarkLogsSynced:1"); + TEST_SYNC_POINT("DBImpl::SyncWAL:BeforeMarkLogsSynced:2"); + { InstrumentedMutexLock l(&mutex_); MarkLogsSynced(current_log_number, need_log_dir_sync, status); @@ -2229,7 +2232,8 @@ void DBImpl::MarkLogsSynced( ++it; } } - assert(logs_.empty() || (logs_.size() == 1 && !logs_[0].getting_synced)); + assert(logs_.empty() || logs_[0].number > up_to || + (logs_.size() == 1 && !logs_[0].getting_synced)); log_sync_cv_.SignalAll(); }