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

Replace deprecated functions with new grpc functions (Picker V2) #12439

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion client/v3/balancer/balancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ func (bb *baseBalancer) HandleSubConnStateChange(sc balancer.SubConn, s grpcconn
bb.updatePicker()
}

bb.currentConn.UpdateBalancerState(bb.connectivityRecorder.GetCurrentState(), bb.picker)
bb.currentConn.UpdateState(balancer.State{ConnectivityState: bb.connectivityRecorder.GetCurrentState(), Picker: bb.picker})
}

func (bb *baseBalancer) updatePicker() {
Expand Down
6 changes: 2 additions & 4 deletions client/v3/balancer/picker/err.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
package picker

import (
"context"

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

Expand All @@ -34,6 +32,6 @@ func (ep *errPicker) String() string {
return ep.p.String()
}

func (ep *errPicker) Pick(context.Context, balancer.PickInfo) (balancer.SubConn, func(balancer.DoneInfo), error) {
return nil, nil, ep.err
func (ep *errPicker) Pick(balancer.PickInfo) (balancer.PickResult, error) {
return balancer.PickResult{}, nil
}
2 changes: 1 addition & 1 deletion client/v3/balancer/picker/picker.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (

// Picker defines balancer Picker methods.
type Picker interface {
balancer.Picker
balancer.V2Picker
String() string
}

Expand Down
10 changes: 6 additions & 4 deletions client/v3/balancer/picker/roundrobin_balanced.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
package picker

import (
"context"
"sync"

"go.uber.org/zap"
Expand Down Expand Up @@ -52,12 +51,13 @@ type rrBalanced struct {
func (rb *rrBalanced) String() string { return rb.p.String() }

// Pick is called for every client request.
func (rb *rrBalanced) Pick(ctx context.Context, opts balancer.PickInfo) (balancer.SubConn, func(balancer.DoneInfo), error) {
func (rb *rrBalanced) Pick(opts balancer.PickInfo) (balancer.PickResult, error) {
rb.mu.RLock()
n := len(rb.scs)
rb.mu.RUnlock()
if n == 0 {
return nil, nil, balancer.ErrNoSubConnAvailable
pr := balancer.PickResult{}
return pr, balancer.ErrNoSubConnAvailable
}

rb.mu.Lock()
Expand Down Expand Up @@ -91,5 +91,7 @@ func (rb *rrBalanced) Pick(ctx context.Context, opts balancer.PickInfo) (balance
rb.lg.Warn("balancer failed", fss...)
}
}
return sc, doneFunc, nil

pr := balancer.PickResult{SubConn: rb.scs[cur], Done: doneFunc}
return pr, nil
}
5 changes: 3 additions & 2 deletions client/v3/balancer/resolver/endpoint/endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func (e *ResolverGroup) addResolver(r *Resolver) {
addrs := epsToAddrs(e.endpoints...)
e.resolvers = append(e.resolvers, r)
e.mu.Unlock()
r.cc.NewAddress(addrs)
r.cc.UpdateState(resolver.State{Addresses: addrs})
}

func (e *ResolverGroup) removeResolver(r *Resolver) {
Expand All @@ -85,8 +85,9 @@ func (e *ResolverGroup) SetEndpoints(endpoints []string) {
addrs := epsToAddrs(endpoints...)
e.mu.Lock()
e.endpoints = endpoints
state := resolver.State{Addresses: addrs}
for _, r := range e.resolvers {
r.cc.NewAddress(addrs)
r.cc.UpdateState(state)
}
e.mu.Unlock()
}
Expand Down