Skip to content

Commit

Permalink
fix: init server map when the map is empty
Browse files Browse the repository at this point in the history
  • Loading branch information
dougsong committed Dec 11, 2022
1 parent 55956ad commit 755d850
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions env/server/server.go
Expand Up @@ -73,21 +73,33 @@ func SetServers(configIp string, serverMap map[string]*config.ServerInfo) {
}

//SetDownNode 璁剧疆澶辨晥鑺傜偣
func SetDownNode(configIp string, host string) {
func SetDownNode(configService string, serverHost string) {
serverLock.Lock()
defer serverLock.Unlock()
s := ipMap[configIp]
if host == "" || s == nil || len(s.serverMap) == 0 {
s := ipMap[configService]
if serverHost == "" {
return
}

if host == configIp {
if s == nil || len(s.serverMap) == 0 {
// init server map
ipMap[configService] = &Info{
serverMap: map[string]*config.ServerInfo{
serverHost: {
HomepageURL: serverHost,
},
},
}
s = ipMap[configService]
}

if serverHost == configService {
s.nextTryConnTime = time.Now().Unix() + nextTryConnectPeriod
}

for k, server := range s.serverMap {
// if some node has down then select next node
if strings.Index(k, host) > -1 {
if strings.Index(k, serverHost) > -1 {
server.IsDown = true
}
}
Expand Down

0 comments on commit 755d850

Please sign in to comment.