mirror of
https://github.com/talent-plan/tinykv.git
synced 2024-12-28 05:40:10 +08:00
5e089a2cd1
Signed-off-by: Connor <zbk602423539@gmail.com> Co-authored-by: Nick Cameron <nrc@ncameron.org> Co-authored-by: linning <linningde25@gmail.com> Co-authored-by: YangKeao <keao.yang@yahoo.com> Co-authored-by: andylokandy <andylokandy@hotmail.com> Co-authored-by: Iosmanthus Teng <myosmanthustree@gmail.com>
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
|
|
}
|