-
Notifications
You must be signed in to change notification settings - Fork 4.6k
grpclb: fallback after init #2681
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -85,24 +85,26 @@ func (lb *lbBalancer) processServerList(l *lbpb.ServerList) { | |
| backendAddrs = append(backendAddrs, addr) | ||
| } | ||
|
|
||
| // Call refreshSubConns to create/remove SubConns. | ||
| // Call refreshSubConns to create/remove SubConns. If we are in fallback, | ||
| // this is also exiting fallback. | ||
| lb.refreshSubConns(backendAddrs, true) | ||
| // Regenerate and update picker no matter if there's update on backends (if | ||
| // any SubConn will be newed/removed). Because since the full serverList was | ||
| // different, there might be updates in drops or pick weights(different | ||
| // number of duplicates). We need to update picker with the fulllist. | ||
| // | ||
| // Now with cache, even if SubConn was newed/removed, there might be no | ||
| // state changes. | ||
| lb.regeneratePicker(true) | ||
| lb.cc.UpdateBalancerState(lb.state, lb.picker) | ||
| } | ||
|
|
||
| // refreshSubConns creates/removes SubConns with backendAddrs. It returns a bool | ||
| // indicating whether the backendAddrs are different from the cached | ||
| // backendAddrs (whether any SubConn was newed/removed). | ||
| // refreshSubConns creates/removes SubConns with backendAddrs, and refreshes | ||
| // balancer state and picker. | ||
| // | ||
| // Caller must hold lb.mu. | ||
| func (lb *lbBalancer) refreshSubConns(backendAddrs []resolver.Address, fromGRPCLBServer bool) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. Now also updates picker after regenerating picker. |
||
| defer func() { | ||
| // Regenerate and update picker after refreshing subconns because with | ||
| // cache, even if SubConn was newed/removed, there might be no state | ||
| // changes (the subconn will be kept in cache, not actually | ||
| // newed/removed). | ||
| lb.updateStateAndPicker(true, true) | ||
| }() | ||
|
|
||
| lb.inFallback = !fromGRPCLBServer | ||
lyuxuan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| opts := balancer.NewSubConnOptions{} | ||
| if fromGRPCLBServer { | ||
| opts.CredsBundle = lb.grpclbBackendCreds | ||
|
|
@@ -218,6 +220,9 @@ func (lb *lbBalancer) callRemoteBalancer() (backoff bool, _ error) { | |
| if err != nil { | ||
| return true, fmt.Errorf("grpclb: failed to perform RPC to the remote balancer %v", err) | ||
| } | ||
| lb.mu.Lock() | ||
| lb.remoteBalancerConnected = true | ||
| lb.mu.Unlock() | ||
|
|
||
| // grpclb handshake on the stream. | ||
| initReq := &lbpb.LoadBalanceRequest{ | ||
|
|
@@ -270,6 +275,17 @@ func (lb *lbBalancer) watchRemoteBalancer() { | |
| // Trigger a re-resolve when the stream errors. | ||
| lb.cc.cc.ResolveNow(resolver.ResolveNowOption{}) | ||
|
|
||
| lb.mu.Lock() | ||
| lb.remoteBalancerConnected = false | ||
| lb.fullServerList = nil | ||
| // Enter fallback when connection to remote balancer is lost, and the | ||
| // aggregated state is not Ready. | ||
| if !lb.inFallback && lb.state != connectivity.Ready { | ||
| // Entering fallback. | ||
| lb.refreshSubConns(lb.resolvedBackendAddrs, false) | ||
| } | ||
| lb.mu.Unlock() | ||
|
|
||
| if !doBackoff { | ||
| retryCount = 0 | ||
| continue | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.