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
This commit is contained in:
Mayank Agarwal 2013-10-01 23:19:51 -07:00
parent 71046971f0
commit 6b34021fc2

View File

@ -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,39 +1063,56 @@ 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;
} }
unique_ptr<Iterator> iter(db_->NewIterator(options)); if (!thread->rand.OneIn(2)) {
iter->Seek(Key(start)); // Use iterator to verify this range
for (long i = start; i < end; i++) { unique_ptr<Iterator> iter(db_->NewIterator(options));
std::string from_db; iter->Seek(Key(start));
std::string keystr = Key(i); for (long i = start; i < end; i++) {
Slice k = keystr; std::string from_db;
Status s = iter->status(); std::string keystr = Key(i);
if (iter->Valid()) { Slice k = keystr;
if (iter->key().compare(k) > 0) { Status s = iter->status();
if (iter->Valid()) {
if (iter->key().compare(k) > 0) {
s = Status::NotFound(Slice());
} else if (iter->key().compare(k) == 0) {
from_db = iter->value().ToString();
iter->Next();
} else if (iter->key().compare(k) < 0) {
VerificationAbort("An out of range key was found", i);
}
} else {
// The iterator found no value for the key in question, so do not
// move to the next item in the iterator
s = Status::NotFound(Slice()); s = Status::NotFound(Slice());
} else if (iter->key().compare(k) == 0) {
from_db = iter->value().ToString();
iter->Next();
} else if (iter->key().compare(k) < 0) {
VerificationAbort("An out of range key was found", i);
} }
} else { VerifyValue(i, options, shared, from_db, s, true);
// The iterator found no value for the key in question, so do not if (from_db.length()) {
// move to the next item in the iterator PrintKeyValue(i, from_db.data(), from_db.length());
s = Status::NotFound(Slice()); }
} }
VerifyValue(i, options, shared, from_db, s, true); }
if (from_db.length()) { else {
PrintKeyValue(i, from_db.data(), from_db.length()); // 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());
}
} }
} }
} }