Skip to content

Commit

Permalink
Merge pull request #2 from iFA88/iFA88-patch-1
Browse files Browse the repository at this point in the history
add bottommost_compression support
  • Loading branch information
iFA88 authored May 21, 2021
2 parents 3bd767e + 487b19b commit fcf9d33
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 4 deletions.
80 changes: 76 additions & 4 deletions rocksdb/_rocksdb.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -936,6 +936,30 @@ cdef class ColumnFamilyOptions(object):
if 'max_dict_bytes' in value:
copts.max_dict_bytes = value['max_dict_bytes']

property bottommost_compression_opts:
def __get__(self):
cdef dict ret_ob = {}

ret_ob['window_bits'] = self.copts.bottommost_compression_opts.window_bits
ret_ob['level'] = self.copts.bottommost_compression_opts.level
ret_ob['strategy'] = self.copts.bottommost_compression_opts.strategy
ret_ob['max_dict_bytes'] = self.copts.bottommost_compression_opts.max_dict_bytes

return ret_ob

def __set__(self, dict value):
cdef options.CompressionOptions* copts
copts = cython.address(self.copts.bottommost_compression_opts)
# CompressionOptions(int wbits, int _lev, int _strategy, int _max_dict_bytes)
if 'window_bits' in value:
copts.window_bits = value['window_bits']
if 'level' in value:
copts.level = value['level']
if 'strategy' in value:
copts.strategy = value['strategy']
if 'max_dict_bytes' in value:
copts.max_dict_bytes = value['max_dict_bytes']

property compaction_pri:
def __get__(self):
if self.copts.compaction_pri == options.kByCompensatedSize:
Expand Down Expand Up @@ -1005,6 +1029,53 @@ cdef class ColumnFamilyOptions(object):
else:
raise TypeError("Unknown compression: %s" % value)

property bottommost_compression:
def __get__(self):
if self.copts.bottommost_compression == options.kNoCompression:
return CompressionType.no_compression
elif self.copts.bottommost_compression == options.kSnappyCompression:
return CompressionType.snappy_compression
elif self.copts.bottommost_compression == options.kZlibCompression:
return CompressionType.zlib_compression
elif self.copts.bottommost_compression == options.kBZip2Compression:
return CompressionType.bzip2_compression
elif self.copts.bottommost_compression == options.kLZ4Compression:
return CompressionType.lz4_compression
elif self.copts.bottommost_compression == options.kLZ4HCCompression:
return CompressionType.lz4hc_compression
elif self.copts.bottommost_compression == options.kXpressCompression:
return CompressionType.xpress_compression
elif self.copts.bottommost_compression == options.kZSTD:
return CompressionType.zstd_compression
elif self.copts.bottommost_compression == options.kZSTDNotFinalCompression:
return CompressionType.zstdnotfinal_compression
elif self.copts.bottommost_compression == options.kDisableCompressionOption:
return CompressionType.disable_compression
else:
raise Exception("Unknonw type: %s" % self.opts.compression)

def __set__(self, value):
if value == CompressionType.no_compression:
self.copts.bottommost_compression = options.kNoCompression
elif value == CompressionType.snappy_compression:
self.copts.bottommost_compression = options.kSnappyCompression
elif value == CompressionType.zlib_compression:
self.copts.bottommost_compression = options.kZlibCompression
elif value == CompressionType.bzip2_compression:
self.copts.bottommost_compression = options.kBZip2Compression
elif value == CompressionType.lz4_compression:
self.copts.bottommost_compression = options.kLZ4Compression
elif value == CompressionType.lz4hc_compression:
self.copts.bottommost_compression = options.kLZ4HCCompression
elif value == CompressionType.zstd_compression:
self.copts.bottommost_compression = options.kZSTD
elif value == CompressionType.zstdnotfinal_compression:
self.copts.bottommost_compression = options.kZSTDNotFinalCompression
elif value == CompressionType.disable_compression:
self.copts.bottommost_compression = options.kDisableCompressionOption
else:
raise TypeError("Unknown compression: %s" % value)

property max_compaction_bytes:
def __get__(self):
return self.copts.max_compaction_bytes
Expand Down Expand Up @@ -1294,7 +1365,7 @@ cdef class Options(ColumnFamilyOptions):
def __dealloc__(self):
if not self.opts == NULL:
with nogil:
del self.copts
self.copts = NULL
del self.opts

def __init__(self, **kwargs):
Expand Down Expand Up @@ -1758,7 +1829,7 @@ cdef class DB(object):
cdef ColumnFamilyOptions copts
cdef cpp_bool c_safe = safe
cdef Status st
if self.db != NULL:
if not self.db == NULL:
# We need stop backround compactions
with nogil:
db.CancelAllBackgroundWork(self.db, c_safe)
Expand All @@ -1769,11 +1840,12 @@ cdef class DB(object):
if copts:
copts.in_use = False
self.cf_options.clear()
if self.opts is not None:
self.opts.in_use = False
self.opts = None
with nogil:
self.db.Close()
self.db = NULL
if self.opts is not None:
self.opts.in_use = False

def __dealloc__(self):
self.close()
Expand Down
2 changes: 2 additions & 0 deletions rocksdb/options.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ cdef extern from "rocksdb/options.h" namespace "rocksdb":
int max_write_buffer_number
int min_write_buffer_number_to_merge
CompressionType compression
CompressionType bottommost_compression
CompactionPri compaction_pri
# TODO: compression_per_level
shared_ptr[SliceTransform] prefix_extractor
Expand Down Expand Up @@ -157,6 +158,7 @@ cdef extern from "rocksdb/options.h" namespace "rocksdb":
# TODO: remove options source_compaction_factor, max_grandparent_overlap_bytes and expanded_compaction_factor from document
uint64_t max_compaction_bytes
CompressionOptions compression_opts
CompressionOptions bottommost_compression_opts
cpp_bool optimize_filters_for_hits
cpp_bool paranoid_file_checks
cpp_bool level_compaction_dynamic_level_bytes
Expand Down
1 change: 1 addition & 0 deletions rocksdb/statistics.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ cdef extern from "rocksdb/statistics.h" namespace "rocksdb":

cdef cppclass Statistics:
void set_stats_level(StatsLevel) nogil except+

0 comments on commit fcf9d33

Please sign in to comment.