Skip to content

Commit

Permalink
Allow rocksdb.DB instances to be manually closed
Browse files Browse the repository at this point in the history
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, stephan-hof#39.
  • Loading branch information
fish2000 authored Feb 1, 2019
1 parent 11da1aa commit 952e7bb
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions rocksdb/_rocksdb.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 952e7bb

Please sign in to comment.