mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
raft: block Stop() on n.done, support idempotency
This commit is contained in:
12
raft/node.go
12
raft/node.go
@@ -210,8 +210,15 @@ func newNode() node {
|
||||
}
|
||||
|
||||
func (n *node) Stop() {
|
||||
n.stop <- struct{}{}
|
||||
<-n.stop
|
||||
select {
|
||||
case n.stop <- struct{}{}:
|
||||
// Not already stopped, so trigger it
|
||||
case <-n.done:
|
||||
// Node has already been stopped - no need to do anything
|
||||
return
|
||||
}
|
||||
// Block until the stop has been acknowledged by run()
|
||||
<-n.done
|
||||
}
|
||||
|
||||
func (n *node) run(r *raft) {
|
||||
@@ -306,7 +313,6 @@ func (n *node) run(r *raft) {
|
||||
r.raftLog.stableTo(prevLastUnstablei)
|
||||
advancec = nil
|
||||
case <-n.stop:
|
||||
n.stop <- struct{}{}
|
||||
close(n.done)
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user