Browse Source

server: remove return value of func run

Yicheng Qin 11 years ago
parent
commit
20c995c142
3 changed files with 13 additions and 9 deletions
  1. 7 3
      etcd/etcd.go
  2. 3 3
      etcd/participant.go
  3. 3 3
      etcd/standby.go

+ 7 - 3
etcd/etcd.go

@@ -198,7 +198,8 @@ func (s *Server) Run() error {
 			s.mode.Set(participantMode)
 			log.Printf("id=%x server.run mode=participantMode\n", s.id)
 			s.mu.Unlock()
-			next = s.p.run()
+			s.p.run()
+			next = standbyMode
 			if d != nil {
 				close(dStopc)
 			}
@@ -207,7 +208,8 @@ func (s *Server) Run() error {
 			s.mode.Set(standbyMode)
 			log.Printf("id=%x server.run mode=standbyMode\n", s.id)
 			s.mu.Unlock()
-			next = s.s.run()
+			s.s.run()
+			next = participantMode
 		case stopMode:
 			s.mode.Set(stopMode)
 			log.Printf("id=%x server.run mode=stopMode\n", s.id)
@@ -217,9 +219,11 @@ func (s *Server) Run() error {
 		default:
 			panic("unsupport mode")
 		}
-		if next != stopMode {
+		s.mu.Lock()
+		if !s.stopped {
 			s.id = genId()
 		}
+		s.mu.Unlock()
 	}
 }
 

+ 3 - 3
etcd/participant.go

@@ -152,7 +152,7 @@ func newParticipant(id int64, pubAddr string, raftPubAddr string, dir string, cl
 	return p, nil
 }
 
-func (p *participant) run() int64 {
+func (p *participant) run() {
 	defer p.w.Close()
 
 	if p.node.IsEmpty() {
@@ -207,7 +207,7 @@ func (p *participant) run() int64 {
 			node.Sync()
 		case <-p.stopc:
 			log.Printf("id=%x participant.stop\n", p.id)
-			return stopMode
+			return
 		}
 		if s := node.UnstableSnapshot(); !s.IsEmpty() {
 			if err := p.Recovery(s.Data); err != nil {
@@ -222,7 +222,7 @@ func (p *participant) run() int64 {
 		if node.IsRemoved() {
 			p.stop()
 			log.Printf("id=%x participant.end\n", p.id)
-			return standbyMode
+			return
 		}
 		if p.node.EntsLen() > defaultCompact {
 			d, err := p.Save()

+ 3 - 3
etcd/standby.go

@@ -62,7 +62,7 @@ func newStandby(client *v2client, peerHub *peerHub) *standby {
 	return s
 }
 
-func (s *standby) run() int64 {
+func (s *standby) run() {
 	syncDuration := time.Millisecond * 100
 	nodes := s.peerHub.getSeeds()
 	for {
@@ -70,7 +70,7 @@ func (s *standby) run() int64 {
 		case <-time.After(syncDuration):
 		case <-s.stopc:
 			log.Printf("standby.stop\n")
-			return stopMode
+			return
 		}
 
 		if update, err := s.syncCluster(nodes); err != nil {
@@ -84,7 +84,7 @@ func (s *standby) run() int64 {
 			continue
 		}
 		log.Printf("standby.end\n")
-		return participantMode
+		return
 	}
 }