1
0
Fork 0

Merge pull request #1187 from rqlite/not-in-config-not-voter

Node not in configuration, it's not a voter
master
Philip O'Toole 2 years ago committed by GitHub
commit d3de6530db
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -511,22 +511,20 @@ func (s *Store) IsLeader() bool {
return s.raft.State() == raft.Leader return s.raft.State() == raft.Leader
} }
// IsVoter returns true if the current node is a voter in the cluster. // IsVoter returns true if the current node is a voter in the cluster. If there
// is no reference to the current node in the current cluster configuration then
// false will also be returned.
func (s *Store) IsVoter() (bool, error) { func (s *Store) IsVoter() (bool, error) {
cfg := s.raft.GetConfiguration() cfg := s.raft.GetConfiguration()
if err := cfg.Error(); err != nil { if err := cfg.Error(); err != nil {
return false, err return false, err
} }
if len(cfg.Configuration().Servers) == 0 {
return false, nil
}
for _, srv := range cfg.Configuration().Servers { for _, srv := range cfg.Configuration().Servers {
if srv.ID == raft.ServerID(s.raftID) { if srv.ID == raft.ServerID(s.raftID) {
return srv.Suffrage == raft.Voter, nil return srv.Suffrage == raft.Voter, nil
} }
} }
return false, fmt.Errorf("this node (id=%s) not found in configuration", s.raftID) return false, nil
} }
// State returns the current node's Raft state // State returns the current node's Raft state

Loading…
Cancel
Save