From 3613d862ba0cae1ff31bd194e083f0e91bd7f7dc Mon Sep 17 00:00:00 2001 From: Yanqin Jin Date: Mon, 29 Aug 2022 14:13:06 -0700 Subject: [PATCH] print value when verification fails (#10587) Summary: When verification fails for db_stress, print more information about value read from the db and expected state. Pull Request resolved: https://github.com/facebook/rocksdb/pull/10587 Test Plan: make check ./db_stress Reviewed By: akankshamahajan15, hx235 Differential Revision: D39078511 Pulled By: riversand963 fbshipit-source-id: 77ac8ffae01fc3a9b58a02c2e7bbe141e1a18f0b --- db_stress_tool/db_stress_test_base.cc | 13 +++++++++++++ db_stress_tool/db_stress_test_base.h | 4 ++++ db_stress_tool/no_batched_ops_stress.cc | 15 ++++++++++----- 3 files changed, 27 insertions(+), 5 deletions(-) diff --git a/db_stress_tool/db_stress_test_base.cc b/db_stress_tool/db_stress_test_base.cc index 05d688400..387595831 100644 --- a/db_stress_tool/db_stress_test_base.cc +++ b/db_stress_tool/db_stress_test_base.cc @@ -411,6 +411,19 @@ void StressTest::VerificationAbort(SharedState* shared, std::string msg, int cf, shared->SetVerificationFailure(); } +void StressTest::VerificationAbort(SharedState* shared, std::string msg, int cf, + int64_t key, Slice value_from_db, + Slice value_from_expected) const { + auto key_str = Key(key); + fprintf(stderr, + "Verification failed for column family %d key %s (%" PRIi64 + "): value_from_db: %s, value_from_expected: %s, msg: %s\n", + cf, Slice(key_str).ToString(true).c_str(), key, + value_from_db.ToString(true).c_str(), + value_from_expected.ToString(true).c_str(), msg.c_str()); + shared->SetVerificationFailure(); +} + void StressTest::PrintStatistics() { if (dbstats) { fprintf(stdout, "STATISTICS:\n%s\n", dbstats->ToString().c_str()); diff --git a/db_stress_tool/db_stress_test_base.h b/db_stress_tool/db_stress_test_base.h index 3a4b8aa57..40e4e7a92 100644 --- a/db_stress_tool/db_stress_test_base.h +++ b/db_stress_tool/db_stress_test_base.h @@ -222,6 +222,10 @@ class StressTest { void VerificationAbort(SharedState* shared, std::string msg, int cf, int64_t key) const; + void VerificationAbort(SharedState* shared, std::string msg, int cf, + int64_t key, Slice value_from_db, + Slice value_from_expected) const; + void PrintEnv() const; void Open(SharedState* shared); diff --git a/db_stress_tool/no_batched_ops_stress.cc b/db_stress_tool/no_batched_ops_stress.cc index 2792cd98a..38ef31f4e 100644 --- a/db_stress_tool/no_batched_ops_stress.cc +++ b/db_stress_tool/no_batched_ops_stress.cc @@ -1264,22 +1264,27 @@ class NonBatchedOpsStressTest : public StressTest { if (s.ok()) { char value[kValueMaxLen]; if (value_base == SharedState::DELETION_SENTINEL) { - VerificationAbort(shared, "Unexpected value found", cf, key); + VerificationAbort(shared, "Unexpected value found", cf, key, + value_from_db, ""); return false; } size_t sz = GenerateValue(value_base, value, sizeof(value)); if (value_from_db.length() != sz) { - VerificationAbort(shared, "Length of value read is not equal", cf, key); + VerificationAbort(shared, "Length of value read is not equal", cf, key, + value_from_db, Slice(value, sz)); return false; } if (memcmp(value_from_db.data(), value, sz) != 0) { - VerificationAbort(shared, "Contents of value read don't match", cf, - key); + VerificationAbort(shared, "Contents of value read don't match", cf, key, + value_from_db, Slice(value, sz)); return false; } } else { if (value_base != SharedState::DELETION_SENTINEL) { - VerificationAbort(shared, "Value not found: " + s.ToString(), cf, key); + char value[kValueMaxLen]; + size_t sz = GenerateValue(value_base, value, sizeof(value)); + VerificationAbort(shared, "Value not found: " + s.ToString(), cf, key, + "", Slice(value, sz)); return false; } }