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:
parent
11da1aa988
commit
952e7bb4ab
1 changed files with 3 additions and 0 deletions
|
@ -1671,6 +1671,9 @@ cdef class DB(object):
|
||||||
self.opts.in_use = True
|
self.opts.in_use = True
|
||||||
|
|
||||||
def __dealloc__(self):
|
def __dealloc__(self):
|
||||||
|
self.close()
|
||||||
|
|
||||||
|
def close(self):
|
||||||
cdef ColumnFamilyOptions copts
|
cdef ColumnFamilyOptions copts
|
||||||
if not self.db == NULL:
|
if not self.db == NULL:
|
||||||
# We have to make sure we delete the handles so rocksdb doesn't
|
# We have to make sure we delete the handles so rocksdb doesn't
|
||||||
|
|
Loading…
Reference in a new issue