Allow rocksdb.DB instances to be manually closed

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.
This commit is contained in:
Alexander Böhn 2019-02-01 11:36:36 -05:00 committed by GitHub
parent 11da1aa988
commit 952e7bb4ab
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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