mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
raft: remove return bool
This commit is contained in:
committed by
Yicheng Qin
parent
022a663e91
commit
9616162dbc
@@ -104,6 +104,18 @@ func (n *Node) Propose(ctx context.Context, data []byte) error {
|
||||
}
|
||||
}
|
||||
|
||||
// func (n *Node) SingleFlightPropose(ctx context.Context, id string, data []byte) error {
|
||||
// ch := n.getSingleFlightChan(id)
|
||||
// select {
|
||||
// case ch <- data:
|
||||
// return nil
|
||||
// case <-ctx.Done():
|
||||
// return ctx.Err()
|
||||
// case <-n.ctx.Done():
|
||||
// return n.ctx.Err()
|
||||
// }
|
||||
// }
|
||||
|
||||
// Step advances the state machine using m.
|
||||
func (n *Node) Step(m Message) error {
|
||||
select {
|
||||
|
||||
@@ -405,9 +405,9 @@ func (r *raft) removeNode(id int64) {
|
||||
r.pendingConf = false
|
||||
}
|
||||
|
||||
type stepFunc func(r *raft, m Message) bool
|
||||
type stepFunc func(r *raft, m Message)
|
||||
|
||||
func stepLeader(r *raft, m Message) bool {
|
||||
func stepLeader(r *raft, m Message) {
|
||||
switch m.Type {
|
||||
case msgBeat:
|
||||
r.bcastHeartbeat()
|
||||
@@ -418,7 +418,7 @@ func stepLeader(r *raft, m Message) bool {
|
||||
e := m.Entries[0]
|
||||
if e.isConfig() {
|
||||
if r.pendingConf {
|
||||
return false
|
||||
panic("pending conf")
|
||||
}
|
||||
r.pendingConf = true
|
||||
}
|
||||
@@ -437,13 +437,12 @@ func stepLeader(r *raft, m Message) bool {
|
||||
case msgVote:
|
||||
r.send(Message{To: m.From, Type: msgVoteResp, Index: -1})
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func stepCandidate(r *raft, m Message) bool {
|
||||
func stepCandidate(r *raft, m Message) {
|
||||
switch m.Type {
|
||||
case msgProp:
|
||||
return false
|
||||
panic("no leader")
|
||||
case msgApp:
|
||||
r.becomeFollower(r.Term, m.From)
|
||||
r.handleAppendEntries(m)
|
||||
@@ -462,14 +461,13 @@ func stepCandidate(r *raft, m Message) bool {
|
||||
r.becomeFollower(r.Term, none)
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func stepFollower(r *raft, m Message) bool {
|
||||
func stepFollower(r *raft, m Message) {
|
||||
switch m.Type {
|
||||
case msgProp:
|
||||
if r.lead.Get() == none {
|
||||
return false
|
||||
panic("no leader")
|
||||
}
|
||||
m.To = r.lead.Get()
|
||||
r.send(m)
|
||||
@@ -486,7 +484,6 @@ func stepFollower(r *raft, m Message) bool {
|
||||
r.send(Message{To: m.From, Type: msgVoteResp, Index: -1})
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func (r *raft) compact(d []byte) {
|
||||
|
||||
@@ -629,7 +629,12 @@ func TestConf(t *testing.T) {
|
||||
}
|
||||
|
||||
// deny the second configuration change request if there is a pending one
|
||||
paniced := false
|
||||
defer func() { recover(); paniced = true }()
|
||||
sm.Step(Message{From: 0, To: 0, Type: msgProp, Entries: []Entry{{Type: AddNode}}})
|
||||
if !paniced {
|
||||
t.Errorf("expected panic")
|
||||
}
|
||||
if sm.raftLog.lastIndex() != 2 {
|
||||
t.Errorf("lastindex = %d, want %d", sm.raftLog.lastIndex(), 1)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user