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
main
Yanqin Jin 2 years ago committed by Facebook GitHub Bot
parent c5afbbfe4b
commit 3613d862ba
  1. 13
      db_stress_tool/db_stress_test_base.cc
  2. 4
      db_stress_tool/db_stress_test_base.h
  3. 15
      db_stress_tool/no_batched_ops_stress.cc

@ -411,6 +411,19 @@ void StressTest::VerificationAbort(SharedState* shared, std::string msg, int cf,
shared->SetVerificationFailure(); 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() { void StressTest::PrintStatistics() {
if (dbstats) { if (dbstats) {
fprintf(stdout, "STATISTICS:\n%s\n", dbstats->ToString().c_str()); fprintf(stdout, "STATISTICS:\n%s\n", dbstats->ToString().c_str());

@ -222,6 +222,10 @@ class StressTest {
void VerificationAbort(SharedState* shared, std::string msg, int cf, void VerificationAbort(SharedState* shared, std::string msg, int cf,
int64_t key) const; 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 PrintEnv() const;
void Open(SharedState* shared); void Open(SharedState* shared);

@ -1264,22 +1264,27 @@ class NonBatchedOpsStressTest : public StressTest {
if (s.ok()) { if (s.ok()) {
char value[kValueMaxLen]; char value[kValueMaxLen];
if (value_base == SharedState::DELETION_SENTINEL) { 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; return false;
} }
size_t sz = GenerateValue(value_base, value, sizeof(value)); size_t sz = GenerateValue(value_base, value, sizeof(value));
if (value_from_db.length() != sz) { 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; return false;
} }
if (memcmp(value_from_db.data(), value, sz) != 0) { if (memcmp(value_from_db.data(), value, sz) != 0) {
VerificationAbort(shared, "Contents of value read don't match", cf, VerificationAbort(shared, "Contents of value read don't match", cf, key,
key); value_from_db, Slice(value, sz));
return false; return false;
} }
} else { } else {
if (value_base != SharedState::DELETION_SENTINEL) { 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; return false;
} }
} }

Loading…
Cancel
Save