Browse Source

etcd: glue

Xiang Li 11 years ago
parent
commit
7be945f59b
1 changed files with 8 additions and 6 deletions
  1. 8 6
      raft/node.go

+ 8 - 6
raft/node.go

@@ -12,7 +12,7 @@ type Interface interface {
 
 
 type tick int
 type tick int
 
 
-type config struct {
+type Config struct {
 	NodeId int
 	NodeId int
 	Addr   string
 	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}}})
 	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() }
 func (n *Node) Msgs() []Message { return n.sm.Msgs() }
 
 
@@ -83,14 +85,14 @@ func (n *Node) Next() []Entry {
 		switch ents[i].Type {
 		switch ents[i].Type {
 		case Normal:
 		case Normal:
 		case AddNode:
 		case AddNode:
-			c := new(config)
+			c := new(Config)
 			if err := json.Unmarshal(ents[i].Data, c); err != nil {
 			if err := json.Unmarshal(ents[i].Data, c); err != nil {
 				golog.Println(err)
 				golog.Println(err)
 				continue
 				continue
 			}
 			}
 			n.sm.addNode(c.NodeId)
 			n.sm.addNode(c.NodeId)
 		case RemoveNode:
 		case RemoveNode:
-			c := new(config)
+			c := new(Config)
 			if err := json.Unmarshal(ents[i].Data, c); err != nil {
 			if err := json.Unmarshal(ents[i].Data, c); err != nil {
 				golog.Println(err)
 				golog.Println(err)
 				continue
 				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)
 	data, err := json.Marshal(c)
 	if err != nil {
 	if err != nil {
 		panic(err)
 		panic(err)