-
Notifications
You must be signed in to change notification settings - Fork 4.6k
balancer: automatically stop producers on subchannel state changes #7663
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
a6a5fc1
balancer: automatically stop producers on subchannel state changes
dfawley 1c6a9b1
add a test to confirm producer shutdown is happening as advertised
dfawley 2eb9103
fix races in orca test
dfawley 230f34d
fix orca OOB test to use RegisterOOBListener correctly
dfawley 07b5ecc
delete ac.getTransport and use getReadyTransport instead
dfawley a23eb96
add comment about negative refs
dfawley File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -825,14 +825,13 @@ func (cc *ClientConn) newAddrConnLocked(addrs []resolver.Address, opts balancer. | |
| } | ||
|
|
||
| ac := &addrConn{ | ||
| state: connectivity.Idle, | ||
| cc: cc, | ||
| addrs: copyAddresses(addrs), | ||
| scopts: opts, | ||
| dopts: cc.dopts, | ||
| channelz: channelz.RegisterSubChannel(cc.channelz, ""), | ||
| resetBackoff: make(chan struct{}), | ||
| stateReadyChan: make(chan struct{}), | ||
| state: connectivity.Idle, | ||
| cc: cc, | ||
| addrs: copyAddresses(addrs), | ||
| scopts: opts, | ||
| dopts: cc.dopts, | ||
| channelz: channelz.RegisterSubChannel(cc.channelz, ""), | ||
| resetBackoff: make(chan struct{}), | ||
| } | ||
| ac.ctx, ac.cancel = context.WithCancel(cc.ctx) | ||
| // Start with our address set to the first address; this may be updated if | ||
|
|
@@ -1179,8 +1178,7 @@ type addrConn struct { | |
| addrs []resolver.Address // All addresses that the resolver resolved to. | ||
|
|
||
| // Use updateConnectivityState for updating addrConn's connectivity state. | ||
| state connectivity.State | ||
| stateReadyChan chan struct{} // closed and recreated on every READY state change. | ||
| state connectivity.State | ||
|
|
||
| backoffIdx int // Needs to be stateful for resetConnectBackoff. | ||
| resetBackoff chan struct{} | ||
|
|
@@ -1193,22 +1191,14 @@ func (ac *addrConn) updateConnectivityState(s connectivity.State, lastErr error) | |
| if ac.state == s { | ||
| return | ||
| } | ||
| if ac.state == connectivity.Ready { | ||
| // When leaving ready, re-create the ready channel. | ||
| ac.stateReadyChan = make(chan struct{}) | ||
| } | ||
| if s == connectivity.Shutdown { | ||
| // Wake any producer waiting to create a stream on the transport. | ||
| close(ac.stateReadyChan) | ||
| } | ||
| ac.state = s | ||
| ac.channelz.ChannelMetrics.State.Store(&s) | ||
| if lastErr == nil { | ||
| channelz.Infof(logger, ac.channelz, "Subchannel Connectivity change to %v", s) | ||
| } else { | ||
| channelz.Infof(logger, ac.channelz, "Subchannel Connectivity change to %v, last error: %s", s, lastErr) | ||
| } | ||
| ac.acbw.updateState(s, ac.curAddr, lastErr, ac.stateReadyChan) | ||
| ac.acbw.updateState(s, ac.curAddr, lastErr) | ||
| } | ||
|
|
||
| // adjustParams updates parameters used to create transports upon | ||
|
|
@@ -1515,26 +1505,16 @@ func (ac *addrConn) getReadyTransport() transport.ClientTransport { | |
| // getTransport waits until the addrconn is ready and returns the transport. | ||
| // If the context expires first, returns an appropriate status. If the | ||
| // addrConn is stopped first, returns an Unavailable status error. | ||
|
||
| func (ac *addrConn) getTransport(ctx context.Context) (transport.ClientTransport, error) { | ||
| for ctx.Err() == nil { | ||
| ac.mu.Lock() | ||
| t, state, readyChan := ac.transport, ac.state, ac.stateReadyChan | ||
| ac.mu.Unlock() | ||
| if state == connectivity.Shutdown { | ||
| // Return an error immediately in only this case since a connection | ||
| // will never occur. | ||
| return nil, status.Errorf(codes.Unavailable, "SubConn shutting down") | ||
| } | ||
| func (ac *addrConn) getTransport() (transport.ClientTransport, error) { | ||
| ac.mu.Lock() | ||
| t, state := ac.transport, ac.state | ||
| ac.mu.Unlock() | ||
|
|
||
| select { | ||
| case <-ctx.Done(): | ||
| case <-readyChan: | ||
| if state == connectivity.Ready { | ||
| return t, nil | ||
| } | ||
| } | ||
| if state != connectivity.Ready { | ||
| return nil, status.Errorf(codes.Unavailable, "SubConn state is %v; not Ready", state) | ||
| } | ||
| return nil, status.FromContextError(ctx.Err()).Err() | ||
|
|
||
| return t, nil | ||
| } | ||
|
|
||
| // tearDown starts to tear down the addrConn. | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given that the subchannel now takes care of closing the producer, do you think it makes sense to simplify things here by getting rid of the
stopORCAListenerfield?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, I wanted to do that, but we still need to restart the listener when the config changes.