aboutsummaryrefslogtreecommitdiff
path: root/weed
diff options
context:
space:
mode:
authorcheng.li01 <cheng.li01@aispeech.com>2020-08-10 16:37:47 +0800
committercheng.li01 <cheng.li01@aispeech.com>2020-08-10 16:37:47 +0800
commit25fbff5d52f0c74bd0ee55802ee20e80e0359f44 (patch)
tree0e85d3640fa84cf997f1a907f4e46c304379752b /weed
parentdad1161c7002d074ef87e4b9279881e4e4a6e426 (diff)
downloadseaweedfs-25fbff5d52f0c74bd0ee55802ee20e80e0359f44.tar.xz
seaweedfs-25fbff5d52f0c74bd0ee55802ee20e80e0359f44.zip
fix bug: two same volumeId in different collections
1, there will be two leader when master server startup in a few seconds 2, raft server will get a leader even there is only one master, so there is no need to do hard code to set the server to be leader
Diffstat (limited to 'weed')
-rw-r--r--weed/topology/topology.go27
1 files changed, 14 insertions, 13 deletions
diff --git a/weed/topology/topology.go b/weed/topology/topology.go
index 993f444a7..f93d2179c 100644
--- a/weed/topology/topology.go
+++ b/weed/topology/topology.go
@@ -5,6 +5,7 @@ import (
"fmt"
"math/rand"
"sync"
+ "time"
"github.com/chrislusf/raft"
@@ -65,26 +66,26 @@ func (t *Topology) IsLeader() bool {
if t.RaftServer.State() == raft.Leader {
return true
}
- if t.RaftServer.Leader() == "" {
- return true
- }
}
return false
}
func (t *Topology) Leader() (string, error) {
l := ""
- if t.RaftServer != nil {
- l = t.RaftServer.Leader()
- } else {
- return "", errors.New("Raft Server not ready yet!")
- }
-
- if l == "" {
- // We are a single node cluster, we are the leader
- return t.RaftServer.Name(), nil
+ count := 3
+ for count > 0 {
+ if t.RaftServer != nil {
+ l = t.RaftServer.Leader()
+ } else {
+ return "", errors.New("Raft Server not ready yet!")
+ }
+ if l != "" {
+ break
+ } else {
+ time.Sleep(time.Duration(5-count) * time.Second)
+ }
+ count -= 1
}
-
return l, nil
}