diff options
author | jorlow@chromium.org <jorlow@chromium.org@62dab493-f737-651d-591e-8d6aee1b9529> | 2011-03-21 19:40:57 +0000 |
---|---|---|
committer | jorlow@chromium.org <jorlow@chromium.org@62dab493-f737-651d-591e-8d6aee1b9529> | 2011-03-21 19:40:57 +0000 |
commit | 0e389254905fc246271ca991e203d95031c93559 (patch) | |
tree | 32cd0421f16f1941079ba212e69dab68d209041d /db/corruption_test.cc | |
parent | 24ba6148694a68d010fe0c515616390abc12c5c4 (diff) | |
download | leveldb-0e389254905fc246271ca991e203d95031c93559.tar.gz |
Sync in bug fixes
git-svn-id: https://leveldb.googlecode.com/svn/trunk@9 62dab493-f737-651d-591e-8d6aee1b9529
Diffstat (limited to 'db/corruption_test.cc')
-rw-r--r-- | db/corruption_test.cc | 33 |
1 files changed, 18 insertions, 15 deletions
diff --git a/db/corruption_test.cc b/db/corruption_test.cc index a59ab0e..1f4f26c 100644 --- a/db/corruption_test.cc +++ b/db/corruption_test.cc @@ -13,6 +13,7 @@ #include "include/write_batch.h" #include "db/db_impl.h" #include "db/filename.h" +#include "db/log_format.h" #include "db/version_set.h" #include "util/logging.h" #include "util/testharness.h" @@ -128,17 +129,17 @@ class CorruptionTest { std::string fname = candidates[rnd_.Uniform(candidates.size())]; struct stat sbuf; - if (stat(fname.c_str(), &sbuf) != 0) { - const char* msg = strerror(errno); - ASSERT_TRUE(false) << fname << ": " << msg; - } - - if (offset < 0) { - // Relative to end of file; make it absolute - if (-offset > sbuf.st_size) { - offset = 0; - } else { - offset = sbuf.st_size + offset; + if (stat(fname.c_str(), &sbuf) != 0) { + const char* msg = strerror(errno); + ASSERT_TRUE(false) << fname << ": " << msg; + } + + if (offset < 0) { + // Relative to end of file; make it absolute + if (-offset > sbuf.st_size) { + offset = 0; + } else { + offset = sbuf.st_size + offset; } } if (offset > sbuf.st_size) { @@ -183,12 +184,14 @@ class CorruptionTest { }; TEST(CorruptionTest, Recovery) { - Build(10); - Check(10, 10); + Build(100); + Check(100, 100); Corrupt(kLogFile, 19, 1); // WriteBatch tag for first record - Corrupt(kLogFile, 2*kValueSize, 1); // Somewhere in second log record? + Corrupt(kLogFile, log::kBlockSize + 1000, 1); // Somewhere in second block Reopen(); - Check(8, 8); + + // The 64 records in the first two log blocks are completely lost. + Check(36, 36); } TEST(CorruptionTest, RecoverWriteError) { |