Skip to content

Commit

Permalink
Replace deprecated functions with new grpc version
Browse files Browse the repository at this point in the history
  • Loading branch information
agargi committed Nov 1, 2020
1 parent 0b4b5d8 commit 34276cb
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 12 deletions.
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

0 comments on commit 34276cb

Please sign in to comment.