From 3b86a51cb1f54f9b34a0ca585e80ff8ba560cd75 Mon Sep 17 00:00:00 2001 From: Dhruba Borthakur Date: Sat, 19 May 2012 00:05:48 -0700 Subject: [PATCH] Ability to switch on checksum verification from benchmark. Summary: Task ID: # Blame Rev: Test Plan: Revert Plan: Differential Revision: https://reviews.facebook.net/D3309 --- db/db_bench.cc | 18 ++++++++++++------ include/leveldb/options.h | 4 ++++ 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/db/db_bench.cc b/db/db_bench.cc index 8912fad1d..0bab80748 100644 --- a/db/db_bench.cc +++ b/db/db_bench.cc @@ -107,6 +107,9 @@ static const char* FLAGS_db = "/tmp/dbbench"; // if FLAGS_cache_size is non-negative. static int FLAGS_cache_numshardbits = -1; +// Verify checksum for every block read from storage +static bool FLAGS_verify_checksum = false; + namespace leveldb { namespace { @@ -751,7 +754,7 @@ class Benchmark { } void ReadSequential(ThreadState* thread) { - Iterator* iter = db_->NewIterator(ReadOptions()); + Iterator* iter = db_->NewIterator(ReadOptions(FLAGS_verify_checksum, true)); int i = 0; int64_t bytes = 0; for (iter->SeekToFirst(); i < reads_ && iter->Valid(); iter->Next()) { @@ -764,7 +767,7 @@ class Benchmark { } void ReadReverse(ThreadState* thread) { - Iterator* iter = db_->NewIterator(ReadOptions()); + Iterator* iter = db_->NewIterator(ReadOptions(FLAGS_verify_checksum, true)); int i = 0; int64_t bytes = 0; for (iter->SeekToLast(); i < reads_ && iter->Valid(); iter->Prev()) { @@ -777,7 +780,7 @@ class Benchmark { } void ReadRandom(ThreadState* thread) { - ReadOptions options; + ReadOptions options(FLAGS_verify_checksum, true); std::string value; int found = 0; for (int i = 0; i < reads_; i++) { @@ -795,7 +798,7 @@ class Benchmark { } void ReadMissing(ThreadState* thread) { - ReadOptions options; + ReadOptions options(FLAGS_verify_checksum, true); std::string value; for (int i = 0; i < reads_; i++) { char key[100]; @@ -807,7 +810,7 @@ class Benchmark { } void ReadHot(ThreadState* thread) { - ReadOptions options; + ReadOptions options(FLAGS_verify_checksum, true); std::string value; const int range = (FLAGS_num + 99) / 100; for (int i = 0; i < reads_; i++) { @@ -820,7 +823,7 @@ class Benchmark { } void SeekRandom(ThreadState* thread) { - ReadOptions options; + ReadOptions options(FLAGS_verify_checksum, true); std::string value; int found = 0; for (int i = 0; i < reads_; i++) { @@ -971,6 +974,9 @@ int main(int argc, char** argv) { FLAGS_open_files = n; } else if (strncmp(argv[i], "--db=", 5) == 0) { FLAGS_db = argv[i] + 5; + } else if (sscanf(argv[i], "--verify_checksum=%d%c", &n, &junk) == 1 && + (n == 0 || n == 1)) { + FLAGS_verify_checksum = n; } else { fprintf(stderr, "Invalid flag '%s'\n", argv[i]); exit(1); diff --git a/include/leveldb/options.h b/include/leveldb/options.h index fdda718d3..83fede3e6 100644 --- a/include/leveldb/options.h +++ b/include/leveldb/options.h @@ -163,6 +163,10 @@ struct ReadOptions { fill_cache(true), snapshot(NULL) { } + ReadOptions(bool cksum, bool cache) : + verify_checksums(cksum), fill_cache(cache), + snapshot(NULL) { + } }; // Options that control write operations