From 7be945f59bef5a953530a4a8328fd3bc04690930 Mon Sep 17 00:00:00 2001 From: Xiang Li Date: Thu, 26 Jun 2014 13:48:59 -0700 Subject: [PATCH] etcd: glue --- raft/node.go | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/raft/node.go b/raft/node.go index 5b1b12d2f..4084a07f5 100644 --- a/raft/node.go +++ b/raft/node.go @@ -12,7 +12,7 @@ type Interface interface { type tick int -type config struct { +type Config struct { NodeId int Addr string } @@ -50,9 +50,11 @@ func (n *Node) propose(t int, data []byte) { n.Step(Message{Type: msgProp, Entries: []Entry{{Type: t, Data: data}}}) } -func (n *Node) Add(id int, addr string) { n.updateConf(AddNode, &config{NodeId: id, Addr: addr}) } +func (n *Node) Campaign() { n.Step(Message{Type: msgHup}) } -func (n *Node) Remove(id int) { n.updateConf(RemoveNode, &config{NodeId: id}) } +func (n *Node) Add(id int, addr string) { n.updateConf(AddNode, &Config{NodeId: id, Addr: addr}) } + +func (n *Node) Remove(id int) { n.updateConf(RemoveNode, &Config{NodeId: id}) } func (n *Node) Msgs() []Message { return n.sm.Msgs() } @@ -83,14 +85,14 @@ func (n *Node) Next() []Entry { switch ents[i].Type { case Normal: case AddNode: - c := new(config) + c := new(Config) if err := json.Unmarshal(ents[i].Data, c); err != nil { golog.Println(err) continue } n.sm.addNode(c.NodeId) case RemoveNode: - c := new(config) + c := new(Config) if err := json.Unmarshal(ents[i].Data, c); err != nil { golog.Println(err) continue @@ -123,7 +125,7 @@ func (n *Node) Tick() { } } -func (n *Node) updateConf(t int, c *config) { +func (n *Node) updateConf(t int, c *Config) { data, err := json.Marshal(c) if err != nil { panic(err)