Triggering verify for gets also

Summary: Will use iterators to verify keys in the db for half of its keys and Gets for the other half.

Test Plan: ./db_stress --max_key=1000 --ops_per_thread=100

Reviewers: dhruba, haobo

Reviewed By: dhruba

CC: leveldb

Differential Revision: https://reviews.facebook.net/D13227
main
Mayank Agarwal 11 years ago
parent 71046971f0
commit 6b34021fc2
  1. 28
      tools/db_stress.cc

@ -698,8 +698,7 @@ class StressTest {
} }
if (!FLAGS_test_batches_snapshots) { if (!FLAGS_test_batches_snapshots) {
thread->shared->GetStressTest()->VerifyDb(*(thread->shared), thread->shared->GetStressTest()->VerifyDb(thread);
thread->tid);
} }
{ {
@ -1064,15 +1063,18 @@ class StressTest {
thread->stats.Stop(); thread->stats.Stop();
} }
void VerifyDb(const SharedState &shared, long tid) const { void VerifyDb(ThreadState* thread) const {
ReadOptions options(FLAGS_verify_checksum, true); ReadOptions options(FLAGS_verify_checksum, true);
long max_key = shared.GetMaxKey(); const SharedState& shared = *(thread->shared);
static const long max_key = shared.GetMaxKey();
static const long keys_per_thread = max_key / shared.GetNumThreads(); static const long keys_per_thread = max_key / shared.GetNumThreads();
long start = keys_per_thread * tid; long start = keys_per_thread * thread->tid;
long end = start + keys_per_thread; long end = start + keys_per_thread;
if (tid == shared.GetNumThreads() - 1) { if (thread->tid == shared.GetNumThreads() - 1) {
end = max_key; end = max_key;
} }
if (!thread->rand.OneIn(2)) {
// Use iterator to verify this range
unique_ptr<Iterator> iter(db_->NewIterator(options)); unique_ptr<Iterator> iter(db_->NewIterator(options));
iter->Seek(Key(start)); iter->Seek(Key(start));
for (long i = start; i < end; i++) { for (long i = start; i < end; i++) {
@ -1100,6 +1102,20 @@ class StressTest {
} }
} }
} }
else {
// Use Get to verify this range
for (long i = start; i < end; i++) {
std::string from_db;
std::string keystr = Key(i);
Slice k = keystr;
Status s = db_->Get(options, k, &from_db);
VerifyValue(i, options, shared, from_db, s, true);
if (from_db.length()) {
PrintKeyValue(i, from_db.data(), from_db.length());
}
}
}
}
void VerificationAbort(std::string msg, long key) const { void VerificationAbort(std::string msg, long key) const {
fprintf(stderr, "Verification failed for key %ld: %s\n", fprintf(stderr, "Verification failed for key %ld: %s\n",

Loading…
Cancel
Save