mirror of
https://github.com/talent-plan/tinykv.git
synced 2024-12-25 20:30:30 +08:00
load snapshot meta again when the snapshot exists, make sure snapshot is not nil (#404)
* make every store really have a different dbPath Co-authored-by: Connor <zbk602423539@gmail.com>
This commit is contained in:
parent
d732002724
commit
5c800faefd
@ -206,3 +206,7 @@ func (n *Node) Stop() {
|
||||
func (n *Node) GetStoreID() uint64 {
|
||||
return n.store.GetId()
|
||||
}
|
||||
|
||||
func (n *Node) GetDBPath() string {
|
||||
return n.cfg.DBPath
|
||||
}
|
||||
|
@ -34,7 +34,7 @@ type Cluster struct {
|
||||
schedulerClient *MockSchedulerClient
|
||||
count int
|
||||
engines map[uint64]*engine_util.Engines
|
||||
snapPaths map[uint64]string
|
||||
dbPaths map[uint64]string
|
||||
dirs []string
|
||||
simulator Simulator
|
||||
cfg *config.Config
|
||||
@ -46,7 +46,7 @@ func NewCluster(count int, schedulerClient *MockSchedulerClient, simulator Simul
|
||||
count: count,
|
||||
schedulerClient: schedulerClient,
|
||||
engines: make(map[uint64]*engine_util.Engines),
|
||||
snapPaths: make(map[uint64]string),
|
||||
dbPaths: make(map[uint64]string),
|
||||
simulator: simulator,
|
||||
cfg: cfg,
|
||||
baseDir: "test-raftstore",
|
||||
@ -62,11 +62,10 @@ func (c *Cluster) Start() {
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
c.cfg.DBPath = dbPath
|
||||
c.dbPaths[storeID] = dbPath
|
||||
kvPath := filepath.Join(dbPath, "kv")
|
||||
raftPath := filepath.Join(dbPath, "raft")
|
||||
snapPath := filepath.Join(dbPath, "snap")
|
||||
c.snapPaths[storeID] = snapPath
|
||||
c.dirs = append(c.dirs, dbPath)
|
||||
|
||||
err = os.MkdirAll(kvPath, os.ModePerm)
|
||||
@ -167,7 +166,10 @@ func (c *Cluster) StopServer(storeID uint64) {
|
||||
|
||||
func (c *Cluster) StartServer(storeID uint64) {
|
||||
engine := c.engines[storeID]
|
||||
err := c.simulator.RunStore(c.cfg, engine, context.TODO())
|
||||
// do not share config because of different DBPath
|
||||
storeCfg := *c.cfg
|
||||
storeCfg.DBPath = c.dbPaths[storeID]
|
||||
err := c.simulator.RunStore(&storeCfg, engine, context.TODO())
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
22
kv/test_raftstore/cluster_test.go
Normal file
22
kv/test_raftstore/cluster_test.go
Normal file
@ -0,0 +1,22 @@
|
||||
package test_raftstore
|
||||
|
||||
import (
|
||||
"github.com/pingcap-incubator/tinykv/kv/config"
|
||||
"github.com/pingcap-incubator/tinykv/log"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestDifferentDBPath(t *testing.T) {
|
||||
cfg := config.NewTestConfig()
|
||||
cluster := NewTestCluster(5, cfg)
|
||||
cluster.Start()
|
||||
defer cluster.Shutdown()
|
||||
snapPaths := make(map[string]bool)
|
||||
for i := 1; i <= 5; i++ {
|
||||
path := cluster.simulator.(*NodeSimulator).nodes[uint64(i)].GetDBPath()
|
||||
log.Infof("DBPath of Store %v: %v", i, path)
|
||||
assert.False(t, snapPaths[path])
|
||||
snapPaths[path] = true
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user