From a3f402c6bdda987f0d648bab575237476d69677c Mon Sep 17 00:00:00 2001 From: siddontang Date: Fri, 15 Aug 2014 10:46:48 +0800 Subject: [PATCH 1/3] lmdv add nosync config, fix hyperleveldb build bug --- config/config.go | 3 ++- config/config.json | 3 ++- config/config.toml | 1 + etc/ledis.conf | 1 + store/hyperleveldb.go | 2 ++ store/hyperleveldb_test.go | 2 ++ store/mdb/mdb.go | 9 ++++++++- 7 files changed, 18 insertions(+), 3 deletions(-) diff --git a/config/config.go b/config/config.go index 85ec414..0939afb 100644 --- a/config/config.go +++ b/config/config.go @@ -34,7 +34,8 @@ type LevelDBConfig struct { } type LMDBConfig struct { - MapSize int `toml:"map_size" json:"map_size"` + MapSize int `toml:"map_size" json:"map_size"` + NoSync bool `toml:"nosync" json:"nosync"` } type BinLogConfig struct { diff --git a/config/config.json b/config/config.json index 82bc668..2710e0a 100644 --- a/config/config.json +++ b/config/config.json @@ -14,7 +14,8 @@ }, "lmdb" : { - "map_size" : 524288000 + "map_size" : 524288000, + "nosync" : true }, "access_log" : "" diff --git a/config/config.toml b/config/config.toml index 6ef9a6c..573db9a 100644 --- a/config/config.toml +++ b/config/config.toml @@ -34,6 +34,7 @@ max_open_files = 1024 [lmdb] map_size = 524288000 +nosync = true [binlog] max_file_size = 0 diff --git a/etc/ledis.conf b/etc/ledis.conf index 8d92919..2097f65 100644 --- a/etc/ledis.conf +++ b/etc/ledis.conf @@ -36,6 +36,7 @@ max_open_files = 1024 [lmdb] map_size = 524288000 +nosync = true [binlog] # Set either size or num to 0 to disable binlog diff --git a/store/hyperleveldb.go b/store/hyperleveldb.go index f26631b..6ef70f1 100644 --- a/store/hyperleveldb.go +++ b/store/hyperleveldb.go @@ -1,3 +1,5 @@ +// +build hyperleveldb + package store import ( diff --git a/store/hyperleveldb_test.go b/store/hyperleveldb_test.go index 51bef8f..2d3a25b 100644 --- a/store/hyperleveldb_test.go +++ b/store/hyperleveldb_test.go @@ -1,3 +1,5 @@ +// +build hyperleveldb + package store import ( diff --git a/store/mdb/mdb.go b/store/mdb/mdb.go index 5a16463..ad767dc 100644 --- a/store/mdb/mdb.go +++ b/store/mdb/mdb.go @@ -23,6 +23,8 @@ type MDB struct { func (s Store) Open(path string, c *config.Config) (driver.IDB, error) { mapSize := c.LMDB.MapSize + noSync := c.LMDB.NoSync + if mapSize <= 0 { mapSize = 500 * 1024 * 1024 } @@ -48,7 +50,12 @@ func (s Store) Open(path string, c *config.Config) (driver.IDB, error) { } } - err = env.Open(path, mdb.NOSYNC|mdb.NOMETASYNC|mdb.WRITEMAP|mdb.MAPASYNC|mdb.CREATE, 0755) + var flags uint = mdb.CREATE + if noSync { + flags |= mdb.NOSYNC | mdb.NOMETASYNC | mdb.WRITEMAP | mdb.MAPASYNC + } + + err = env.Open(path, flags, 0755) if err != nil { return MDB{}, err } From ed9f1e9ac86f696c7552eb978b4f7a98d0516b87 Mon Sep 17 00:00:00 2001 From: siddontang Date: Fri, 15 Aug 2014 11:42:18 +0800 Subject: [PATCH 2/3] config test bugfix --- config/config_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/config/config_test.go b/config/config_test.go index 14620ec..943c513 100644 --- a/config/config_test.go +++ b/config/config_test.go @@ -18,6 +18,7 @@ func TestConfig(t *testing.T) { dstCfg.LevelDB.CacheSize = 524288000 dstCfg.LevelDB.MaxOpenFiles = 1024 dstCfg.LMDB.MapSize = 524288000 + dstCfg.LMDB.NoSync = true cfg, err := NewConfigWithFile("./config.toml") if err != nil { From 6c9d38fab762c0523418b7da44292df1edb231a8 Mon Sep 17 00:00:00 2001 From: wenyekui Date: Fri, 15 Aug 2014 11:32:26 +0800 Subject: [PATCH 3/3] bug fix: encode bitmap meta key --- ledis/t_bit.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ledis/t_bit.go b/ledis/t_bit.go index 37b788d..bc208a0 100644 --- a/ledis/t_bit.go +++ b/ledis/t_bit.go @@ -121,7 +121,7 @@ func (db *DB) bEncodeMetaKey(key []byte) []byte { mk[0] = db.index mk[1] = BitMetaType - copy(mk, key) + copy(mk[2:], key) return mk }