mirror of
https://github.com/talent-plan/tinykv.git
synced 2025-01-01 07:50:11 +08:00
39 lines
910 B
Go
39 lines
910 B
Go
|
package util
|
||
|
|
||
|
import (
|
||
|
"io/ioutil"
|
||
|
|
||
|
"github.com/Connor1996/badger"
|
||
|
"github.com/pingcap-incubator/tinykv/kv/util/engine_util"
|
||
|
)
|
||
|
|
||
|
func NewTestEngines() *engine_util.Engines {
|
||
|
engines := new(engine_util.Engines)
|
||
|
var err error
|
||
|
engines.KvPath, err = ioutil.TempDir("", "tinykv_kv")
|
||
|
if err != nil {
|
||
|
panic("create kv dir failed")
|
||
|
}
|
||
|
kvOpts := badger.DefaultOptions
|
||
|
kvOpts.Dir = engines.KvPath
|
||
|
kvOpts.ValueDir = engines.KvPath
|
||
|
kvOpts.ValueThreshold = 256
|
||
|
engines.Kv, err = badger.Open(kvOpts)
|
||
|
if err != nil {
|
||
|
panic("open kv db failed")
|
||
|
}
|
||
|
engines.RaftPath, err = ioutil.TempDir("", "tinykv_raft")
|
||
|
if err != nil {
|
||
|
panic("create raft dir failed")
|
||
|
}
|
||
|
raftOpts := badger.DefaultOptions
|
||
|
raftOpts.Dir = engines.RaftPath
|
||
|
raftOpts.ValueDir = engines.RaftPath
|
||
|
raftOpts.ValueThreshold = 256
|
||
|
engines.Raft, err = badger.Open(raftOpts)
|
||
|
if err != nil {
|
||
|
panic("open raft db failed")
|
||
|
}
|
||
|
return engines
|
||
|
}
|