[kv/util/engine_util] remove dependence on config, making the code more concise and efficient (#215)

This commit is contained in:
Binacs 2020-08-04 14:00:43 +08:00 committed by GitHub
parent e55ab1a6d0
commit 6998f4c47a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 7 additions and 9 deletions

View File

@ -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}

View File

@ -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
}

View File

@ -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)