From 952e7bb4ab8d6cfad2c5fdd003e7077c179993a3 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Alexander=20B=C3=B6hn?= <fish2000@users.noreply.github.com>
Date: Fri, 1 Feb 2019 11:36:36 -0500
Subject: [PATCH] Allow `rocksdb.DB` instances to be manually closed
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

While `delete rocks_ptr` is a deterministic operation in C++, the Python analogue `del rocks_handle` is not – disposal and finalization of the Rocks database are entirely dependent on the Python garbage collector (q.v. the `python-rocksdb` tests themselves, which call `gc.collect()` after `del rocks_handle` to attempt to force the destructor to run). This change exposes a method to trigger the destruction of the underlying Rocks database pointer (deterministic!) through the Python Rocks handle; existing code will not need to be changed, as the Python object destructor (non-deterministic!) will now call this method.

This is the second revision of this PR – it resolves the first revision, #39.
---
 rocksdb/_rocksdb.pyx | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/rocksdb/_rocksdb.pyx b/rocksdb/_rocksdb.pyx
index 32efba5..edd856a 100644
--- a/rocksdb/_rocksdb.pyx
+++ b/rocksdb/_rocksdb.pyx
@@ -1671,6 +1671,9 @@ cdef class DB(object):
         self.opts.in_use = True
 
     def __dealloc__(self):
+        self.close()
+        
+    def close(self):
         cdef ColumnFamilyOptions copts
         if not self.db == NULL:
             # We have to make sure we delete the handles so rocksdb doesn't
-- 
GitLab