diff --git a/docs/api/database.rst b/docs/api/database.rst index 2b2f875f027ac8655f293bce008278a84f8c37a1..2477bcebe22cfc9499c29feec880a915cf33bf4a 100644 --- a/docs/api/database.rst +++ b/docs/api/database.rst @@ -421,8 +421,20 @@ WriteBatchIterator Third item (value): The value for this operation. Empty for ``"Delete"``. - changelog - tutoro +Repair DB +========= + +.. py:function:: repair_db(db_name, opts) + + :param unicode db_name: Name of the database to open + :param opts: Options for this specific database + :type opts: :py:class:`rocksdb.Options` + + If a DB cannot be opened, you may attempt to call this method to + resurrect as much of the contents of the database as possible. + Some data may be lost, so be careful when calling this function + on a database that contains important information. + Errors ====== diff --git a/docs/changelog.rst b/docs/changelog.rst index ef9afe8bc3ef92c803f8fc31d51a0e6779879b09..654ad9d69d695076935875766c48665cd6fb647e 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -3,7 +3,9 @@ Changelog Version 0.4 ----------- -Nothing in yet. + +* Added :py:func:`repair_db` + Version 0.3 ----------- diff --git a/rocksdb/_rocksdb.pyx b/rocksdb/_rocksdb.pyx index 4ceb8cc98fb72939dd5156e75f5d200cb0d0e519..99e841aae317c68f9c1dd80902dbfd9b15d039e6 100644 --- a/rocksdb/_rocksdb.pyx +++ b/rocksdb/_rocksdb.pyx @@ -1615,6 +1615,16 @@ cdef class DB(object): def __get__(self): return self.opts + +def repair_db(db_name, Options opts): + cdef Status st + cdef string db_path + + db_path = path_to_string(db_name) + st = db.RepairDB(db_path, deref(opts.opts)) + check_status(st) + + @cython.no_gc_clear @cython.internal cdef class Snapshot(object): diff --git a/rocksdb/db.pxd b/rocksdb/db.pxd index 06a7f4093dedd43f3de40db1dc3b767c24a321e3..afd444f879546fb45375ae76d10af5501c1d75d0 100644 --- a/rocksdb/db.pxd +++ b/rocksdb/db.pxd @@ -140,3 +140,5 @@ cdef extern from "rocksdb/db.h" namespace "rocksdb": const string&, DB**, cpp_bool) nogil except+ + + cdef Status RepairDB(const string& dbname, const options.Options&)