Skip to content

Commit

Permalink
Add "row_cache" to options.
Browse files Browse the repository at this point in the history
  • Loading branch information
stephan-hof committed Aug 30, 2015
1 parent 6b54dc9 commit 01f1357
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
17 changes: 17 additions & 0 deletions rocksdb/_rocksdb.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -708,6 +708,7 @@ cdef class Options(object):
cdef PySliceTransform py_prefix_extractor
cdef PyTableFactory py_table_factory
cdef PyMemtableFactory py_memtable_factory
cdef PyCache py_row_cache

# Used to protect sharing of Options with many DB-objects
cdef cpp_bool in_use
Expand All @@ -727,6 +728,7 @@ cdef class Options(object):
self.py_prefix_extractor = None
self.py_table_factory = None
self.py_memtable_factory = None
self.py_row_cache = None

for key, value in kwargs.items():
setattr(self, key, value)
Expand Down Expand Up @@ -1210,6 +1212,21 @@ cdef class Options(object):
self.py_prefix_extractor = PySliceTransform(value)
self.opts.prefix_extractor = self.py_prefix_extractor.get_transformer()

property row_cache:
def __get__(self):
return self.py_row_cache

def __set__(self, value):
if value is None:
self.py_row_cache = None
self.opts.row_cache.reset()
elif not isinstance(value, PyCache):
raise Exception("row_cache must be a Cache object")
else:
self.py_row_cache = value
self.opts.row_cache = self.py_row_cache.get_cache()


# Forward declaration
cdef class Snapshot

Expand Down
2 changes: 2 additions & 0 deletions rocksdb/options.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ from slice_transform cimport SliceTransform
from table_factory cimport TableFactory
from memtablerep cimport MemTableRepFactory
from universal_compaction cimport CompactionOptionsUniversal
from cache cimport Cache

cdef extern from "rocksdb/options.h" namespace "rocksdb":
ctypedef enum CompactionStyle:
Expand Down Expand Up @@ -105,6 +106,7 @@ cdef extern from "rocksdb/options.h" namespace "rocksdb":
# TODO: table_properties_collectors
cpp_bool inplace_update_support
size_t inplace_update_num_locks
shared_ptr[Cache] row_cache

cdef cppclass WriteOptions:
cpp_bool sync
Expand Down
6 changes: 6 additions & 0 deletions rocksdb/tests/test_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,3 +96,9 @@ def test_compaction_opts_universal(self):
self.assertEqual(1, uopts['size_ratio'])
self.assertEqual(2, uopts['min_merge_width'])
self.assertEqual(30, uopts['max_merge_width'])

def test_row_cache(self):
opts = rocksdb.Options()
self.assertIsNone(opts.row_cache)
opts.row_cache = cache = rocksdb.LRUCache(2*1024*1024)
self.assertEqual(cache, opts.row_cache)

0 comments on commit 01f1357

Please sign in to comment.