@@ -162,6 +162,19 @@ cdef inline bint _check_db(DB *db) except -1 nogil:
162162 raise LevelDBException(" The database has been closed." )
163163
164164
165+ cdef inline Options* _create_options(bint create_if_missing = False ) except NULL nogil:
166+ cdef Options * options = new Options()
167+ options.create_if_missing = create_if_missing
168+ options.filter_policy = NewBloomFilterPolicy(10 )
169+ options.block_cache = NewLRUCache(40 * 1024 * 1024 )
170+ options.write_buffer_size = 4 * 1024 * 1024
171+ options.info_log = new NullLogger()
172+ options.compressors[0 ] = new ZlibCompressorRaw(- 1 )
173+ options.compressors[1 ] = new ZlibCompressor(- 1 )
174+ options.block_size = 163840
175+ return options
176+
177+
165178cdef class LevelDB:
166179 cdef DB * db
167180 cdef ReadOptions read_options
@@ -188,16 +201,7 @@ cdef class LevelDB:
188201 else :
189202 raise LevelDBException(f" No database exists to open at {path}" )
190203
191- cdef Options* options = new Options()
192- options.create_if_missing = create_if_missing
193- options.filter_policy = NewBloomFilterPolicy(10 )
194- options.block_cache = NewLRUCache(40 * 1024 * 1024 )
195- options.write_buffer_size = 4 * 1024 * 1024
196- options.info_log = new NullLogger()
197- options.compressors[0 ] = new ZlibCompressorRaw(- 1 )
198- options.compressors[1 ] = new ZlibCompressor(- 1 )
199- options.block_size = 163840
200- cdef const Options* const_options = options
204+ cdef const Options* const_options = _create_options(True )
201205
202206 self .read_options.decompress_allocator = new DecompressAllocator()
203207
@@ -393,3 +397,9 @@ cdef class LevelDB:
393397
394398 def __iter__ (self ) -> IteratorT[bytes]:
395399 return self.keys()
400+
401+
402+ def repair_db(str path ):
403+ cdef string s_path = path.encode()
404+ cdef const Options* const_options = _create_options()
405+ RepairDB(s_path, dereference(const_options))
0 commit comments