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

client/SubConn: do not recreate addrConn if UpdateAddresses is called with the same addresses #5373

Merged
merged 5 commits into from
May 20, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Revert "[pickfirst_check_addrs] do it in pickfirst?"
This reverts commit 6f40d78.
  • Loading branch information
menghanl committed May 20, 2022
commit f402cf3bcc0c2d85991a1b8819ee88b3c7322f02
29 changes: 0 additions & 29 deletions pickfirst.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (

"google.golang.org/grpc/balancer"
"google.golang.org/grpc/connectivity"
"google.golang.org/grpc/resolver"
)

// PickFirstBalancerName is the name of the pick_first balancer.
Expand All @@ -48,7 +47,6 @@ type pickfirstBalancer struct {
state connectivity.State
cc balancer.ClientConn
subConn balancer.SubConn
addrs []resolver.Address
}

func (b *pickfirstBalancer) ResolverError(err error) {
Expand All @@ -70,18 +68,6 @@ func (b *pickfirstBalancer) ResolverError(err error) {
})
}

func equalAddresses(a, b []resolver.Address) bool {
if len(a) != len(b) {
return false
}
for i, v := range a {
if !v.Equal(b[i]) {
return false
}
}
return true
}

func (b *pickfirstBalancer) UpdateClientConnState(state balancer.ClientConnState) error {
if len(state.ResolverState.Addresses) == 0 {
// The resolver reported an empty address list. Treat it like an error by
Expand All @@ -96,21 +82,6 @@ func (b *pickfirstBalancer) UpdateClientConnState(state balancer.ClientConnState
return balancer.ErrBadResolverState
}

if equalAddresses(b.addrs, state.ResolverState.Addresses) {
// Avoid updating SubConn addresses if the addresses are the same.
//
// Usually SubConns can compare the new addresses with the address in
// use, and will not recreate the connection if not necessary.
//
// A special case is if the SubConn is in Connecting (so it's still
// trying to connect the addresses, and there's no address in use).
// Calling update addresses, even with the same set of Addresses, cause
// the SubConn to stop connecting, and retry with the new (same) set of
// addresses.
return nil
}
b.addrs = state.ResolverState.Addresses

if b.subConn != nil {
b.cc.UpdateAddresses(b.subConn, state.ResolverState.Addresses)
return nil
Expand Down