Skip to content

Commit

Permalink
[kv/util/engine_util] remove dependence on config, making the code mo…
Browse files Browse the repository at this point in the history
…re concise and efficient (talent-plan#215)
  • Loading branch information
binacs authored Aug 4, 2020
1 parent e55ab1a commit 6998f4c
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 9 deletions.
4 changes: 2 additions & 2 deletions kv/storage/raft_storage/raft_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
4 changes: 2 additions & 2 deletions kv/test_raftstore/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
8 changes: 3 additions & 5 deletions kv/util/engine_util/engines.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 6998f4c

Please sign in to comment.