mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
raft: make peers a prviate field in raft.Config
This commit is contained in:
parent
abddef0f28
commit
b3fb052ad4
@ -141,7 +141,6 @@ type Peer struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// StartNode returns a new Node given configuration and a list of raft peers.
|
// StartNode returns a new Node given configuration and a list of raft peers.
|
||||||
// It ignores the given peer list in the given Config.
|
|
||||||
// It appends a ConfChangeAddNode entry for each given peer to the initial log.
|
// It appends a ConfChangeAddNode entry for each given peer to the initial log.
|
||||||
func StartNode(c *Config, peers []Peer) Node {
|
func StartNode(c *Config, peers []Peer) Node {
|
||||||
r := newRaft(c)
|
r := newRaft(c)
|
||||||
|
10
raft/raft.go
10
raft/raft.go
@ -55,12 +55,14 @@ func (st StateType) String() string {
|
|||||||
type Config struct {
|
type Config struct {
|
||||||
// ID is the identity of the local raft. ID cannot be 0.
|
// ID is the identity of the local raft. ID cannot be 0.
|
||||||
ID uint64
|
ID uint64
|
||||||
// Peers contains the IDs of all nodes (including self) in
|
|
||||||
|
// peers contains the IDs of all nodes (including self) in
|
||||||
// the raft cluster. It should only be set when starting a new
|
// the raft cluster. It should only be set when starting a new
|
||||||
// raft cluster.
|
// raft cluster.
|
||||||
// Restarting raft from previous configuration will panic if
|
// Restarting raft from previous configuration will panic if
|
||||||
// Peers is set.
|
// peers is set.
|
||||||
Peers []uint64
|
// peer is private and only used for testing right now.
|
||||||
|
peers []uint64
|
||||||
|
|
||||||
// ElectionTick is the election timeout. If a follower does not
|
// ElectionTick is the election timeout. If a follower does not
|
||||||
// receive any message from the leader of current term during
|
// receive any message from the leader of current term during
|
||||||
@ -161,7 +163,7 @@ func newRaft(c *Config) *raft {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err) // TODO(bdarnell)
|
panic(err) // TODO(bdarnell)
|
||||||
}
|
}
|
||||||
peers := c.Peers
|
peers := c.peers
|
||||||
if len(cs.Nodes) > 0 {
|
if len(cs.Nodes) > 0 {
|
||||||
if len(peers) > 0 {
|
if len(peers) > 0 {
|
||||||
// TODO(bdarnell): the peers argument is always nil except in
|
// TODO(bdarnell): the peers argument is always nil except in
|
||||||
|
@ -1884,7 +1884,7 @@ func idsBySize(size int) []uint64 {
|
|||||||
func newTestRaft(id uint64, peers []uint64, election, heartbeat int, storage Storage) *raft {
|
func newTestRaft(id uint64, peers []uint64, election, heartbeat int, storage Storage) *raft {
|
||||||
c := &Config{
|
c := &Config{
|
||||||
ID: id,
|
ID: id,
|
||||||
Peers: peers,
|
peers: peers,
|
||||||
ElectionTick: election,
|
ElectionTick: election,
|
||||||
HeartbeatTick: heartbeat,
|
HeartbeatTick: heartbeat,
|
||||||
Storage: storage,
|
Storage: storage,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user