diff --git a/kv/raftstore/node.go b/kv/raftstore/node.go index 48150679..6a44f8ce 100644 --- a/kv/raftstore/node.go +++ b/kv/raftstore/node.go @@ -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 +} diff --git a/kv/test_raftstore/cluster.go b/kv/test_raftstore/cluster.go index 11de7afd..f775611c 100644 --- a/kv/test_raftstore/cluster.go +++ b/kv/test_raftstore/cluster.go @@ -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) } diff --git a/kv/test_raftstore/cluster_test.go b/kv/test_raftstore/cluster_test.go new file mode 100644 index 00000000..866127ff --- /dev/null +++ b/kv/test_raftstore/cluster_test.go @@ -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 + } +}