mirror of
https://github.com/talent-plan/tinykv.git
synced 2025-01-13 13:50:43 +08:00
[kv/util/engine_util] remove dependence on config, making the code more concise and efficient (#215)
This commit is contained in:
parent
e55ab1a6d0
commit
6998f4c47a
@ -68,8 +68,8 @@ func NewRaftStorage(conf *config.Config) *RaftStorage {
|
||||
os.MkdirAll(raftPath, os.ModePerm)
|
||||
os.Mkdir(snapPath, os.ModePerm)
|
||||
|
||||
raftDB := engine_util.CreateDB("raft", conf)
|
||||
kvDB := engine_util.CreateDB("kv", conf)
|
||||
raftDB := engine_util.CreateDB(raftPath, true)
|
||||
kvDB := engine_util.CreateDB(kvPath, false)
|
||||
engines := engine_util.NewEngines(kvDB, raftDB, kvPath, raftPath)
|
||||
|
||||
return &RaftStorage{engines: engines, config: conf}
|
||||
|
@ -80,8 +80,8 @@ func (c *Cluster) Start() {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
raftDB := engine_util.CreateDB("raft", c.cfg)
|
||||
kvDB := engine_util.CreateDB("kv", c.cfg)
|
||||
raftDB := engine_util.CreateDB(raftPath, true)
|
||||
kvDB := engine_util.CreateDB(kvPath, false)
|
||||
engine := engine_util.NewEngines(kvDB, raftDB, kvPath, raftPath)
|
||||
c.engines[storeID] = engine
|
||||
}
|
||||
|
@ -2,10 +2,8 @@ package engine_util
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/Connor1996/badger"
|
||||
"github.com/pingcap-incubator/tinykv/kv/config"
|
||||
"github.com/pingcap-incubator/tinykv/log"
|
||||
)
|
||||
|
||||
@ -63,13 +61,13 @@ func (en *Engines) Destroy() error {
|
||||
}
|
||||
|
||||
// CreateDB creates a new Badger DB on disk at subPath.
|
||||
func CreateDB(subPath string, conf *config.Config) *badger.DB {
|
||||
func CreateDB(path string, raft bool) *badger.DB {
|
||||
opts := badger.DefaultOptions
|
||||
if subPath == "raft" {
|
||||
if raft {
|
||||
// Do not need to write blob for raft engine because it will be deleted soon.
|
||||
opts.ValueThreshold = 0
|
||||
}
|
||||
opts.Dir = filepath.Join(conf.DBPath, subPath)
|
||||
opts.Dir = path
|
||||
opts.ValueDir = opts.Dir
|
||||
if err := os.MkdirAll(opts.Dir, os.ModePerm); err != nil {
|
||||
log.Fatal(err)
|
||||
|
Loading…
Reference in New Issue
Block a user