Skip to content

Conversation

@lyuxuan
Copy link
Contributor

@lyuxuan lyuxuan commented Apr 19, 2019

No description provided.

x.fallbackLB = builder.Build(x.cc, x.buildOpts)

if x.fallbackInitData != nil {
// TODO: uncomment when HandleBalancerConfig API is merged.
Copy link
Contributor

Choose a reason for hiding this comment

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

What was this for?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I would like to clean up this at later time. Essentially, it's essentially make fallback balancer which implements V2 API gets both service config and addresses.

Copy link
Contributor

Choose a reason for hiding this comment

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

I have a feeling that this won't be as trivial as it sounds. It may change the way you handle resolver updates in this PR.

x.startFallBackBalancer(u)

if u.addrUpdate != nil && x.fallbackLB != nil {
x.fallbackLB.HandleResolvedAddrs(u.addrUpdate.addrs, u.addrUpdate.err)
Copy link
Contributor

Choose a reason for hiding this comment

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

If this fallback balancer is new, it will handle the same addresses twice.

if u.addrUpdate != nil {
// addresses have been updated.
// in case of x.config == nil where it returns early, we set the fallbackInitData here.
x.fallbackInitData = u.addrUpdate
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do you still need fallbackInitData?

If fallback balancer is updated, the new addresses are also sent along with the update.
You shouldn't need to keep the old addresses for a new fallback balancer.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's possible that fallback balancer is changed at later time (and the addresses are not updated in the same update), so we still need to initialize with the old addresses.

Copy link
Contributor

Choose a reason for hiding this comment

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

Actually, you need this field when switching to fallback.
But this update here shouldn't be necessary. It also causes double address update for a new fallback balancer.

Copy link
Contributor Author

@lyuxuan lyuxuan Apr 23, 2019

Choose a reason for hiding this comment

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

It's here because of the early return. Let me think a bit more if we can just move this line inside the early return condition.

var update interface{}
// if service config does not change for this update, we only send address update.
if x.lastResolverUpdate != nil && x.lastResolverUpdate.ServiceConfig == s.ServiceConfig {
update = &resolverUpdate{
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this function just sent a &resolverUpdate{...} to the executor goroutine, and do all the checks and parsing there?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Why we want to do this?

Copy link
Contributor

Choose a reason for hiding this comment

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

Some of the logic here and later in the goroutine is duplicate.

For example:
Each resolver update, the balancer does:

  1. if addresses are updated, do something for the addresses
  2. if config is updated, do something for the config

Checks like this are done twice.
First time here,

  1. if addresses are updated, resolverUpdate.addrUpdate is set
  2. if config is updated, resolverUpdate.xdsconfig is set

Later in the goroutine

  1. if resolverUpdate.addrUpdate is not nil, do something
  2. if resolverUpdate.xdsconfig is not nil, do something

The code is this way because the resolver update is still treated as two separate things. I think the code should be updated to actually treat them as one.

The update sent to the goroutine can be just

type resolverUpdate struct {
    state resolver.State
}

@lyuxuan lyuxuan merged commit d5973a9 into grpc:master Apr 29, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Oct 26, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants