Skip to content

Commit

Permalink
simplify fix
Browse files Browse the repository at this point in the history
  • Loading branch information
rboyer committed May 10, 2023
1 parent aba9d0e commit 34a1cc9
Showing 1 changed file with 2 additions and 30 deletions.
32 changes: 2 additions & 30 deletions agent/grpc-internal/resolver/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,10 +155,6 @@ func (s *ServerResolverBuilder) AddServer(areaID types.AreaID, server *metadata.

areaServers[uniqueID(server)] = server

if areaID == types.AreaLAN || s.cfg.Datacenter == server.Datacenter {
s.leaderResolver.updateClientConn()
}

addrs := s.getDCAddrs(server.Datacenter)
for _, resolver := range s.resolvers {
if resolver.datacenter == server.Datacenter {
Expand Down Expand Up @@ -201,10 +197,6 @@ func (s *ServerResolverBuilder) RemoveServer(areaID types.AreaID, server *metada
delete(s.servers, areaID)
}

if areaID == types.AreaLAN || s.cfg.Datacenter == server.Datacenter {
s.leaderResolver.updateClientConn()
}

addrs := s.getDCAddrs(server.Datacenter)
for _, resolver := range s.resolvers {
if resolver.datacenter == server.Datacenter {
Expand Down Expand Up @@ -281,28 +273,8 @@ func (s *ServerResolverBuilder) UpdateLeaderAddr(datacenter, addr string) {
s.lock.Lock()
defer s.lock.Unlock()

lanAddr := DCPrefix(datacenter, addr)

s.leaderResolver.globalAddr = lanAddr

if s.lanHasAddrLocked(lanAddr) {
s.leaderResolver.updateClientConn()
}
}

func (s *ServerResolverBuilder) lanHasAddrLocked(lanAddr string) bool {
areaServers, ok := s.servers[types.AreaLAN]
if !ok {
return false
}

for _, server := range areaServers {
if DCPrefix(server.Datacenter, server.Addr.String()) == lanAddr {
return true
}
}

return false
s.leaderResolver.globalAddr = DCPrefix(datacenter, addr)
s.leaderResolver.updateClientConn()
}

// serverResolver is a grpc Resolver that will keep a grpc.ClientConn up to date
Expand Down

0 comments on commit 34a1cc9

Please sign in to comment.