Update _rocksdb.pyx

This commit is contained in:
iFA 2020-09-03 08:50:13 +02:00 committed by GitHub
parent 0f66d77c6c
commit c1e12fd62d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,3 +1,4 @@
#cython: language_level=3
import cython import cython
from libcpp.string cimport string from libcpp.string cimport string
from libcpp.deque cimport deque from libcpp.deque cimport deque
@ -12,44 +13,52 @@ from cpython.bytes cimport PyBytes_FromString
from cpython.bytes cimport PyBytes_FromStringAndSize from cpython.bytes cimport PyBytes_FromStringAndSize
from cpython.unicode cimport PyUnicode_Decode from cpython.unicode cimport PyUnicode_Decode
from std_memory cimport shared_ptr from .std_memory cimport shared_ptr
cimport options from . cimport options
cimport merge_operator from . cimport merge_operator
cimport filter_policy from . cimport filter_policy
cimport comparator from . cimport comparator
cimport slice_transform from . cimport slice_transform
cimport cache from . cimport cache
cimport logger from . cimport logger
cimport snapshot from . cimport snapshot
cimport db from . cimport db
cimport iterator from . cimport iterator
cimport backup from . cimport backup
cimport env from . cimport env
cimport table_factory from . cimport table_factory
cimport memtablerep from . cimport memtablerep
cimport universal_compaction from . cimport universal_compaction
# Enums are the only exception for direct imports # Enums are the only exception for direct imports
# Their name als already unique enough # Their name als already unique enough
from universal_compaction cimport kCompactionStopStyleSimilarSize from .universal_compaction cimport kCompactionStopStyleSimilarSize
from universal_compaction cimport kCompactionStopStyleTotalSize from .universal_compaction cimport kCompactionStopStyleTotalSize
from options cimport kCompactionStyleLevel from .options cimport kCompactionStyleLevel
from options cimport kCompactionStyleUniversal from .options cimport kCompactionStyleUniversal
from options cimport kCompactionStyleFIFO from .options cimport kCompactionStyleFIFO
from options cimport kCompactionStyleNone from .options cimport kCompactionStyleNone
from slice_ cimport Slice from .slice_ cimport Slice
from status cimport Status from .status cimport Status
import sys import sys
from interfaces import MergeOperator as IMergeOperator from .interfaces import MergeOperator as IMergeOperator
from interfaces import AssociativeMergeOperator as IAssociativeMergeOperator from .interfaces import AssociativeMergeOperator as IAssociativeMergeOperator
from interfaces import FilterPolicy as IFilterPolicy from .interfaces import FilterPolicy as IFilterPolicy
from interfaces import Comparator as IComparator from .interfaces import Comparator as IComparator
from interfaces import SliceTransform as ISliceTransform from .interfaces import SliceTransform as ISliceTransform
import traceback import traceback
import errors from .errors import NotFound
from .errors import Corruption
from .errors import NotSupported
from .errors import InvalidArgument
from .errors import RocksIOError
from .errors import MergeInProgress
from .errors import Incomplete
import weakref import weakref
ctypedef const filter_policy.FilterPolicy ConstFilterPolicy ctypedef const filter_policy.FilterPolicy ConstFilterPolicy
@ -70,25 +79,25 @@ cdef check_status(const Status& st):
return return
if st.IsNotFound(): if st.IsNotFound():
raise errors.NotFound(st.ToString()) raise NotFound(st.ToString())
if st.IsCorruption(): if st.IsCorruption():
raise errors.Corruption(st.ToString()) raise Corruption(st.ToString())
if st.IsNotSupported(): if st.IsNotSupported():
raise errors.NotSupported(st.ToString()) raise NotSupported(st.ToString())
if st.IsInvalidArgument(): if st.IsInvalidArgument():
raise errors.InvalidArgument(st.ToString()) raise InvalidArgument(st.ToString())
if st.IsIOError(): if st.IsIOError():
raise errors.RocksIOError(st.ToString()) raise RocksIOError(st.ToString())
if st.IsMergeInProgress(): if st.IsMergeInProgress():
raise errors.MergeInProgress(st.ToString()) raise MergeInProgress(st.ToString())
if st.IsIncomplete(): if st.IsIncomplete():
raise errors.Incomplete(st.ToString()) raise Incomplete(st.ToString())
raise Exception("Unknown error: %s" % st.ToString()) raise Exception("Unknown error: %s" % st.ToString())
###################################################### ######################################################
@ -1739,11 +1748,14 @@ cdef class DB(object):
del self.cf_options[:] del self.cf_options[:]
with nogil: with nogil:
st = self.db.Close()
del self.db del self.db
if self.opts is not None: if self.opts is not None:
self.opts.in_use = False self.opts.in_use = False
check_status(st)
@property @property
def column_families(self): def column_families(self):
return [handle.weakref for handle in self.cf_handles] return [handle.weakref for handle in self.cf_handles]