Skip to content

Commit

Permalink
Migrating to gRPC 1.26. Fixes bazelbuild#117.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ola Rozenfeld committed Jan 14, 2020
1 parent 6e44b2e commit 802e4e9
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 24 deletions.
13 changes: 10 additions & 3 deletions WORKSPACE
Expand Up @@ -29,11 +29,18 @@ go_register_toolchains()
gazelle_dependencies()

# gRPC.
#http_archive(
# name = "com_github_grpc_grpc",
# sha256 = "b391a327429279f6f29b9ae7e5317cd80d5e9d49cc100e6d682221af73d984a6",
# strip_prefix = "grpc-93e8830070e9afcbaa992c75817009ee3f4b63a0", # v1.24.3 with fixes
# urls = ["https://github.com/grpc/grpc/archive/93e8830070e9afcbaa992c75817009ee3f4b63a0.zip"],
#)

http_archive(
name = "com_github_grpc_grpc",
sha256 = "b391a327429279f6f29b9ae7e5317cd80d5e9d49cc100e6d682221af73d984a6",
strip_prefix = "grpc-93e8830070e9afcbaa992c75817009ee3f4b63a0", # v1.24.3 with fixes
urls = ["https://github.com/grpc/grpc/archive/93e8830070e9afcbaa992c75817009ee3f4b63a0.zip"],
#sha256 = "d6af0859d3ae4693b1955e972aa2e590d6f4d44baaa82651467c6beea453e30e",
strip_prefix = "grpc-1.26.0",
urls = ["https://github.com/grpc/grpc/archive/v1.26.0.tar.gz"],
)

# Pull in all gRPC dependencies.
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Expand Up @@ -65,6 +65,6 @@ require (
google.golang.org/api v0.13.0 // indirect
google.golang.org/appengine v1.6.5 // indirect
google.golang.org/genproto v0.0.0-20191028173616-919d9bdd9fe6
google.golang.org/grpc v1.24.0
google.golang.org/grpc v1.26.0
gopkg.in/yaml.v1 v1.0.0-20140924161607-9f9df34309c0 // indirect
)
6 changes: 3 additions & 3 deletions go/pkg/balancer/gcp_balancer.go
Expand Up @@ -40,7 +40,7 @@ func (bb *gcpBalancerBuilder) Build(
csEvltr: &connectivityStateEvaluator{},
// Initialize picker to a picker that always return
// ErrNoSubConnAvailable, because when state of a SubConn changes, we
// may call UpdateBalancerState with this picker.
// may call UpdateState with this picker.
picker: newErrPicker(balancer.ErrNoSubConnAvailable),
}
}
Expand Down Expand Up @@ -144,7 +144,7 @@ type gcpBalancer struct {
scStates map[balancer.SubConn]connectivity.State
scRefs map[balancer.SubConn]*subConnRef

picker balancer.Picker
picker balancer.V2Picker
}

func (gb *gcpBalancer) HandleResolvedAddrs(addrs []resolver.Address, err error) {
Expand Down Expand Up @@ -302,7 +302,7 @@ func (gb *gcpBalancer) HandleSubConnStateChange(sc balancer.SubConn, s connectiv
if (s == connectivity.Ready) != (oldS == connectivity.Ready) ||
(gb.state == connectivity.TransientFailure) != (oldAggrState == connectivity.TransientFailure) {
gb.regeneratePicker()
gb.cc.UpdateBalancerState(gb.state, gb.picker)
gb.cc.UpdateState(balancer.State{ConnectivityState: gb.state, Picker: gb.picker})
}
}

Expand Down
30 changes: 14 additions & 16 deletions go/pkg/balancer/gcp_picker.go
@@ -1,7 +1,6 @@
package balancer

import (
"context"
"fmt"
"reflect"
"sort"
Expand All @@ -12,7 +11,7 @@ import (
"google.golang.org/grpc/balancer"
)

func newGCPPicker(readySCRefs []*subConnRef, gb *gcpBalancer) balancer.Picker {
func newGCPPicker(readySCRefs []*subConnRef, gb *gcpBalancer) balancer.V2Picker {
return &gcpPicker{
gcpBalancer: gb,
scRefs: readySCRefs,
Expand All @@ -28,18 +27,15 @@ type gcpPicker struct {
}

// Pick picks the appropriate subconnection.
func (p *gcpPicker) Pick(
ctx context.Context,
opts balancer.PickOptions,
) (balancer.SubConn, func(balancer.DoneInfo), error) {
func (p *gcpPicker) Pick(info balancer.PickInfo) (result balancer.PickResult, err error) {
if len(p.scRefs) <= 0 {
return nil, nil, balancer.ErrNoSubConnAvailable
return balancer.PickResult{}, balancer.ErrNoSubConnAvailable
}

p.mu.Lock()
defer p.mu.Unlock()

gcpCtx, hasGcpCtx := ctx.Value(gcpKey).(*gcpContext)
gcpCtx, hasGcpCtx := info.Ctx.Value(gcpKey).(*gcpContext)
boundKey := ""

if hasGcpCtx {
Expand All @@ -54,22 +50,24 @@ func (p *gcpPicker) Pick(
if cmd == pb.AffinityConfig_BOUND || cmd == pb.AffinityConfig_UNBIND {
a, err := getAffinityKeyFromMessage(locator, gcpCtx.reqMsg)
if err != nil {
return nil, nil, fmt.Errorf(
return balancer.PickResult{}, fmt.Errorf(
"failed to retrieve affinity key from request message: %v", err)
}
boundKey = a
}
}
}

scRef, err := p.getSubConnRef(boundKey)
var scRef *subConnRef
scRef, err = p.getSubConnRef(boundKey)
if err != nil {
return nil, nil, err
return balancer.PickResult{}, err
}
result.SubConn = scRef.subConn
scRef.streamsIncr()

// define callback for post process once call is done
callback := func(info balancer.DoneInfo) {
result.Done = func(info balancer.DoneInfo) {
if info.Err == nil {
if hasGcpCtx {
affinity := gcpCtx.affinityCfg
Expand All @@ -87,7 +85,7 @@ func (p *gcpPicker) Pick(
}
scRef.streamsDecr()
}
return scRef.subConn, callback, nil
return result, err
}

// getSubConnRef returns the subConnRef object that contains the subconn
Expand Down Expand Up @@ -157,14 +155,14 @@ func getAffinityKeyFromMessage(
}

// NewErrPicker returns a picker that always returns err on Pick().
func newErrPicker(err error) balancer.Picker {
func newErrPicker(err error) balancer.V2Picker {
return &errPicker{err: err}
}

type errPicker struct {
err error // Pick() always returns this err.
}

func (p *errPicker) Pick(ctx context.Context, opts balancer.PickOptions) (balancer.SubConn, func(balancer.DoneInfo), error) {
return nil, nil, p.err
func (p *errPicker) Pick(info balancer.PickInfo) (balancer.PickResult, error) {
return balancer.PickResult{}, p.err
}
2 changes: 1 addition & 1 deletion remote-apis-sdks-deps.bzl
Expand Up @@ -31,7 +31,7 @@ def remote_apis_sdks_go_deps():
name = "org_golang_google_grpc",
build_file_proto_mode = "disable",
importpath = "google.golang.org/grpc",
tag = "v1.24.0",
tag = "v1.26.0",
)
_maybe(
go_repository,
Expand Down

0 comments on commit 802e4e9

Please sign in to comment.