mirror of https://github.com/ledisdb/ledisdb.git
update rocksdb
This commit is contained in:
parent
b5518dd14c
commit
b8cc69e50a
|
@ -60,7 +60,7 @@ Create a workspace and checkout ledisdb source
|
|||
+ Set ```ROCKSDB_DIR``` and ```SNAPPY_DIR``` to the actual install path in `dev.sh`.
|
||||
+ ```make```
|
||||
|
||||
|
||||
**Because RocksDB API may change sometimes, LedisDB may not build successfully. Now LedisDB supports RocksDB version 3.5 or newest master branch. **
|
||||
|
||||
|
||||
## HyperLevelDB support
|
||||
|
|
|
@ -77,7 +77,8 @@ type DB struct {
|
|||
|
||||
env *Env
|
||||
|
||||
opts *Options
|
||||
opts *Options
|
||||
blockOpts *BlockBasedTableOptions
|
||||
|
||||
//for default read and write options
|
||||
readOpts *ReadOptions
|
||||
|
@ -106,6 +107,7 @@ func (db *DB) open() error {
|
|||
|
||||
func (db *DB) initOptions(cfg *config.LevelDBConfig) {
|
||||
opts := NewOptions()
|
||||
blockOpts := NewBlockBasedTableOptions()
|
||||
|
||||
opts.SetCreateIfMissing(true)
|
||||
|
||||
|
@ -117,11 +119,11 @@ func (db *DB) initOptions(cfg *config.LevelDBConfig) {
|
|||
opts.SetEnv(db.env)
|
||||
|
||||
db.cache = NewLRUCache(cfg.CacheSize)
|
||||
opts.SetCache(db.cache)
|
||||
blockOpts.SetCache(db.cache)
|
||||
|
||||
//we must use bloomfilter
|
||||
db.filter = NewBloomFilter(defaultFilterBits)
|
||||
opts.SetFilterPolicy(db.filter)
|
||||
blockOpts.SetFilterPolicy(db.filter)
|
||||
|
||||
if !cfg.Compression {
|
||||
opts.SetCompression(NoCompression)
|
||||
|
@ -129,7 +131,7 @@ func (db *DB) initOptions(cfg *config.LevelDBConfig) {
|
|||
opts.SetCompression(SnappyCompression)
|
||||
}
|
||||
|
||||
opts.SetBlockSize(cfg.BlockSize)
|
||||
blockOpts.SetBlockSize(cfg.BlockSize)
|
||||
|
||||
opts.SetWriteBufferSize(cfg.WriteBufferSize)
|
||||
|
||||
|
@ -142,7 +144,10 @@ func (db *DB) initOptions(cfg *config.LevelDBConfig) {
|
|||
opts.SetLevel0StopWritesTrigger(64)
|
||||
opts.SetTargetFileSizeBase(32 * 1024 * 1024)
|
||||
|
||||
opts.SetBlockBasedTableFactory(blockOpts)
|
||||
|
||||
db.opts = opts
|
||||
db.blockOpts = blockOpts
|
||||
|
||||
db.readOpts = NewReadOptions()
|
||||
db.writeOpts = NewWriteOptions()
|
||||
|
@ -157,20 +162,22 @@ func (db *DB) Close() error {
|
|||
db.db = nil
|
||||
}
|
||||
|
||||
db.opts.Close()
|
||||
if db.filter != nil {
|
||||
db.filter.Close()
|
||||
}
|
||||
|
||||
if db.cache != nil {
|
||||
db.cache.Close()
|
||||
}
|
||||
|
||||
if db.filter != nil {
|
||||
db.filter.Close()
|
||||
}
|
||||
|
||||
if db.env != nil {
|
||||
db.env.Close()
|
||||
}
|
||||
|
||||
//db.blockOpts.Close()
|
||||
|
||||
db.opts.Close()
|
||||
|
||||
db.readOpts.Close()
|
||||
db.writeOpts.Close()
|
||||
db.iteratorOpts.Close()
|
||||
|
|
|
@ -25,6 +25,10 @@ type WriteOptions struct {
|
|||
Opt *C.rocksdb_writeoptions_t
|
||||
}
|
||||
|
||||
type BlockBasedTableOptions struct {
|
||||
Opt *C.rocksdb_block_based_table_options_t
|
||||
}
|
||||
|
||||
func NewOptions() *Options {
|
||||
opt := C.rocksdb_options_create()
|
||||
return &Options{opt}
|
||||
|
@ -40,6 +44,11 @@ func NewWriteOptions() *WriteOptions {
|
|||
return &WriteOptions{opt}
|
||||
}
|
||||
|
||||
func NewBlockBasedTableOptions() *BlockBasedTableOptions {
|
||||
opt := C.rocksdb_block_based_options_create()
|
||||
return &BlockBasedTableOptions{opt}
|
||||
}
|
||||
|
||||
func (o *Options) Close() {
|
||||
C.rocksdb_options_destroy(o.Opt)
|
||||
}
|
||||
|
@ -53,10 +62,6 @@ func (o *Options) SetErrorIfExists(error_if_exists bool) {
|
|||
C.rocksdb_options_set_error_if_exists(o.Opt, eie)
|
||||
}
|
||||
|
||||
func (o *Options) SetCache(cache *Cache) {
|
||||
C.rocksdb_options_set_cache(o.Opt, cache.Cache)
|
||||
}
|
||||
|
||||
func (o *Options) SetEnv(env *Env) {
|
||||
C.rocksdb_options_set_env(o.Opt, env.Env)
|
||||
}
|
||||
|
@ -73,14 +78,6 @@ func (o *Options) SetMaxOpenFiles(n int) {
|
|||
C.rocksdb_options_set_max_open_files(o.Opt, C.int(n))
|
||||
}
|
||||
|
||||
func (o *Options) SetBlockSize(s int) {
|
||||
C.rocksdb_options_set_block_size(o.Opt, C.size_t(s))
|
||||
}
|
||||
|
||||
func (o *Options) SetBlockRestartInterval(n int) {
|
||||
C.rocksdb_options_set_block_restart_interval(o.Opt, C.int(n))
|
||||
}
|
||||
|
||||
func (o *Options) SetCompression(t CompressionOpt) {
|
||||
C.rocksdb_options_set_compression(o.Opt, C.int(t))
|
||||
}
|
||||
|
@ -89,14 +86,6 @@ func (o *Options) SetCreateIfMissing(b bool) {
|
|||
C.rocksdb_options_set_create_if_missing(o.Opt, boolToUchar(b))
|
||||
}
|
||||
|
||||
func (o *Options) SetFilterPolicy(fp *FilterPolicy) {
|
||||
var policy *C.rocksdb_filterpolicy_t
|
||||
if fp != nil {
|
||||
policy = fp.Policy
|
||||
}
|
||||
C.rocksdb_options_set_filter_policy(o.Opt, policy)
|
||||
}
|
||||
|
||||
func (o *Options) SetMaxWriteBufferNumber(n int) {
|
||||
C.rocksdb_options_set_max_write_buffer_number(o.Opt, C.int(n))
|
||||
}
|
||||
|
@ -141,6 +130,34 @@ func (o *Options) SetMaxBytesForLevelMultiplier(n int) {
|
|||
C.rocksdb_options_set_max_bytes_for_level_multiplier(o.Opt, C.int(n))
|
||||
}
|
||||
|
||||
func (o *Options) SetBlockBasedTableFactory(opt *BlockBasedTableOptions) {
|
||||
C.rocksdb_options_set_block_based_table_factory(o.Opt, opt.Opt)
|
||||
}
|
||||
|
||||
func (o *BlockBasedTableOptions) Close() {
|
||||
C.rocksdb_block_based_options_destroy(o.Opt)
|
||||
}
|
||||
|
||||
func (o *BlockBasedTableOptions) SetFilterPolicy(fp *FilterPolicy) {
|
||||
var policy *C.rocksdb_filterpolicy_t
|
||||
if fp != nil {
|
||||
policy = fp.Policy
|
||||
}
|
||||
C.rocksdb_block_based_options_set_filter_policy(o.Opt, policy)
|
||||
}
|
||||
|
||||
func (o *BlockBasedTableOptions) SetBlockSize(s int) {
|
||||
C.rocksdb_block_based_options_set_block_size(o.Opt, C.size_t(s))
|
||||
}
|
||||
|
||||
func (o *BlockBasedTableOptions) SetBlockRestartInterval(n int) {
|
||||
C.rocksdb_block_based_options_set_block_restart_interval(o.Opt, C.int(n))
|
||||
}
|
||||
|
||||
func (o *BlockBasedTableOptions) SetCache(cache *Cache) {
|
||||
C.rocksdb_block_based_options_set_block_cache(o.Opt, cache.Cache)
|
||||
}
|
||||
|
||||
func (ro *ReadOptions) Close() {
|
||||
C.rocksdb_readoptions_destroy(ro.Opt)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue