njuhugn / leveldb

Automatically exported from code.google.com/p/leveldb
BSD 3-Clause "New" or "Revised" License
0 stars 0 forks source link

Iteration Fails but Get() Works with Corrupted Archive #216

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
My team is writing routines to verify the integrity of LevelDB databases, and 
we've encountered a case where a corrupt LevelDB database throws corruption 
exceptions on calls to key() during iteration but throws no exceptions when 
calling get() for every key in the database. 

We're accessing LevelDB version 1.13.0 through a JNA wrapper and running it on 
OSX 10.8.5 with paranoid checks and verify checksums turned on. We corrupt the 
archive by flipping the bits of one randomly selected byte in a .sst file. 

//iteratio psuedocode
LevelDBIterator it = JNAWrapper.getIterator();
it.seekToFirst(); //no problem
while(it.valid()){ //no problem
    try {
        ByteString key = it.key(); // <-----corruption exception thrown here. 
        ByteString value = it.value();
        //blah blah
    } catch (CorruptionException e){
        log(e); //Exception is block checksum mismatch
    } finally{}
        it.next();
    }
}

//later, iterating over a separate collection of every key in the database

for(ByteString key: keys){
    ByteString value = JNAWrapper.get(key); // <-----No exception thrown, something always returned
}

It seems that there is an inconsistency between how the iterator is checking 
for corruption and how the get() call checks for corruption. Ideally, get() 
would thrown an exception if and when iterator calls to a corrupt record (or 
block of records) throws an exception. 

Original issue reported on code.google.com by jpflana...@gmail.com on 11 Nov 2013 at 10:02