Sfoglia il codice sorgente

etcd: abstract out mode change logic

Xiang Li 11 anni fa
parent
commit
5d498918bf
1 ha cambiato i file con 1 aggiunte e 3 eliminazioni
  1. 1 3
      etcd/etcd.go

+ 1 - 3
etcd/etcd.go

@@ -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: