Skip to content

Commit

Permalink
Make ConnectivityStateEvaluator private
Browse files Browse the repository at this point in the history
  • Loading branch information
WeiranFang committed Feb 26, 2019
1 parent 72541bb commit a0862e6
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions grpcgcp/gcp_balancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func (bb *gcpBalancerBuilder) Build(
affinityMap: make(map[string]balancer.SubConn),
scRefs: make(map[balancer.SubConn]*subConnRef),
scStates: make(map[balancer.SubConn]connectivity.State),
csEvltr: &ConnectivityStateEvaluator{},
csEvltr: &connectivityStateEvaluator{},
// Initialize picker to a picker that always return
// ErrNoSubConnAvailable, because when state of a SubConn changes, we
// may call UpdateBalancerState with this picker.
Expand All @@ -76,24 +76,24 @@ func newBuilder() balancer.Builder {
}
}

// ConnectivityStateEvaluator gets updated by addrConns when their
// connectivityStateEvaluator gets updated by addrConns when their
// states transition, based on which it evaluates the state of
// ClientConn.
type ConnectivityStateEvaluator struct {
type connectivityStateEvaluator struct {
numReady uint64 // Number of addrConns in ready state.
numConnecting uint64 // Number of addrConns in connecting state.
numTransientFailure uint64 // Number of addrConns in transientFailure.
}

// RecordTransition records state change happening in every subConn and based on
// recordTransition records state change happening in every subConn and based on
// that it evaluates what aggregated state should be.
// It can only transition between Ready, Connecting and TransientFailure. Other states,
// Idle and Shutdown are transitioned into by ClientConn; in the beginning of the connection
// before any subConn is created ClientConn is in idle state. In the end when ClientConn
// closes it is in Shutdown state.
//
// recordTransition should only be called synchronously from the same goroutine.
func (cse *ConnectivityStateEvaluator) RecordTransition(
func (cse *connectivityStateEvaluator) recordTransition(
oldState,
newState connectivity.State,
) connectivity.State {
Expand Down Expand Up @@ -147,7 +147,7 @@ func (ref *subConnRef) streamsDecr() {
type gcpBalancer struct {
addrs []resolver.Address
cc balancer.ClientConn
csEvltr *ConnectivityStateEvaluator
csEvltr *connectivityStateEvaluator
state connectivity.State

mu sync.Mutex
Expand Down Expand Up @@ -303,7 +303,7 @@ func (gb *gcpBalancer) HandleSubConnStateChange(sc balancer.SubConn, s connectiv
gb.mu.Unlock()

oldAggrState := gb.state
gb.state = gb.csEvltr.RecordTransition(oldS, s)
gb.state = gb.csEvltr.recordTransition(oldS, s)

// Regenerate picker when one of the following happens:
// - this sc became ready from not-ready
Expand Down

0 comments on commit a0862e6

Please sign in to comment.