Move setPeers to raft state

pull/3372/head
Jason Wilder 2015-07-17 12:03:04 -06:00
parent 9e4339753f
commit b86fecfd80
2 changed files with 20 additions and 9 deletions

View File

@ -4,6 +4,7 @@ import (
"errors"
"fmt"
"math/rand"
"net"
"os"
"path/filepath"
"time"
@ -23,6 +24,7 @@ type raftState interface {
leaderCh() <-chan bool
raftEnabled() bool
sync(index uint64, timeout time.Duration) error
setPeers(addrs []string) error
invalidate() error
close() error
}
@ -156,6 +158,19 @@ func (r *localRaft) sync(index uint64, timeout time.Duration) error {
}
}
// setPeers sets a list of peers in the cluster.
func (r *localRaft) setPeers(addrs []string) error {
a := make([]string, len(addrs))
for i, s := range addrs {
addr, err := net.ResolveTCPAddr("tcp", s)
if err != nil {
return fmt.Errorf("cannot resolve addr: %s, err=%s", s, err)
}
a[i] = addr.String()
}
return r.store.raft.SetPeers(a).Error()
}
func (r *localRaft) leader() string {
if r.store.raft == nil {
return ""
@ -221,6 +236,10 @@ func (r *remoteRaft) invalidate() error {
return nil
}
func (r *remoteRaft) setPeers(addrs []string) error {
return nil
}
func (r *remoteRaft) openRaft() error {
go func() {
for {

View File

@ -448,15 +448,7 @@ func (s *Store) LeaderCh() <-chan bool {
// SetPeers sets a list of peers in the cluster.
func (s *Store) SetPeers(addrs []string) error {
a := make([]string, len(addrs))
for i, s := range addrs {
addr, err := net.ResolveTCPAddr("tcp", s)
if err != nil {
return fmt.Errorf("cannot resolve addr: %s, err=%s", s, err)
}
a[i] = addr.String()
}
return s.raft.SetPeers(a).Error()
return s.raftState.setPeers(addrs)
}
// AddPeer adds addr to the list of peers in the cluster.