mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
raft: StartCluster -> Dictate
This commit is contained in:
parent
1a75beb57c
commit
7cdd148e24
@ -92,7 +92,7 @@ func buildCluster(size int) (nt *network, nodes []*Node) {
|
|||||||
}
|
}
|
||||||
nt = newNetwork(nis...)
|
nt = newNetwork(nis...)
|
||||||
|
|
||||||
nodes[0].StartCluster()
|
Dictate(nodes[0]).Next()
|
||||||
for i := 1; i < size; i++ {
|
for i := 1; i < size; i++ {
|
||||||
nt.send(nodes[0].newConfMessage(configAdd, &Config{NodeId: i}))
|
nt.send(nodes[0].newConfMessage(configAdd, &Config{NodeId: i}))
|
||||||
nodes[i].Start()
|
nodes[i].Start()
|
||||||
|
@ -50,14 +50,11 @@ func (n *Node) Propose(data []byte) {
|
|||||||
n.Step(m)
|
n.Step(m)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n *Node) StartCluster() {
|
func Dictate(n *Node) *Node {
|
||||||
if n.sm != nil {
|
|
||||||
panic("node is started")
|
|
||||||
}
|
|
||||||
n.sm = newStateMachine(n.addr, []int{n.addr})
|
n.sm = newStateMachine(n.addr, []int{n.addr})
|
||||||
n.Step(Message{Type: msgHup})
|
n.Step(Message{Type: msgHup})
|
||||||
n.Step(n.newConfMessage(configAdd, &Config{NodeId: n.addr}))
|
n.Step(n.newConfMessage(configAdd, &Config{NodeId: n.addr}))
|
||||||
n.Next()
|
return n
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n *Node) Start() {
|
func (n *Node) Start() {
|
||||||
|
@ -89,8 +89,8 @@ func TestResetElapse(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestStartCluster(t *testing.T) {
|
func TestStartCluster(t *testing.T) {
|
||||||
n := New(0, defaultHeartbeat, defaultElection)
|
n := Dictate(New(0, defaultHeartbeat, defaultElection))
|
||||||
n.StartCluster()
|
n.Next()
|
||||||
|
|
||||||
if len(n.sm.ins) != 1 {
|
if len(n.sm.ins) != 1 {
|
||||||
t.Errorf("k = %d, want 1", len(n.sm.ins))
|
t.Errorf("k = %d, want 1", len(n.sm.ins))
|
||||||
@ -104,8 +104,8 @@ func TestStartCluster(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestAdd(t *testing.T) {
|
func TestAdd(t *testing.T) {
|
||||||
n := New(0, defaultHeartbeat, defaultElection)
|
n := Dictate(New(0, defaultHeartbeat, defaultElection))
|
||||||
n.StartCluster()
|
n.Next()
|
||||||
n.Add(1)
|
n.Add(1)
|
||||||
n.Next()
|
n.Next()
|
||||||
|
|
||||||
@ -118,8 +118,8 @@ func TestAdd(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestRemove(t *testing.T) {
|
func TestRemove(t *testing.T) {
|
||||||
n := New(0, defaultHeartbeat, defaultElection)
|
n := Dictate(New(0, defaultHeartbeat, defaultElection))
|
||||||
n.StartCluster()
|
n.Next()
|
||||||
n.Add(1)
|
n.Add(1)
|
||||||
n.Next()
|
n.Next()
|
||||||
n.Remove(0)
|
n.Remove(0)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user