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:
ZYFZYF 2022-07-14 14:05:26 +08:00 committed by GitHub
parent d732002724
commit 5c800faefd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 33 additions and 5 deletions

View File

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

View File

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

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