From c1aeded2dd871239b63eb271b56b3a3f5a5b4c5c Mon Sep 17 00:00:00 2001 From: Konstantin Lebedev <9497591+kmlebedev@users.noreply.github.com> Date: Wed, 6 Apr 2022 12:18:43 +0500 Subject: [PATCH] force raft bootstrap avoid err bootstrap only works on new clusters --- weed/server/raft_hashicorp.go | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/weed/server/raft_hashicorp.go b/weed/server/raft_hashicorp.go index f36899d5c..3ce3ebcda 100644 --- a/weed/server/raft_hashicorp.go +++ b/weed/server/raft_hashicorp.go @@ -13,12 +13,18 @@ import ( "google.golang.org/grpc" "math/rand" "os" + "path" "path/filepath" "sort" "strings" "time" ) +const ( + ldbFile = "logs.dat" + sdbFile = "stable.dat" +) + func getPeerIdx(self pb.ServerAddress, mapPeers map[string]pb.ServerAddress) int { peers := make([]pb.ServerAddress, 0, len(mapPeers)) for _, peer := range mapPeers { @@ -108,14 +114,19 @@ func NewHashicorpRaftServer(option *RaftServerOption) (*RaftServer, error) { c.LogLevel = "Error" } + if option.RaftBootstrap { + os.RemoveAll(path.Join(s.dataDir, ldbFile)) + os.RemoveAll(path.Join(s.dataDir, sdbFile)) + os.RemoveAll(path.Join(s.dataDir, "snapshot")) + } baseDir := s.dataDir - ldb, err := boltdb.NewBoltStore(filepath.Join(baseDir, "logs.dat")) + ldb, err := boltdb.NewBoltStore(filepath.Join(baseDir, ldbFile)) if err != nil { return nil, fmt.Errorf(`boltdb.NewBoltStore(%q): %v`, filepath.Join(baseDir, "logs.dat"), err) } - sdb, err := boltdb.NewBoltStore(filepath.Join(baseDir, "stable.dat")) + sdb, err := boltdb.NewBoltStore(filepath.Join(baseDir, sdbFile)) if err != nil { return nil, fmt.Errorf(`boltdb.NewBoltStore(%q): %v`, filepath.Join(baseDir, "stable.dat"), err) }