func (s *Server) waitOnline() { s.mu.Lock() defer s.mu.Unlock() for { pi, err := s.top.GetProxyInfo(s.pi.Id) if err != nil { log.Fatal(errors.ErrorStack(err)) } if pi.State == models.PROXY_STATE_MARK_OFFLINE { s.handleMarkOffline() } if pi.State == models.PROXY_STATE_ONLINE { s.pi.State = pi.State println("good, we are on line", s.pi.Id) log.Info("we are online", s.pi.Id) _, err := s.top.WatchNode(path.Join(models.GetProxyPath(s.top.ProductName), s.pi.Id), s.evtbus) if err != nil { log.Fatal(errors.ErrorStack(err)) } return } println("wait to be online ", s.pi.Id) log.Warning(s.pi.Id, "wait to be online") time.Sleep(3 * time.Second) } }
func (top *Topology) Close(proxyName string) { zkhelper.DeleteRecursive(top.zkConn, path.Join(models.GetProxyPath(top.ProductName), proxyName), -1) top.zkConn.Close() }
func (s *Server) processAction(e interface{}) { start := time.Now() s.mu.Lock() defer s.mu.Unlock() if time.Since(start).Seconds() > 10 { log.Warning("take too long to get lock") } actPath := GetEventPath(e) if strings.Index(actPath, models.GetProxyPath(s.top.ProductName)) == 0 { //proxy event, should be order for me to suicide s.handleProxyCommand() return } //re-watch nodes, err := s.top.WatchChildren(models.GetWatchActionPath(s.top.ProductName), s.evtbus) if err != nil { log.Fatal(errors.ErrorStack(err)) } seqs, err := models.ExtraSeqList(nodes) if err != nil { log.Fatal(errors.ErrorStack(err)) } if len(seqs) == 0 || !s.top.IsChildrenChangedEvent(e) { return } //get last pos index := -1 for i, seq := range seqs { if s.lastActionSeq < seq { index = i break } } if index < 0 { log.Warningf("zookeeper restarted or actions were deleted ? lastActionSeq: %d", s.lastActionSeq) if s.lastActionSeq > seqs[len(seqs)-1] { log.Fatalf("unknown error, zookeeper restarted or actions were deleted ? lastActionSeq: %d, %v", s.lastActionSeq, nodes) } if s.lastActionSeq == seqs[len(seqs)-1] { //children change or delete event return } //actions node was remove by someone, seems we can handle it index = 0 } actions := seqs[index:] for _, seq := range actions { exist, err := s.top.Exist(path.Join(s.top.GetActionResponsePath(seq), s.pi.Id)) if err != nil { log.Fatal(errors.ErrorStack(err)) } if exist { continue } if s.checkAndDoTopoChange(seq) { s.responseAction(int64(seq)) } } s.lastActionSeq = seqs[len(seqs)-1] }