Add examples to use the 'table_factory' and 'memtable_factory'
This commit is contained in:
parent
1cb9ec4ee1
commit
68c58009f2
2 changed files with 59 additions and 2 deletions
|
@ -661,7 +661,7 @@ Options object
|
|||
|
||||
Factory for the files forming the persisten data storage.
|
||||
Sometimes they are also named SST-Files. Right now you can assign
|
||||
instances of the following classes
|
||||
instances of the following classes.
|
||||
|
||||
* :py:class:`rocksdb.BlockBasedTableFactory`
|
||||
* :py:class:`rocksdb.PlainTableFactory`
|
||||
|
@ -803,6 +803,8 @@ LRUCache
|
|||
the least-used order. If not enough space is freed, further free the
|
||||
entries in least used order.
|
||||
|
||||
.. _table_factories_label:
|
||||
|
||||
TableFactories
|
||||
==============
|
||||
|
||||
|
@ -816,7 +818,7 @@ Instances of this classes can assigned to :py:attr:`rocksdb.Options.table_factor
|
|||
for low query latency on pure-memory or really low-latency media.
|
||||
|
||||
Tutorial of rocksdb table formats is available here:
|
||||
https://github.com/facebook/rocksdb/wiki/A-Tutorial-of-RocksDB-SST-formats
|
||||
https://github.com/facebook/rocksdb/wiki/A-Tutorial-of-RocksDB-SST-formats
|
||||
|
||||
.. py:class:: rocksdb.BlockBasedTableFactory
|
||||
|
||||
|
|
|
@ -270,3 +270,58 @@ The two arguments are the db_dir and wal_dir, which are mostly the same. ::
|
|||
|
||||
backup = rocksdb.BackupEngine("test.db/backups")
|
||||
backup.restore_latest_backup("test.db", "test.db")
|
||||
|
||||
|
||||
Change Memtable or SST implementations
|
||||
======================================
|
||||
|
||||
As noted here :ref:`memtable_factories_label`, RocksDB offers different implementations for the memtable
|
||||
representation. Per default :py:class:`rocksdb.SkipListMemtableFactory` is used,
|
||||
but changeing it to a different one is veary easy.
|
||||
|
||||
Here is an example for HashSkipList-MemtableFactory.
|
||||
Keep in mind: To use the hashed based MemtableFactories you must set
|
||||
:py:attr:`rocksdb.Options.prefix_extractor`.
|
||||
In this example all keys have a static prefix of len 5. ::
|
||||
|
||||
class StaticPrefix(rocksdb.interfaces.SliceTransform):
|
||||
def name(self):
|
||||
return b'static'
|
||||
|
||||
def transform(self, src):
|
||||
return (0, 5)
|
||||
|
||||
def in_domain(self, src):
|
||||
return len(src) >= 5
|
||||
|
||||
def in_range(self, dst):
|
||||
return len(dst) == 5
|
||||
|
||||
|
||||
opts = rocksdb.Options()
|
||||
opts.prefix_extractor = StaticPrefix()
|
||||
opts.memtable_factory = rocksdb.HashSkipListMemtableFactory()
|
||||
opts.create_if_missing = True
|
||||
|
||||
db = rocksdb.DB("test.db", opts)
|
||||
db.put(b'00001.x', b'x')
|
||||
db.put(b'00001.y', b'y')
|
||||
db.put(b'00002.x', b'x')
|
||||
|
||||
For initial bulk loads the Vector-MemtableFactory makes sense. ::
|
||||
|
||||
opts = rocksdb.Options()
|
||||
opts.memtable_factory = rocksdb.VectorMemtableFactory()
|
||||
opts.create_if_missing = True
|
||||
|
||||
db = rocksdb.DB("test.db", opts)
|
||||
|
||||
As noted here :ref:`table_factories_label`, it is also possible to change the
|
||||
representation of the final data files.
|
||||
Here is an example how to use one of the 'PlainTables'. ::
|
||||
|
||||
opts = rocksdb.Options()
|
||||
opts.table_factory = rocksdb.TotalOrderPlainTableFactory()
|
||||
opts.create_if_missing = True
|
||||
|
||||
db = rocksdb.DB("test.db", opts)
|
||||
|
|
Loading…
Reference in a new issue