From 8fba5ffa1dd2d4a6b40387a239343c43666bd040 Mon Sep 17 00:00:00 2001
From: hofmockel <dreagonfly@gmx.de>
Date: Sat, 15 Aug 2015 16:34:35 +0200
Subject: [PATCH] Wrap the RepairDB function.

---
 docs/api/database.rst | 16 ++++++++++++++--
 docs/changelog.rst    |  4 +++-
 rocksdb/_rocksdb.pyx  | 10 ++++++++++
 rocksdb/db.pxd        |  2 ++
 4 files changed, 29 insertions(+), 3 deletions(-)

diff --git a/docs/api/database.rst b/docs/api/database.rst
index 2b2f875..2477bce 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 ef9afe8..654ad9d 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 4ceb8cc..99e841a 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 06a7f40..afd444f 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&)
-- 
GitLab