diff options
Diffstat (limited to 'weed/topology/topology.go')
| -rw-r--r-- | weed/topology/topology.go | 27 |
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 { |
