Skip to content

Commit

Permalink
Verbose listing of entries in GetRangeHash()
Browse files Browse the repository at this point in the history
  • Loading branch information
ajkr committed Mar 31, 2024
1 parent 7e80032 commit d336470
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
18 changes: 14 additions & 4 deletions db_stress_tool/db_stress_test_base.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2510,12 +2510,13 @@ void StressTest::TestCompactRange(ThreadState* thread, int64_t rand_key,

const Snapshot* pre_snapshot = nullptr;
uint32_t pre_hash = 0;
std::string pre_entries, post_entries;
if (thread->rand.OneIn(2)) {
// Do some validation by declaring a snapshot and compare the data before
// and after the compaction
pre_snapshot = db_->GetSnapshot();
pre_hash =
GetRangeHash(thread, pre_snapshot, column_family, start_key, end_key);
GetRangeHash(thread, pre_snapshot, column_family, start_key, end_key, &pre_entries);
}
std::ostringstream compact_range_opt_oss;
compact_range_opt_oss << "exclusive_manual_compaction: "
Expand Down Expand Up @@ -2552,7 +2553,7 @@ void StressTest::TestCompactRange(ThreadState* thread, int64_t rand_key,

if (pre_snapshot != nullptr) {
uint32_t post_hash =
GetRangeHash(thread, pre_snapshot, column_family, start_key, end_key);
GetRangeHash(thread, pre_snapshot, column_family, start_key, end_key, &post_entries);
if (pre_hash != post_hash) {
fprintf(stderr,
"Data hash different before and after compact range "
Expand All @@ -2561,18 +2562,20 @@ void StressTest::TestCompactRange(ThreadState* thread, int64_t rand_key,
"missing field indicates default option or value is used)\n",
start_key.ToString(true).c_str(), end_key.ToString(true).c_str(),
compact_range_opt_oss.str().c_str());
fprintf(stderr, "pre_entries=%s\n", pre_entries.c_str());
fprintf(stderr, "post_entries=%s\n", post_entries.c_str());
thread->stats.AddErrors(1);
// Fail fast to preserve the DB state.
thread->shared->SetVerificationFailure();
}
db_->ReleaseSnapshot(pre_snapshot);
}
}

uint32_t StressTest::GetRangeHash(ThreadState* thread, const Snapshot* snapshot,
ColumnFamilyHandle* column_family,
const Slice& start_key,
const Slice& end_key) {
const Slice& end_key,
std::string* range_str) {
// This `ReadOptions` is for validation purposes. Ignore
// `FLAGS_rate_limit_user_ops` to avoid slowing any validation.
ReadOptions ro;
Expand All @@ -2592,21 +2595,28 @@ uint32_t StressTest::GetRangeHash(ThreadState* thread, const Snapshot* snapshot,

uint32_t crc = 0;

std::ostringstream range_oss;
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, sizeof(char));
crc = crc32c::Extend(crc, it->value().data(), it->value().size());
crc = crc32c::Extend(crc, &kCrcCalculatorSepearator, sizeof(char));
range_oss << "key: " << it->key().ToString(true)
<< ", val: " << it->value().ToString(true);

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));
range_oss << ", " << column.name().ToString(true)
<< ": " << column.value().ToString(true);
}
range_oss << std::endl;
}
*range_str = range_oss.str();

if (!it->status().ok()) {
fprintf(stderr, "Iterator non-OK when calculating range CRC: %s\n",
Expand Down
3 changes: 2 additions & 1 deletion db_stress_tool/db_stress_test_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,8 @@ class StressTest {
// at a certain snapshot.
uint32_t GetRangeHash(ThreadState* thread, const Snapshot* snapshot,
ColumnFamilyHandle* column_family,
const Slice& start_key, const Slice& end_key);
const Slice& start_key, const Slice& end_key,
std::string* range_str);

// Return a column family handle that mirrors what is pointed by
// `column_family_id`, which will be used to validate data to be correct.
Expand Down

0 comments on commit d336470

Please sign in to comment.