-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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
Expose ConnectivityState of a ClientConn. #1385
Conversation
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.
Looks great, mostly just nits.
clientconn.go
Outdated
@@ -476,6 +478,97 @@ func (s ConnectivityState) String() string { | |||
} | |||
} | |||
|
|||
// connectivityStateEvaluator gets updated by addrConns when their | |||
// stats transition, based on which it evaluates the state of |
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.
*states
clientconn.go
Outdated
// connectivityStateEvaluator gets updated by addrConns when their | ||
// stats transition, based on which it evaluates the state of | ||
// ClientConn. | ||
// Note: This code will eventully sit in the blanacer in the new design. |
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.
*eventually
clientconn.go
Outdated
// before any addrConn is created ClientConn is in idle state. In the end when ClientConn | ||
// closes it is in Shutdown state. | ||
// TODO Note that in later releases, a ClientConn with no activity will be put into an Idle state. | ||
func (csEvltr *connectivityStateEvaluator) recordTransition(oldState, newState ConnectivityState) { |
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.
csEvltr -> c? cse?
clientconn.go
Outdated
@@ -841,8 +923,9 @@ func (ac *addrConn) resetTransport(closeTransport bool) error { | |||
ac.down(downErrorf(false, true, "%v", errNetworkIO)) | |||
ac.down = nil | |||
} | |||
oldState := ac.state |
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.
How about this:
updateState := func(new ConnectivityState) {
ac.csEvltr.recordTransition(ac.state, new)
ac.state = new
}
....
updateState(Connecting)
...
updateState(TransientFailure)
...
defer cc.Close() | ||
wantState := Ready | ||
if state, ok := assertState(wantState, cc); !ok { | ||
t.Fatalf("asserState(%s) = %s, false, want %s, true", wantState, state, wantState) |
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.
*assertState
clientconn.go
Outdated
// connectivityStateEvaluator gets updated by addrConns when their | ||
// states transition, based on which it evaluates the state of | ||
// ClientConn. | ||
// Note: This code will eventually sit in the blanacer in the new design. |
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.
nit: balancer is typo'ed
clientconn.go
Outdated
// recordTransition records state change happening in every addrConn and based on | ||
// that it evaluates what state the ClientConn is in. | ||
// It can only transition between Ready, Connecting and TransientFailure. Other states, | ||
// Idle and Shutdown are transitioned into by ClientConn; in the begining of the conneciton |
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.
nit: begining, conneciton
} | ||
|
||
// updateState updates the ConnectivityState of ClientConn. | ||
// If there's a change it notifies goroutines waiting on state change to |
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.
it can only notify 1 goroutine, right?
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.
Although rare, but it's possible multiple goroutines can make a call to WaitForStateChange
clientconn.go
Outdated
err = cc.resetAddrConn(a, false, nil) | ||
} | ||
if err != nil { | ||
grpclog.Warningf("Error creating conneciton to %v. Err: %v", a, err) |
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.
nit: connection
fixes #1208
#1359