From 094d37b68252c86ea8f8cc8527fd9216b0142d02 Mon Sep 17 00:00:00 2001 From: Jay Huh Date: Mon, 14 Oct 2024 13:21:51 -0700 Subject: [PATCH] Test for ParanoidFileCheck --- db/compaction/compaction_service_test.cc | 63 ++++++++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/db/compaction/compaction_service_test.cc b/db/compaction/compaction_service_test.cc index 656e45ecd1..c18e6ce364 100644 --- a/db/compaction/compaction_service_test.cc +++ b/db/compaction/compaction_service_test.cc @@ -452,6 +452,69 @@ TEST_F(CompactionServiceTest, CorruptedOutput) { ASSERT_TRUE(result.stats.is_remote_compaction); } +TEST_F(CompactionServiceTest, CorruptedOutputParanoidFileCheck) { + for (bool paranoid_file_check_enabled : {false, true}) { + SCOPED_TRACE("paranoid_file_check_enabled=" + + std::to_string(paranoid_file_check_enabled)); + + Options options = CurrentOptions(); + Destroy(options); + options.disable_auto_compactions = true; + options.paranoid_file_checks = paranoid_file_check_enabled; + ReopenWithCompactionService(&options); + GenerateTestData(); + + auto my_cs = GetCompactionService(); + + std::string start_str = Key(15); + std::string end_str = Key(45); + Slice start(start_str); + Slice end(end_str); + uint64_t comp_num = my_cs->GetCompactionNum(); + + ROCKSDB_NAMESPACE::SyncPoint::GetInstance()->SetCallBack( + "CompactionServiceCompactionJob::Run:0", [&](void* arg) { + CompactionServiceResult* compaction_result = + *(static_cast(arg)); + ASSERT_TRUE(compaction_result != nullptr && + !compaction_result->output_files.empty()); + // Corrupt files here + for (const auto& output_file : compaction_result->output_files) { + std::string file_name = + compaction_result->output_path + "/" + output_file.file_name; + + // Corrupt very small range of bytes. This corruption is so small + // that this isn't caught by default light-weight check + ASSERT_OK(test::CorruptFile(env_, file_name, 0, 1, + false /* verifyChecksum */)); + } + }); + SyncPoint::GetInstance()->EnableProcessing(); + + Status s = db_->CompactRange(CompactRangeOptions(), &start, &end); + if (paranoid_file_check_enabled) { + ASSERT_NOK(s); + ASSERT_TRUE(s.IsCorruption()); + } else { + // CompactRange() goes through if paranoid file check is not enabled + ASSERT_OK(s); + } + + ASSERT_GE(my_cs->GetCompactionNum(), comp_num + 1); + + SyncPoint::GetInstance()->DisableProcessing(); + SyncPoint::GetInstance()->ClearAllCallBacks(); + + // On the worker side, the compaction is considered success + // Verification is done on the primary side + CompactionServiceResult result; + my_cs->GetResult(&result); + ASSERT_OK(result.status); + ASSERT_TRUE(result.stats.is_manual_compaction); + ASSERT_TRUE(result.stats.is_remote_compaction); + } +} + TEST_F(CompactionServiceTest, TruncatedOutput) { Options options = CurrentOptions(); options.disable_auto_compactions = true;