Move addPeer to raft state

pull/3372/head
Jason Wilder 2015-07-17 12:09:07 -06:00
parent 80248f9b53
commit 72e2e1a6f2
2 changed files with 25 additions and 13 deletions

View File

@ -24,6 +24,7 @@ type raftState interface {
raftEnabled() bool
sync(index uint64, timeout time.Duration) error
setPeers(addrs []string) error
addPeer(addr string) error
invalidate() error
close() error
}
@ -157,6 +158,24 @@ func (r *localRaft) sync(index uint64, timeout time.Duration) error {
}
}
// addPeer adds addr to the list of peers in the cluster.
func (r *localRaft) addPeer(addr string) error {
s := r.store
peers, err := s.peerStore.Peers()
if err != nil {
return err
}
if len(peers) >= 3 {
return nil
}
if fut := s.raft.AddPeer(addr); fut.Error() != nil {
return fut.Error()
}
return nil
}
// setPeers sets a list of peers in the cluster.
func (r *localRaft) setPeers(addrs []string) error {
a := make([]string, len(addrs))
@ -228,6 +247,11 @@ func (r *remoteRaft) setPeers(addrs []string) error {
return nil
}
// addPeer adds addr to the list of peers in the cluster.
func (r *remoteRaft) addPeer(addr string) error {
return fmt.Errorf("cannot add peer using remote raft")
}
func (r *remoteRaft) openRaft() error {
go func() {
for {

View File

@ -447,19 +447,7 @@ func (s *Store) SetPeers(addrs []string) error {
// AddPeer adds addr to the list of peers in the cluster.
func (s *Store) AddPeer(addr string) error {
peers, err := s.peerStore.Peers()
if err != nil {
return err
}
if len(peers) >= 3 {
return nil
}
if fut := s.raft.AddPeer(addr); fut.Error() != nil {
return fut.Error()
}
return nil
return s.raftState.addPeer(addr)
}
// Peers returns the list of peers in the cluster.