mirror of https://github.com/ledisdb/ledisdb.git
mdv update
This commit is contained in:
parent
4f5e47e907
commit
727286d1ac
|
@ -6,7 +6,8 @@
|
||||||
"block_size": 32768,
|
"block_size": 32768,
|
||||||
"write_buffer_size": 67108864,
|
"write_buffer_size": 67108864,
|
||||||
"cache_size": 524288000,
|
"cache_size": 524288000,
|
||||||
"max_open_files":1024
|
"max_open_files":1024,
|
||||||
|
"map_size" : 524288000
|
||||||
},
|
},
|
||||||
|
|
||||||
"access_log" : "access.log"
|
"access_log" : "access.log"
|
||||||
|
|
|
@ -15,6 +15,7 @@ type Config struct {
|
||||||
WriteBufferSize int `json:"write_buffer_size"`
|
WriteBufferSize int `json:"write_buffer_size"`
|
||||||
CacheSize int `json:"cache_size"`
|
CacheSize int `json:"cache_size"`
|
||||||
MaxOpenFiles int `json:"max_open_files"`
|
MaxOpenFiles int `json:"max_open_files"`
|
||||||
|
MapSize int `json:"map_size"`
|
||||||
} `json:"db"`
|
} `json:"db"`
|
||||||
|
|
||||||
BinLog struct {
|
BinLog struct {
|
||||||
|
|
|
@ -18,6 +18,7 @@ type Config struct {
|
||||||
WriteBufferSize int `json:"write_buffer_size"`
|
WriteBufferSize int `json:"write_buffer_size"`
|
||||||
CacheSize int `json:"cache_size"`
|
CacheSize int `json:"cache_size"`
|
||||||
MaxOpenFiles int `json:"max_open_files"`
|
MaxOpenFiles int `json:"max_open_files"`
|
||||||
|
MapSize int `json:"map_size"`
|
||||||
} `json:"db"`
|
} `json:"db"`
|
||||||
|
|
||||||
BinLog struct {
|
BinLog struct {
|
||||||
|
|
|
@ -1,17 +1,17 @@
|
||||||
package store
|
package store
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
Name string
|
Name string `json:"name"`
|
||||||
|
|
||||||
Path string
|
Path string `json:"path"`
|
||||||
|
|
||||||
//for leveldb, goleveldb
|
//for leveldb, goleveldb
|
||||||
Compression bool
|
Compression bool `json:"compression"`
|
||||||
BlockSize int
|
BlockSize int `json:"block_size"`
|
||||||
WriteBufferSize int
|
WriteBufferSize int `json:"write_buffer_size"`
|
||||||
CacheSize int
|
CacheSize int `json:"cache_size"`
|
||||||
MaxOpenFiles int
|
MaxOpenFiles int `json:"max_open_files"`
|
||||||
|
|
||||||
//for lmdb
|
//for lmdb
|
||||||
MapSize int
|
MapSize int `json:"map_size"`
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,6 +27,6 @@ func (w *WriteBatch) Commit() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *WriteBatch) Rollback() error {
|
func (w *WriteBatch) Rollback() error {
|
||||||
w.wb = []Write{}
|
w.wb = w.wb[0:0]
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,7 +20,7 @@ type MDB struct {
|
||||||
func Open(c *Config) (MDB, error) {
|
func Open(c *Config) (MDB, error) {
|
||||||
path := c.Path
|
path := c.Path
|
||||||
if c.MapSize == 0 {
|
if c.MapSize == 0 {
|
||||||
c.MapSize = 10 * 1024 * 1024
|
c.MapSize = 1024 * 1024 * 1024
|
||||||
}
|
}
|
||||||
|
|
||||||
env, err := mdb.NewEnv()
|
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 {
|
if err != nil {
|
||||||
return MDB{}, err
|
return MDB{}, err
|
||||||
}
|
}
|
||||||
|
@ -77,7 +77,12 @@ func Repair(c *Config) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (db MDB) Put(key, value []byte) 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 {
|
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 {
|
func (db MDB) Delete(key []byte) error {
|
||||||
itr := db.iterator(false)
|
itr := db.iterator(false)
|
||||||
|
defer itr.Close()
|
||||||
|
|
||||||
itr.key, itr.value, itr.err = itr.c.Get(key, mdb.SET)
|
itr.key, itr.value, itr.err = itr.c.Get(key, mdb.SET)
|
||||||
if itr.err == nil {
|
if itr.err == nil {
|
||||||
itr.err = itr.c.Del(0)
|
itr.err = itr.c.Del(0)
|
||||||
}
|
}
|
||||||
itr.setState()
|
itr.setState()
|
||||||
return itr.Close()
|
return itr.Error()
|
||||||
}
|
}
|
||||||
|
|
||||||
type MDBIterator struct {
|
type MDBIterator struct {
|
||||||
|
|
Loading…
Reference in New Issue