forked from mirror/ledisdb
mdv update
This commit is contained in:
parent
4f5e47e907
commit
727286d1ac
|
@ -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"
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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"`
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in New Issue