Skip to content

Commit

Permalink
xds/priority: add ignore reresolution boolean to config (#4275)
Browse files Browse the repository at this point in the history
  • Loading branch information
menghanl committed Apr 27, 2021
1 parent 7c5e737 commit 24d03d9
Show file tree
Hide file tree
Showing 7 changed files with 417 additions and 66 deletions.
6 changes: 3 additions & 3 deletions xds/internal/balancer/priority/balancer.go
Expand Up @@ -131,7 +131,7 @@ func (b *priorityBalancer) UpdateClientConnState(s balancer.ClientConnState) err
// the balancer isn't built, because this child can be a low
// priority. If necessary, it will be built when syncing priorities.
cb := newChildBalancer(name, b, bb)
cb.updateConfig(newSubConfig.Config.Config, resolver.State{
cb.updateConfig(newSubConfig, resolver.State{
Addresses: addressesSplit[name],
ServiceConfig: s.ResolverState.ServiceConfig,
Attributes: s.ResolverState.Attributes,
Expand All @@ -146,13 +146,13 @@ func (b *priorityBalancer) UpdateClientConnState(s balancer.ClientConnState) err
// rebuild, rebuild will happen when syncing priorities.
if currentChild.bb.Name() != bb.Name() {
currentChild.stop()
currentChild.bb = bb
currentChild.updateBuilder(bb)
}

// Update config and address, but note that this doesn't send the
// updates to child balancer (the child balancer might not be built, if
// it's a low priority).
currentChild.updateConfig(newSubConfig.Config.Config, resolver.State{
currentChild.updateConfig(newSubConfig, resolver.State{
Addresses: addressesSplit[name],
ServiceConfig: s.ResolverState.ServiceConfig,
Attributes: s.ResolverState.Attributes,
Expand Down
20 changes: 14 additions & 6 deletions xds/internal/balancer/priority/balancer_child.go
Expand Up @@ -29,10 +29,11 @@ import (
type childBalancer struct {
name string
parent *priorityBalancer
bb balancer.Builder
bb *ignoreResolveNowBalancerBuilder

config serviceconfig.LoadBalancingConfig
rState resolver.State
ignoreReresolutionRequests bool
config serviceconfig.LoadBalancingConfig
rState resolver.State

started bool
state balancer.State
Expand All @@ -44,7 +45,7 @@ func newChildBalancer(name string, parent *priorityBalancer, bb balancer.Builder
return &childBalancer{
name: name,
parent: parent,
bb: bb,
bb: newIgnoreResolveNowBalancerBuilder(bb, false),
started: false,
// Start with the connecting state and picker with re-pick error, so
// that when a priority switch causes this child picked before it's
Expand All @@ -56,10 +57,16 @@ func newChildBalancer(name string, parent *priorityBalancer, bb balancer.Builder
}
}

// updateBuilder updates builder for the child, but doesn't build.
func (cb *childBalancer) updateBuilder(bb balancer.Builder) {
cb.bb = newIgnoreResolveNowBalancerBuilder(bb, cb.ignoreReresolutionRequests)
}

// updateConfig sets childBalancer's config and state, but doesn't send update to
// the child balancer.
func (cb *childBalancer) updateConfig(config serviceconfig.LoadBalancingConfig, rState resolver.State) {
cb.config = config
func (cb *childBalancer) updateConfig(child *Child, rState resolver.State) {
cb.ignoreReresolutionRequests = child.IgnoreReresolutionRequests
cb.config = child.Config.Config
cb.rState = rState
}

Expand All @@ -76,6 +83,7 @@ func (cb *childBalancer) start() {

// sendUpdate sends the addresses and config to the child balancer.
func (cb *childBalancer) sendUpdate() {
cb.bb.updateIgnoreResolveNow(cb.ignoreReresolutionRequests)
// TODO: return and aggregate the returned error in the parent.
err := cb.parent.bg.UpdateClientConnState(cb.name, balancer.ClientConnState{
ResolverState: cb.rState,
Expand Down

0 comments on commit 24d03d9

Please sign in to comment.