Improve obsolete_files_test (#5125)

Summary:
We see a failure of obsolete_files_test but aren't able to identify
the issue. Improve the test in following way and hope we can debug
better next time:
1. Place sync point before automatic compaction runs so race condition
   will always trigger.
2. Disable sync point before test finishes.
3. ASSERT_OK() instead of ASSERT_TRUE(status.ok())
Pull Request resolved: https://github.com/facebook/rocksdb/pull/5125

Differential Revision: D14669456

Pulled By: siying

fbshipit-source-id: dccb7648e334501ad651eb212880096eef1f4ab2
This commit is contained in:
Siying Dong 2019-03-28 13:11:53 -07:00 committed by Facebook Github Bot
parent d1edf4eced
commit 106a94af15

View File

@ -158,9 +158,6 @@ class ObsoleteFilesTest : public testing::Test {
}; };
TEST_F(ObsoleteFilesTest, RaceForObsoleteFileDeletion) { TEST_F(ObsoleteFilesTest, RaceForObsoleteFileDeletion) {
createLevel0Files(2, 50000);
CheckFileTypeCounts(options_.wal_dir, 1, 0, 0);
SyncPoint::GetInstance()->LoadDependency({ SyncPoint::GetInstance()->LoadDependency({
{"DBImpl::BackgroundCallCompaction:FoundObsoleteFiles", {"DBImpl::BackgroundCallCompaction:FoundObsoleteFiles",
"ObsoleteFilesTest::RaceForObsoleteFileDeletion:1"}, "ObsoleteFilesTest::RaceForObsoleteFileDeletion:1"},
@ -170,7 +167,7 @@ TEST_F(ObsoleteFilesTest, RaceForObsoleteFileDeletion) {
SyncPoint::GetInstance()->SetCallBack( SyncPoint::GetInstance()->SetCallBack(
"DBImpl::DeleteObsoleteFileImpl:AfterDeletion", [&](void* arg) { "DBImpl::DeleteObsoleteFileImpl:AfterDeletion", [&](void* arg) {
Status* p_status = reinterpret_cast<Status*>(arg); Status* p_status = reinterpret_cast<Status*>(arg);
ASSERT_TRUE(p_status->ok()); ASSERT_OK(*p_status);
}); });
SyncPoint::GetInstance()->SetCallBack( SyncPoint::GetInstance()->SetCallBack(
"DBImpl::CloseHelper:PendingPurgeFinished", [&](void* arg) { "DBImpl::CloseHelper:PendingPurgeFinished", [&](void* arg) {
@ -180,6 +177,9 @@ TEST_F(ObsoleteFilesTest, RaceForObsoleteFileDeletion) {
}); });
SyncPoint::GetInstance()->EnableProcessing(); SyncPoint::GetInstance()->EnableProcessing();
createLevel0Files(2, 50000);
CheckFileTypeCounts(options_.wal_dir, 1, 0, 0);
DBImpl* dbi = reinterpret_cast<DBImpl*>(db_); DBImpl* dbi = reinterpret_cast<DBImpl*>(db_);
port::Thread user_thread([&]() { port::Thread user_thread([&]() {
JobContext jobCxt(0); JobContext jobCxt(0);
@ -196,12 +196,10 @@ TEST_F(ObsoleteFilesTest, RaceForObsoleteFileDeletion) {
user_thread.join(); user_thread.join();
CloseDB(); CloseDB();
SyncPoint::GetInstance()->DisableProcessing();
} }
TEST_F(ObsoleteFilesTest, DeleteObsoleteOptionsFile) { TEST_F(ObsoleteFilesTest, DeleteObsoleteOptionsFile) {
createLevel0Files(2, 50000);
CheckFileTypeCounts(options_.wal_dir, 1, 0, 0);
std::vector<uint64_t> optsfiles_nums; std::vector<uint64_t> optsfiles_nums;
std::vector<bool> optsfiles_keep; std::vector<bool> optsfiles_keep;
SyncPoint::GetInstance()->SetCallBack( SyncPoint::GetInstance()->SetCallBack(
@ -214,6 +212,9 @@ TEST_F(ObsoleteFilesTest, DeleteObsoleteOptionsFile) {
}); });
SyncPoint::GetInstance()->EnableProcessing(); SyncPoint::GetInstance()->EnableProcessing();
createLevel0Files(2, 50000);
CheckFileTypeCounts(options_.wal_dir, 1, 0, 0);
DBImpl* dbi = static_cast<DBImpl*>(db_); DBImpl* dbi = static_cast<DBImpl*>(db_);
ASSERT_OK(dbi->DisableFileDeletions()); ASSERT_OK(dbi->DisableFileDeletions());
for (int i = 0; i != 4; ++i) { for (int i = 0; i != 4; ++i) {
@ -245,6 +246,7 @@ TEST_F(ObsoleteFilesTest, DeleteObsoleteOptionsFile) {
} }
} }
ASSERT_EQ(2, opts_file_count); ASSERT_EQ(2, opts_file_count);
SyncPoint::GetInstance()->DisableProcessing();
} }
} //namespace rocksdb } //namespace rocksdb