Move setPeers to raft state
parent
9e4339753f
commit
b86fecfd80
|
@ -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 {
|
||||
|
|
|
@ -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.
|
||||
|
|
Loading…
Reference in New Issue