diff --git a/etc/ledis.json b/etc/ledis.json index 1631303..89eb922 100644 --- a/etc/ledis.json +++ b/etc/ledis.json @@ -6,7 +6,8 @@ "block_size": 32768, "write_buffer_size": 67108864, "cache_size": 524288000, - "max_open_files":1024 + "max_open_files":1024, + "map_size" : 524288000 }, "access_log" : "access.log" diff --git a/ledis/config.go b/ledis/config.go index 5c2c1c1..ffe64d5 100644 --- a/ledis/config.go +++ b/ledis/config.go @@ -15,6 +15,7 @@ type Config struct { WriteBufferSize int `json:"write_buffer_size"` CacheSize int `json:"cache_size"` MaxOpenFiles int `json:"max_open_files"` + MapSize int `json:"map_size"` } `json:"db"` BinLog struct { diff --git a/server/config.go b/server/config.go index 13ab286..96fbd1a 100644 --- a/server/config.go +++ b/server/config.go @@ -18,6 +18,7 @@ type Config struct { WriteBufferSize int `json:"write_buffer_size"` CacheSize int `json:"cache_size"` MaxOpenFiles int `json:"max_open_files"` + MapSize int `json:"map_size"` } `json:"db"` BinLog struct { diff --git a/store/config.go b/store/config.go index b2939dc..16666a2 100644 --- a/store/config.go +++ b/store/config.go @@ -1,17 +1,17 @@ package store type Config struct { - Name string + Name string `json:"name"` - Path string + Path string `json:"path"` //for leveldb, goleveldb - Compression bool - BlockSize int - WriteBufferSize int - CacheSize int - MaxOpenFiles int + Compression bool `json:"compression"` + BlockSize int `json:"block_size"` + WriteBufferSize int `json:"write_buffer_size"` + CacheSize int `json:"cache_size"` + MaxOpenFiles int `json:"max_open_files"` //for lmdb - MapSize int + MapSize int `json:"map_size"` } diff --git a/store/mdb/batch.go b/store/mdb/batch.go index 60b6812..d8debf6 100644 --- a/store/mdb/batch.go +++ b/store/mdb/batch.go @@ -27,6 +27,6 @@ func (w *WriteBatch) Commit() error { } func (w *WriteBatch) Rollback() error { - w.wb = []Write{} + w.wb = w.wb[0:0] return nil } diff --git a/store/mdb/mdb.go b/store/mdb/mdb.go index 038121a..a737c6a 100644 --- a/store/mdb/mdb.go +++ b/store/mdb/mdb.go @@ -20,7 +20,7 @@ type MDB struct { func Open(c *Config) (MDB, error) { path := c.Path if c.MapSize == 0 { - c.MapSize = 10 * 1024 * 1024 + c.MapSize = 1024 * 1024 * 1024 } env, err := mdb.NewEnv() @@ -43,7 +43,7 @@ func Open(c *Config) (MDB, error) { } } - err = env.Open(path, mdb.WRITEMAP|mdb.MAPASYNC|mdb.CREATE, 0755) + err = env.Open(path, mdb.NOSYNC|mdb.NOMETASYNC|mdb.WRITEMAP|mdb.MAPASYNC|mdb.CREATE, 0755) if err != nil { return MDB{}, err } @@ -77,7 +77,12 @@ func Repair(c *Config) error { } func (db MDB) Put(key, value []byte) error { - return db.BatchPut([]Write{{key, value}}) + itr := db.iterator(false) + defer itr.Close() + + itr.err = itr.c.Put(key, value, 0) + itr.setState() + return itr.Error() } func (db MDB) BatchPut(writes []Write) error { @@ -118,13 +123,14 @@ func (db MDB) Get(key []byte) ([]byte, error) { func (db MDB) Delete(key []byte) error { itr := db.iterator(false) + defer itr.Close() itr.key, itr.value, itr.err = itr.c.Get(key, mdb.SET) if itr.err == nil { itr.err = itr.c.Del(0) } itr.setState() - return itr.Close() + return itr.Error() } type MDBIterator struct {