Skip to content
Merged
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
14 changes: 11 additions & 3 deletions balancer/endpointsharding/endpointsharding.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,24 @@ import (
"google.golang.org/grpc/balancer/base"
"google.golang.org/grpc/balancer/pickfirst/pickfirstleaf"
"google.golang.org/grpc/connectivity"
"google.golang.org/grpc/grpclog"
"google.golang.org/grpc/internal/balancer/gracefulswitch"
"google.golang.org/grpc/resolver"
"google.golang.org/grpc/serviceconfig"
)

// PickFirstConfig is a pick first config without shuffling enabled.
var PickFirstConfig string
var (
// PickFirstConfig is a pick first config without shuffling enabled.
PickFirstConfig serviceconfig.LoadBalancingConfig
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a pubic API change, but the package is experimental. @dfawley should I export a new var instead of replacing the existing one?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should be fine to just change it since it's experimental and very new.

logger = grpclog.Component("endpoint-sharding")
)

func init() {
PickFirstConfig = fmt.Sprintf("[{%q: {}}]", pickfirstleaf.Name)
var err error
PickFirstConfig, err = ParseConfig(json.RawMessage(fmt.Sprintf("[{%q: {}}]", pickfirstleaf.Name)))
if err != nil {
logger.Fatal(err)
}
}

// ChildState is the balancer state of a child along with the endpoint which
Expand Down
14 changes: 5 additions & 9 deletions balancer/endpointsharding/endpointsharding_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*
*/

package endpointsharding
package endpointsharding_test

import (
"context"
Expand All @@ -28,6 +28,7 @@ import (

"google.golang.org/grpc"
"google.golang.org/grpc/balancer"
"google.golang.org/grpc/balancer/endpointsharding"
"google.golang.org/grpc/credentials/insecure"
"google.golang.org/grpc/grpclog"
"google.golang.org/grpc/internal"
Expand All @@ -49,16 +50,11 @@ func Test(t *testing.T) {
grpctest.RunSubTests(t, s{})
}

var gracefulSwitchPickFirst serviceconfig.LoadBalancingConfig
var gracefulSwitchPickFirst = endpointsharding.PickFirstConfig

var logger = grpclog.Component("endpoint-sharding-test")

func init() {
var err error
gracefulSwitchPickFirst, err = ParseConfig(json.RawMessage(PickFirstConfig))
if err != nil {
logger.Fatal(err)
}
balancer.Register(fakePetioleBuilder{})
}

Expand All @@ -75,7 +71,7 @@ func (fakePetioleBuilder) Build(cc balancer.ClientConn, opts balancer.BuildOptio
ClientConn: cc,
bOpts: opts,
}
fp.Balancer = NewBalancer(fp, opts)
fp.Balancer = endpointsharding.NewBalancer(fp, opts)
return fp
}

Expand Down Expand Up @@ -105,7 +101,7 @@ func (fp *fakePetiole) UpdateClientConnState(state balancer.ClientConnState) err
}

func (fp *fakePetiole) UpdateState(state balancer.State) {
childStates := ChildStatesFromPicker(state.Picker)
childStates := endpointsharding.ChildStatesFromPicker(state.Picker)
// Both child states should be present in the child picker. States and
// picker change over the lifecycle of test, but there should always be two.
if len(childStates) != 2 {
Expand Down
7 changes: 1 addition & 6 deletions balancer/weightedroundrobin/balancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,15 +85,10 @@ var (
)

// endpointSharding which specifies pick first children.
var endpointShardingLBConfig serviceconfig.LoadBalancingConfig
var endpointShardingLBConfig = endpointsharding.PickFirstConfig

func init() {
balancer.Register(bb{})
var err error
endpointShardingLBConfig, err = endpointsharding.ParseConfig(json.RawMessage(endpointsharding.PickFirstConfig))
if err != nil {
logger.Fatal(err)
}
}

type bb struct{}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,13 @@ import (
"google.golang.org/grpc/balancer"
"google.golang.org/grpc/balancer/endpointsharding"
"google.golang.org/grpc/connectivity"
"google.golang.org/grpc/grpclog"
"google.golang.org/grpc/serviceconfig"
)

var gracefulSwitchPickFirst serviceconfig.LoadBalancingConfig
var gracefulSwitchPickFirst = endpointsharding.PickFirstConfig

func init() {
balancer.Register(customRoundRobinBuilder{})
var err error
gracefulSwitchPickFirst, err = endpointsharding.ParseConfig(json.RawMessage(endpointsharding.PickFirstConfig))
if err != nil {
logger.Fatal(err)
}
}

const customRRName = "custom_round_robin"
Expand Down Expand Up @@ -79,8 +73,6 @@ func (customRoundRobinBuilder) Build(cc balancer.ClientConn, bOpts balancer.Buil
return crr
}

var logger = grpclog.Component("example")

type customRoundRobin struct {
// All state and operations on this balancer are either initialized at build
// time and read only after, or are only accessed as part of its
Expand Down