Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] fix: sdk load balance #261

Merged
merged 2 commits into from Dec 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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{
zouyx marked this conversation as resolved.
Show resolved Hide resolved
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