Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Repairing Corrupt LevelDB

When the LevelDB database becomes corrupted, the RepairDB option provided by the LevelDB API can be used to recover as much as data as possible. In LevelDB, the manifest file holds account of all files and their corresponding key ranges. The recovery process inspects each file in the leveldb directory and updates the manifest accordingly.

The below script can be used to repair corrupt leveldb cache:

Code Block
languagepy
#!/usr/bin/python
import leveldb
import sys
import os
import subprocess

if (len(sys.argv) != 2) :
  print 'Usage:'
  print 'python repair_leveldb.py /path/to/leveldb/cache'
  sys.exit(1)

path = sys.argv[1]
if not os.path.isdir(path) :
  print sys.argv[0], ": Directory %s does not exist!" % path
  sys.exit()
 
# Use the leveldb module to repair the files
leveldb.RepairDB(path)

# Rename ldb files to sst (Python API uses ldb extension, whereas infinispan expects sst)
script = 'for f in ' + path + '/*.ldb; do mv $f "${f%.ldb}.sst"; done'
subprocess.call(['/bin/bash', '-c', script])