From 85399b14f78e0917b82e42c390e7c825122c6f46 Mon Sep 17 00:00:00 2001 From: Levi Tamasi Date: Tue, 11 Oct 2022 14:40:25 -0700 Subject: [PATCH] Consider wide columns when checksumming in the stress tests (#10788) Summary: There are two places in the stress test code where we compute the CRC for a range of KVs for the purposes of checking consistency, namely in the CF consistency test (to make sure CFs contain the same data), and when performing `CompactRange` (to make sure the pre- and post-compaction states are equivalent). The patch extends the logic so that wide columns are also considered in both cases. Pull Request resolved: https://github.com/facebook/rocksdb/pull/10788 Test Plan: Tested using some simple blackbox crash test runs. Reviewed By: riversand963 Differential Revision: D40191134 Pulled By: ltamasi fbshipit-source-id: 542c21cac9077c6d225780deb210319bb5eee955 --- db_stress_tool/cf_consistency_stress.cc | 8 ++++++++ db_stress_tool/db_stress_test_base.cc | 21 +++++++++++++++++---- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/db_stress_tool/cf_consistency_stress.cc b/db_stress_tool/cf_consistency_stress.cc index 5fd4d7e5a..27c722284 100644 --- a/db_stress_tool/cf_consistency_stress.cc +++ b/db_stress_tool/cf_consistency_stress.cc @@ -510,11 +510,19 @@ class CfConsistencyStressTest : public StressTest { const auto checksum_column_family = [](Iterator* iter, uint32_t* checksum) -> Status { assert(nullptr != checksum); + uint32_t ret = 0; for (iter->SeekToFirst(); iter->Valid(); iter->Next()) { ret = crc32c::Extend(ret, iter->key().data(), iter->key().size()); ret = crc32c::Extend(ret, iter->value().data(), iter->value().size()); + + for (const auto& column : iter->columns()) { + ret = crc32c::Extend(ret, column.name().data(), column.name().size()); + ret = + crc32c::Extend(ret, column.value().data(), column.value().size()); + } } + *checksum = ret; return iter->status(); }; diff --git a/db_stress_tool/db_stress_test_base.cc b/db_stress_tool/db_stress_test_base.cc index 4f2ce8b92..fdf6f8e42 100644 --- a/db_stress_tool/db_stress_test_base.cc +++ b/db_stress_tool/db_stress_test_base.cc @@ -2285,8 +2285,6 @@ uint32_t StressTest::GetRangeHash(ThreadState* thread, const Snapshot* snapshot, ColumnFamilyHandle* column_family, const Slice& start_key, const Slice& end_key) { - const std::string kCrcCalculatorSepearator = ";"; - uint32_t crc = 0; // This `ReadOptions` is for validation purposes. Ignore // `FLAGS_rate_limit_user_ops` to avoid slowing any validation. ReadOptions ro; @@ -2299,15 +2297,29 @@ uint32_t StressTest::GetRangeHash(ThreadState* thread, const Snapshot* snapshot, ts = ts_str; ro.timestamp = &ts; } + std::unique_ptr it(db_->NewIterator(ro, column_family)); + + constexpr char kCrcCalculatorSepearator = ';'; + + uint32_t crc = 0; + for (it->Seek(start_key); it->Valid() && options_.comparator->Compare(it->key(), end_key) <= 0; it->Next()) { crc = crc32c::Extend(crc, it->key().data(), it->key().size()); - crc = crc32c::Extend(crc, kCrcCalculatorSepearator.data(), 1); + crc = crc32c::Extend(crc, &kCrcCalculatorSepearator, sizeof(char)); crc = crc32c::Extend(crc, it->value().data(), it->value().size()); - crc = crc32c::Extend(crc, kCrcCalculatorSepearator.data(), 1); + crc = crc32c::Extend(crc, &kCrcCalculatorSepearator, sizeof(char)); + + for (const auto& column : it->columns()) { + crc = crc32c::Extend(crc, column.name().data(), column.name().size()); + crc = crc32c::Extend(crc, &kCrcCalculatorSepearator, sizeof(char)); + crc = crc32c::Extend(crc, column.value().data(), column.value().size()); + crc = crc32c::Extend(crc, &kCrcCalculatorSepearator, sizeof(char)); + } } + if (!it->status().ok()) { fprintf(stderr, "Iterator non-OK when calculating range CRC: %s\n", it->status().ToString().c_str()); @@ -2315,6 +2327,7 @@ uint32_t StressTest::GetRangeHash(ThreadState* thread, const Snapshot* snapshot, // Fail fast to preserve the DB state. thread->shared->SetVerificationFailure(); } + return crc; }