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 }