From 3762ea9ac158de180e8fa368699ecd5bed82c62a Mon Sep 17 00:00:00 2001 From: Jay Zhuang Date: Thu, 30 Jun 2022 12:40:22 -0700 Subject: [PATCH] Log warning and add unittest --- db/db_impl/db_impl_open.cc | 8 +++++++- db/db_test2.cc | 39 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 1 deletion(-) diff --git a/db/db_impl/db_impl_open.cc b/db/db_impl/db_impl_open.cc index ca627a5ce96..69fd171833a 100644 --- a/db/db_impl/db_impl_open.cc +++ b/db/db_impl/db_impl_open.cc @@ -711,13 +711,19 @@ Status DBImpl::VerifySstUniqueIdInManifest() { "Verifying SST unique id between MANIFEST and SST file table properties"); Status status; for (auto cfd : *versions_->GetColumnFamilySet()) { - if (!cfd->IsDropped() && status.ok()) { + if (!cfd->IsDropped()) { auto version = cfd->current(); version->Ref(); mutex_.Unlock(); status = version->VerifySstUniqueIds(); mutex_.Lock(); version->Unref(); + if (!status.ok()) { + ROCKS_LOG_WARN(immutable_db_options_.info_log, + "SST unique id mismatch in column family \"%s\": %s", + cfd->GetName().c_str(), status.ToString().c_str()); + return status; + } } } return status; diff --git a/db/db_test2.cc b/db/db_test2.cc index a6d6813b817..6e121f3621f 100644 --- a/db/db_test2.cc +++ b/db/db_test2.cc @@ -7436,6 +7436,45 @@ TEST_F(DBTest2, SstUniqueIdVerify) { ASSERT_TRUE(s.IsCorruption()); } +TEST_F(DBTest2, SstUniqueIdVerifyMultiCFs) { + const int kNumSst = 3; + const int kLevel0Trigger = 4; + auto options = CurrentOptions(); + options.level0_file_num_compaction_trigger = kLevel0Trigger; + + CreateAndReopenWithCF({"one", "two"}, options); + + // generate good SSTs + for (int cf_num : {0, 2}) { + for (int i = 0; i < kNumSst; i++) { + for (int j = 0; j < 100; j++) { + ASSERT_OK(Put(cf_num, Key(i * 10 + j), "value")); + } + ASSERT_OK(Flush(cf_num)); + } + } + + // generate SSTs with bad unique id + SyncPoint::GetInstance()->SetCallBack( + "PropertyBlockBuilder::AddTableProperty:Start", [&](void* props_vs) { + auto props = static_cast(props_vs); + // update table property session_id to a different one + props->db_session_id = DBImpl::GenerateDbSessionId(nullptr); + }); + SyncPoint::GetInstance()->EnableProcessing(); + for (int i = 0; i < kNumSst; i++) { + for (int j = 0; j < 100; j++) { + ASSERT_OK(Put(1, Key(i * 10 + j), "value")); + } + ASSERT_OK(Flush(1)); + } + + // Reopen with verification should report corruption + options.verify_sst_unique_id_in_manifest = true; + auto s = TryReopenWithColumnFamilies({"default", "one", "two"}, options); + ASSERT_TRUE(s.IsCorruption()); +} + #ifndef ROCKSDB_LITE TEST_F(DBTest2, GetLatestSeqAndTsForKey) { Destroy(last_options_);