aboutsummaryrefslogtreecommitdiff
path: root/src/leveldb/db/corruption_test.cc
diff options
context:
space:
mode:
authorPieter Wuille <pieter.wuille@gmail.com>2013-12-12 22:08:18 +0100
committerPieter Wuille <pieter.wuille@gmail.com>2013-12-12 22:08:18 +0100
commited873a301eeff8c021ba57c78fb702fd2b6f0452 (patch)
tree3fb5bcb91b8ceab464a50e63b6fce407eccb17e2 /src/leveldb/db/corruption_test.cc
parentfb34be6d5905d36a2d9a392d87aa73bdb9470a1b (diff)
parent55c68902946c8c9bacea748c159be456a7c9c180 (diff)
downloadbitcoin-ed873a301eeff8c021ba57c78fb702fd2b6f0452.tar.xz
Merge src/leveldb changes for LevelDB 1.15
Diffstat (limited to 'src/leveldb/db/corruption_test.cc')
-rw-r--r--src/leveldb/db/corruption_test.cc26
1 files changed, 24 insertions, 2 deletions
diff --git a/src/leveldb/db/corruption_test.cc b/src/leveldb/db/corruption_test.cc
index b37ffdfe64..96afc68913 100644
--- a/src/leveldb/db/corruption_test.cc
+++ b/src/leveldb/db/corruption_test.cc
@@ -75,7 +75,13 @@ class CorruptionTest {
Slice key = Key(i, &key_space);
batch.Clear();
batch.Put(key, Value(i, &value_space));
- ASSERT_OK(db_->Write(WriteOptions(), &batch));
+ WriteOptions options;
+ // Corrupt() doesn't work without this sync on windows; stat reports 0 for
+ // the file size.
+ if (i == n - 1) {
+ options.sync = true;
+ }
+ ASSERT_OK(db_->Write(options, &batch));
}
}
@@ -125,7 +131,7 @@ class CorruptionTest {
FileType type;
std::string fname;
int picked_number = -1;
- for (int i = 0; i < filenames.size(); i++) {
+ for (size_t i = 0; i < filenames.size(); i++) {
if (ParseFileName(filenames[i], &number, &type) &&
type == filetype &&
int(number) > picked_number) { // Pick latest file
@@ -238,6 +244,22 @@ TEST(CorruptionTest, TableFile) {
Check(90, 99);
}
+TEST(CorruptionTest, TableFileRepair) {
+ options_.block_size = 2 * kValueSize; // Limit scope of corruption
+ options_.paranoid_checks = true;
+ Reopen();
+ Build(100);
+ DBImpl* dbi = reinterpret_cast<DBImpl*>(db_);
+ dbi->TEST_CompactMemTable();
+ dbi->TEST_CompactRange(0, NULL, NULL);
+ dbi->TEST_CompactRange(1, NULL, NULL);
+
+ Corrupt(kTableFile, 100, 1);
+ RepairDB();
+ Reopen();
+ Check(95, 99);
+}
+
TEST(CorruptionTest, TableFileIndexData) {
Build(10000); // Enough to build multiple Tables
DBImpl* dbi = reinterpret_cast<DBImpl*>(db_);