etcd: abstract out mode change logic

release-2.0
Xiang Li 2014-07-18 08:44:43 -07:00 committed by Yicheng Qin
parent 4c324fe3a4
commit 5d498918bf
1 changed files with 1 additions and 3 deletions

View File

@ -129,22 +129,20 @@ func (s *Server) ServeRaftHTTP(w http.ResponseWriter, r *http.Request) {
func (s *Server) Run() {
next := participantMode
for {
s.modeC <- next
switch next {
case participantMode:
s.p = newParticipant(s.id, s.pubAddr, s.raftPubAddr, s.nodes, s.client, s.peerHub, s.tickDuration)
s.mode.Set(participantMode)
s.modeC <- s.mode.Get()
// TODO: it may block here. move modeC later.
next = s.p.run()
case standbyMode:
s.s = newStandby(s.id, s.pubAddr, s.raftPubAddr, s.nodes, s.client, s.peerHub)
s.mode.Set(standbyMode)
s.modeC <- s.mode.Get()
next = s.s.run()
case stopMode:
s.client.CloseConnections()
s.peerHub.stop()
s.modeC <- s.mode.Get()
s.stopc <- struct{}{}
return
default: