add compaction_pri

This commit is contained in:
twmht 2017-04-17 00:00:44 +08:00
parent 9aed9561e0
commit 9d87eb5bdc
2 changed files with 38 additions and 0 deletions

View file

@ -725,6 +725,12 @@ cdef class CompressionType(object):
zstdnotfinal_compression = u'zstdnotfinal_compression'
disable_compression = u'disable_compression'
cdef class CompactionPri(object):
by_compensated_size = u'by_compensated_size'
oldest_largest_seq_first = u'oldest_largest_seq_first'
oldest_smallest_seq_first = u'oldest_smallest_seq_first'
min_overlapping_ratio = u'min_overlapping_ratio'
cdef class Options(object):
cdef options.Options* opts
cdef PyComparator py_comparator
@ -829,6 +835,27 @@ cdef class Options(object):
if 'max_dict_bytes' in value:
copts.max_dict_bytes = value['max_dict_bytes']
property compaction_pri:
def __get__(self):
if self.opts.compaction_pri == options.kByCompensatedSize:
return CompactionPri.by_compensated_size
if self.opts.compaction_pri == options.kOldestLargestSeqFirst:
return CompactionPri.oldest_largest_seq_first
if self.opts.compaction_pri == options.kOldestSmallestSeqFirst:
return CompactionPri.oldest_smallest_seq_first
if self.opts.compaction_pri == options.kMinOverlappingRatio:
return CompactionPri.min_overlapping_ratio
def __set__(self, value):
if value == CompactionPri.by_compensated_size:
self.opts.compaction_pri = options.kByCompensatedSize
elif value == CompactionPri.oldest_largest_seq_first:
self.opts.compaction_pri = options.kOldestLargestSeqFirst
elif value == CompactionPri.oldest_smallest_seq_first:
self.opts.compaction_pri = options.kOldestSmallestSeqFirst
elif value == CompactionPri.min_overlapping_ratio:
self.opts.compaction_pri = options.kMinOverlappingRatio
else:
raise TypeError("Unknown compaction pri: %s" % value)
property compression:

View file

@ -35,6 +35,17 @@ class TestOptions(unittest.TestCase):
with self.assertRaises(TypeError):
opts.merge_operator = "not an operator"
def test_compaction_pri(self):
opts = rocksdb.Options()
# default compaction_pri
self.assertEqual(opts.compaction_pri, rocksdb.CompactionPri.by_compensated_size)
opts.compaction_pri = rocksdb.CompactionPri.by_compensated_size
self.assertEqual(opts.compaction_pri, rocksdb.CompactionPri.by_compensated_size)
opts.compaction_pri = rocksdb.CompactionPri.oldest_largest_seq_first
self.assertEqual(opts.compaction_pri, rocksdb.CompactionPri.oldest_largest_seq_first)
opts.compaction_pri = rocksdb.CompactionPri.min_overlapping_ratio
self.assertEqual(opts.compaction_pri, rocksdb.CompactionPri.min_overlapping_ratio)
def test_compression_opts(self):
opts = rocksdb.Options()
compression_opts = opts.compression_opts