raft: make peers a prviate field in raft.Config

This commit is contained in:
Xiang Li 2015-03-24 11:10:07 -07:00
parent abddef0f28
commit b3fb052ad4
3 changed files with 7 additions and 6 deletions

View File

@ -141,7 +141,6 @@ type Peer struct {
}
// 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.
func StartNode(c *Config, peers []Peer) Node {
r := newRaft(c)

View File

@ -55,12 +55,14 @@ func (st StateType) String() string {
type Config struct {
// ID is the identity of the local raft. ID cannot be 0.
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
// raft cluster.
// Restarting raft from previous configuration will panic if
// Peers is set.
Peers []uint64
// peers is set.
// peer is private and only used for testing right now.
peers []uint64
// ElectionTick is the election timeout. If a follower does not
// receive any message from the leader of current term during
@ -161,7 +163,7 @@ func newRaft(c *Config) *raft {
if err != nil {
panic(err) // TODO(bdarnell)
}
peers := c.Peers
peers := c.peers
if len(cs.Nodes) > 0 {
if len(peers) > 0 {
// TODO(bdarnell): the peers argument is always nil except in

View File

@ -1884,7 +1884,7 @@ func idsBySize(size int) []uint64 {
func newTestRaft(id uint64, peers []uint64, election, heartbeat int, storage Storage) *raft {
c := &Config{
ID: id,
Peers: peers,
peers: peers,
ElectionTick: election,
HeartbeatTick: heartbeat,
Storage: storage,