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

Switch balancer to grpclb when at least one address is grpclb address #1692

Merged
merged 6 commits into from
Dec 12, 2017

Conversation

menghanl
Copy link
Contributor

@menghanl menghanl commented Nov 28, 2017

$switch-balancer-1$

This change is Reviewable

@menghanl menghanl mentioned this pull request Nov 29, 2017
8 tasks
@dfawley dfawley self-assigned this Nov 30, 2017
@menghanl menghanl assigned menghanl and unassigned dfawley Dec 1, 2017
@menghanl menghanl assigned dfawley and unassigned menghanl Dec 1, 2017
clientconn.go Outdated
@@ -600,6 +600,7 @@ type ClientConn struct {
// Keepalive parameter can be updated if a GoAway is received.
mkp keepalive.ClientParameters
curBalancerName string
preBalancerName string // previous balancer nam.
Copy link
Member

Choose a reason for hiding this comment

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

*namE

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

clientconn.go Outdated
newBalancerName = pickfirstName
}
for _, a := range addrs {
if a.Type == resolver.GRPCLB && newBalancerName != grpclbName {
Copy link
Member

Choose a reason for hiding this comment

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

I think we don't want "newBalancerName != grpclbName". We should break if any Type is resolver.GRPCLB, and re-assigning newBalancerName to grpclbName is not worth optimizing away (actually it's more optimal than the extra branch).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

clientconn.go Outdated
// Switch from non-grpclb to grpclb.
newBalancerName = grpclbName
break
} else if a.Type == resolver.Backend && newBalancerName == grpclbName {
Copy link
Member

Choose a reason for hiding this comment

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

I thought we wanted to go with gRPCLB if any address is a gRPCLB address? This will switch away if both kinds are returned and we were previously using gRPCLB.

Maybe we should have a test where the gRPCLB backend changes (but both before and after are gRPCLB).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right!
Fixed and added a test.

clientconn.go Outdated
cc.balancerWrapper.handleResolvedAddrs(addrs, nil)
}

// switchBalancer starts the switching from current balancer to the balancer with name.
// switchBalancer starts the switching from current balancer to the balancer
// with the given name. It will NOT send the current address list to the new
Copy link
Member

Choose a reason for hiding this comment

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

It will NOT send the current address list to the new balancer.

Why? How do we bootstrap the new balancer then?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Caller of this function should do that. Comment updated.

clientconn.go Outdated
@@ -688,7 +700,6 @@ func (cc *ClientConn) switchBalancer(name string) {
grpclog.Infoln("ignoring service config balancer configuration: WithBalancer DialOption used instead")
return
}

if cc.curBalancerName == name {
Copy link
Member

Choose a reason for hiding this comment

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

Should this go above the log about switching?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The idea here is, if balancer is set by a dial option, all switch balancer call will be no-op.

Copy link
Member

Choose a reason for hiding this comment

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

Right, but we don't need to log that we aren't switching if the name doesn't change, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

time.Sleep(time.Millisecond)
}
if !isPickFirst {
t.Fatalf("after 1 second, cc.balancer is of type %v, not pick_first", cc.curBalancerName)
Copy link
Member

Choose a reason for hiding this comment

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

Is 1s long enough for these tests on travis? I'd rather give them 5-10 to avoid potential flakiness -- they stop early when the condition occurs, so it's not harmful to give them longer unless the timing is important.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@dfawley dfawley assigned menghanl and unassigned dfawley Dec 7, 2017
Copy link
Contributor Author

@menghanl menghanl left a comment

Choose a reason for hiding this comment

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

Thanks for the review.
All done. PTAL.

clientconn.go Outdated
@@ -600,6 +600,7 @@ type ClientConn struct {
// Keepalive parameter can be updated if a GoAway is received.
mkp keepalive.ClientParameters
curBalancerName string
preBalancerName string // previous balancer nam.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

clientconn.go Outdated
cc.balancerWrapper.handleResolvedAddrs(addrs, nil)
}

// switchBalancer starts the switching from current balancer to the balancer with name.
// switchBalancer starts the switching from current balancer to the balancer
// with the given name. It will NOT send the current address list to the new
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Caller of this function should do that. Comment updated.

clientconn.go Outdated
@@ -688,7 +700,6 @@ func (cc *ClientConn) switchBalancer(name string) {
grpclog.Infoln("ignoring service config balancer configuration: WithBalancer DialOption used instead")
return
}

if cc.curBalancerName == name {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The idea here is, if balancer is set by a dial option, all switch balancer call will be no-op.

time.Sleep(time.Millisecond)
}
if !isPickFirst {
t.Fatalf("after 1 second, cc.balancer is of type %v, not pick_first", cc.curBalancerName)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

clientconn.go Outdated
// Switch from non-grpclb to grpclb.
newBalancerName = grpclbName
break
} else if a.Type == resolver.Backend && newBalancerName == grpclbName {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right!
Fixed and added a test.

clientconn.go Outdated
newBalancerName = pickfirstName
}
for _, a := range addrs {
if a.Type == resolver.GRPCLB && newBalancerName != grpclbName {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@menghanl menghanl assigned dfawley and unassigned menghanl Dec 8, 2017
clientconn.go Outdated
}
var newBalancerName string
if isGRPCLB {
newBalancerName = grpclbName
Copy link
Member

Choose a reason for hiding this comment

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

Optional, but it's a go-ism:

newBalancerName := grpclbName
if !isGRPCLB {
  ...
}

but it's a little awkward in this case, so either is probably fine.

clientconn.go Outdated
@@ -719,15 +719,14 @@ func (cc *ClientConn) switchBalancer(name string) {
}
grpclog.Infof("ClientConn switching balancer to %q", name)

if cc.dopts.balancerBuilder != nil {
grpclog.Infoln("ignoring balancer switching: WithBalancer DialOption used instead")
if strings.ToLower(cc.curBalancerName) == strings.ToLower(name) {
Copy link
Member

Choose a reason for hiding this comment

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

I would rather move this above the info log on 720 also, but if you feel strongly then OK.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@menghanl menghanl merged commit dba60db into grpc:master Dec 12, 2017
@menghanl menghanl deleted the switch_to_grpclb branch December 12, 2017 20:45
@dfawley dfawley added the Type: Feature New features or improvements in behavior label Jan 2, 2018
@dfawley dfawley added this to the 1.9 Release milestone Jan 2, 2018
@lock lock bot locked as resolved and limited conversation to collaborators Jan 18, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Type: Feature New features or improvements in behavior
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants