Skip to content

Commit

Permalink
Merge pull request #261 from dougsong/master
Browse files Browse the repository at this point in the history
[FIX] fix: sdk load balance
  • Loading branch information
mergify[bot] committed Dec 11, 2022
2 parents 734a8a5 + 755d850 commit 9459f7a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
24 changes: 18 additions & 6 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 {
s.nextTryConnTime = nextTryConnectPeriod
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
6 changes: 1 addition & 5 deletions protocol/http/request.go
Expand Up @@ -207,11 +207,7 @@ func RequestRecovery(appConfig config.AppConfig,
return response, nil
}

if host == appConfig.GetHost() {
return response, err
}

server.SetDownNode(host, appConfig.GetHost())
server.SetDownNode(appConfig.GetHost(), host)
}
}

Expand Down

0 comments on commit 9459f7a

Please sign in to comment.