Chainstate LevelDB corruption after reading from the database I've been working with the LevelDB for a few weeks, coding some tools to access the database and parse the data to be human readable. 

However, every single time I read from the chainstate the data gets corrupted (ask me to rebuild it when running bitcoind). I decided to copy the DB as a workaround after it happened the first time, but it's quite annoying to do so every single time I want to update the data.

I'm using plyvel and Python 2.8, and I close the DB every time I finish with the reading.

Example

# Open the LevelDB
db = plyvel.DB(".bitcoin/chainstate")

for key, o_value in db:
 # do stuff

# Close the LevelDB
db.close()


Does anyone knows what could be the reason? Does bitcoind prevent other software to access the DB by marking the last access somehow?

chainstate LOG after running the code, retrieving the obfuscation key, and closing the database:

2017/03/22-11:03:45.746702 7f3c18a39700 Recovering log #394423
2017/03/22-11:03:45.854583 7f3c18a39700 Delete type=0 #394423
2017/03/22-11:03:45.854711 7f3c18a39700 Delete type=3 #394422


Example code:

db = plyvel.DB(".bitcoin/chainstate")
o_key = db.get((a2b_hex("0e00") + "obfuscate_key"))
db.close()


debug.log after opening bitcoind (just the part referring to the LevelDB):

2017-03-22 10:03:45 Cache configuration:
2017-03-22 10:03:45 * Using 2.0MiB for block index database
2017-03-22 10:03:45 * Using 8.0MiB for chain state database
2017-03-22 10:03:45 * Using 290.0MiB for in-memory UTXO set
2017-03-22 10:03:45 init message: Loading block index...
2017-03-22 10:03:45 Opening LevelDB in /home/sdelgado/.bitcoin/blocks/index
2017-03-22 10:03:45 Opened LevelDB successfully
2017-03-22 10:03:45 Using obfuscation key for /home/sdelgado/.bitcoin/blocks/index: 0000000000000000
2017-03-22 10:03:45 Opening LevelDB in /home/sdelgado/.bitcoin/chainstate
2017-03-22 10:03:45 Opened LevelDB successfully
2017-03-22 10:03:45 Using obfuscation key for /home/sdelgado/.bitcoin/chainstate: 27c78118b7316105
2017-03-22 10:03:48 LoadBlockIndexDB: last block file = 810
2017-03-22 10:03:48 LoadBlockIndexDB: last block file info: CBlockFileInfo(blocks=53, size=51783543, heights=457770...458279, time=2017-03-18...2017-03-21)
2017-03-22 10:03:48 Checking all blk files are present...
2017-03-22 10:03:49 LoadBlockIndexDB: transaction index disabled
2017-03-22 10:03:49 LevelDB read failure: Corruption: corrupted compressed block contents
2017-03-22 10:03:49 Corruption: corrupted compressed block contents
2017-03-22 10:03:51 Aborted block database rebuild. Exiting.
2017-03-22 10:03:51 scheduler thread interrupt
2017-03-22 10:03:51 Shutdown: In progress...
2017-03-22 10:03:51 StopNode()
2017-03-22 10:03:51 Shutdown: done
Plyvel has Snappy compression enabled by default. Have you tried disabling it when opening the database?

# Open the LevelDB
db = plyvel.DB(".bitcoin/chainstate", compression=None)


With this code my bitcoind does not seem to complain after having opened the database with python.