From 31368958dd9191129b0c64408b429708ecbfd33b Mon Sep 17 00:00:00 2001 From: Alexander Regueiro Date: Wed, 10 Mar 2021 23:24:58 +0000 Subject: [PATCH 1/2] Added bindings for `DB::Close` and `CancelAllBackgroundWork`. --- rocksdb/db.pxd | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/rocksdb/db.pxd b/rocksdb/db.pxd index 3578501..7c71976 100644 --- a/rocksdb/db.pxd +++ b/rocksdb/db.pxd @@ -55,6 +55,8 @@ cdef extern from "rocksdb/db.h" namespace "rocksdb": Range(const Slice&, const Slice&) cdef cppclass DB: + Status Close() nogil except+ + Status Put( const options.WriteOptions&, ColumnFamilyHandle*, @@ -203,3 +205,8 @@ cdef extern from "rocksdb/db.h" namespace "rocksdb": const options.ColumnFamilyOptions&) nogil except+ string name options.ColumnFamilyOptions options + +cdef extern from "rocksdb/convenience.h" namespace "rocksdb": + void CancelAllBackgroundWork( + DB* db, + cpp_bool wait) nogil except+ From bc53da42ef8b20c494b555dfaba99ae2c91f403f Mon Sep 17 00:00:00 2001 From: Alexander Regueiro Date: Wed, 10 Mar 2021 23:16:34 +0000 Subject: [PATCH 2/2] Fixed segfault caused by deallocating outside of `DB` destructor. Close DB when `close` is called, and free DB object only in destructor. --- rocksdb/_rocksdb.pyx | 9 ++++----- rocksdb/db.pxd | 2 +- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/rocksdb/_rocksdb.pyx b/rocksdb/_rocksdb.pyx index edd856a..47372c4 100644 --- a/rocksdb/_rocksdb.pyx +++ b/rocksdb/_rocksdb.pyx @@ -1672,21 +1672,20 @@ cdef class DB(object): def __dealloc__(self): self.close() - + if not self.db == NULL: + del self.db + def close(self): cdef ColumnFamilyOptions copts if not self.db == NULL: # We have to make sure we delete the handles so rocksdb doesn't - # assert when we delete the db + # assert when we delete the db. self.cf_handles.clear() for copts in self.cf_options: if copts: copts.in_use = False self.cf_options.clear() - with nogil: - del self.db - if self.opts is not None: self.opts.in_use = False diff --git a/rocksdb/db.pxd b/rocksdb/db.pxd index 7c71976..06d33e1 100644 --- a/rocksdb/db.pxd +++ b/rocksdb/db.pxd @@ -201,7 +201,7 @@ cdef extern from "rocksdb/db.h" namespace "rocksdb": cdef cppclass ColumnFamilyDescriptor: ColumnFamilyDescriptor() nogil except+ ColumnFamilyDescriptor( - const string&, + const string&, const options.ColumnFamilyOptions&) nogil except+ string name options.ColumnFamilyOptions options