aboutsummaryrefslogtreecommitdiff
path: root/weed/topology/topology.go
diff options
context:
space:
mode:
authorhasagi <30975629+LIBA-S@users.noreply.github.com>2020-09-22 21:38:38 +0800
committerGitHub <noreply@github.com>2020-09-22 21:38:38 +0800
commitd7bf2390e2bf4ac55132878faa68119b3558e8e4 (patch)
tree48ede45893c2130d3e039f7fe4af8440835eb02d /weed/topology/topology.go
parent37e964d4bd60a9dd792a9cc24f05eaa05d3766f2 (diff)
parentec5b9f1e91a8609d0e70bf9d26dc0840774153c4 (diff)
downloadseaweedfs-d7bf2390e2bf4ac55132878faa68119b3558e8e4.tar.xz
seaweedfs-d7bf2390e2bf4ac55132878faa68119b3558e8e4.zip
Merge pull request #1 from chrislusf/master
catch up
Diffstat (limited to 'weed/topology/topology.go')
-rw-r--r--weed/topology/topology.go27
1 files changed, 13 insertions, 14 deletions
diff --git a/weed/topology/topology.go b/weed/topology/topology.go
index 993f444a7..a11a1bac6 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,31 +66,29 @@ 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
+ for count := 0; count < 3; count++ {
+ 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)
+ }
}
-
return l, nil
}
func (t *Topology) Lookup(collection string, vid needle.VolumeId) (dataNodes []*DataNode) {
- //maybe an issue if lots of collections?
+ // maybe an issue if lots of collections?
if collection == "" {
for _, c := range t.collectionMap.Items() {
if list := c.(*Collection).Lookup(vid); list != nil {