diff --git a/README.md b/README.md index 07437da..1dacb7b 100644 --- a/README.md +++ b/README.md @@ -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 @@ -89,11 +89,11 @@ Choosing a store database to use is very simple, you have two ways: Flag command set will overwrite config set. -**Caveat** +## Lua support -+ You must known that changing store database runtime is very dangerous, LedisDB will not guarantee the data validation if you do it. -+ Begin a transaction will block any other write operators before you call `commit` or `rollback`. Don't use long-time transaction. -+ `pcall` and `xpcall` are not supported in lua, you can see the readme in [golua](https://github.com/aarzilli/golua). ++ You must install lua by yourself first and be sure that `golua` can find and link it. ++ `go get -u github.com/siddontang/golua/lua` ++ `make` ## Configuration @@ -159,6 +159,12 @@ See [Issues todo](https://github.com/siddontang/ledisdb/issues?labels=todo&page= + [GoDoc](https://godoc.org/github.com/siddontang/ledisdb) + [Server Commands](https://github.com/siddontang/ledisdb/wiki/Commands) +## Caveat + ++ You must known that changing store database runtime is very dangerous, LedisDB will not guarantee the data validation if you do it. ++ Begin a transaction will block any other write operators before you call `commit` or `rollback`. Don't use long-time transaction. ++ `pcall` and `xpcall` are not supported in lua, you can see the readme in [golua](https://github.com/aarzilli/golua). + ## Thanks diff --git a/doc/commands.md b/doc/commands.md index d3c3b39..4dbaa92 100644 --- a/doc/commands.md +++ b/doc/commands.md @@ -2497,7 +2497,6 @@ The optional parameter can be used to select a specific section of information: + server: General information about the Redis server + client: Client connections section + mem: Memory consumption related information -+ cpu: CPU consumption statistics + goroutine: Goroutine num + persistence: Strorage related information diff --git a/store/rocksdb/db.go b/store/rocksdb/db.go index 90183f6..cc1ab81 100644 --- a/store/rocksdb/db.go +++ b/store/rocksdb/db.go @@ -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() diff --git a/store/rocksdb/options.go b/store/rocksdb/options.go index aaa9a06..878ccf1 100644 --- a/store/rocksdb/options.go +++ b/store/rocksdb/options.go @@ -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) }