Skip to content

Commit

Permalink
Remove unnecessary timeout in WaitForLeader()
Browse files Browse the repository at this point in the history
If the timer expires and a leader is still not selected, the local data node will never be created.
cannium committed Jul 9, 2015
1 parent 8b67872 commit c41ef86
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions meta/store.go
Original file line number Diff line number Diff line change
@@ -352,7 +352,7 @@ func (s *Store) init() {
// Writes the id of the node to file on success.
func (s *Store) createLocalNode() error {
// Wait for leader.
if err := s.WaitForLeader(5 * time.Second); err != nil {
if err := s.WaitForLeader(0); err != nil {
return fmt.Errorf("wait for leader: %s", err)
}

@@ -382,6 +382,7 @@ func (s *Store) Snapshot() error {
}

// WaitForLeader sleeps until a leader is found or a timeout occurs.
// timeout == 0 means to wait forever.
func (s *Store) WaitForLeader(timeout time.Duration) error {
if s.raft.Leader() != "" {
return nil
@@ -399,7 +400,9 @@ func (s *Store) WaitForLeader(timeout time.Duration) error {
case <-s.closing:
return errors.New("closing")
case <-timer.C:
return errors.New("timeout")
if timeout != 0 {
return errors.New("timeout")
}
case <-ticker.C:
if s.raft.Leader() != "" {
return nil

0 comments on commit c41ef86

Please sign in to comment.