Skip to content

Commit

Permalink
Move ejection tracking to sc wrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
arjan-bal committed Dec 17, 2024
1 parent 6a6aa7a commit 1af2206
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 19 deletions.
20 changes: 1 addition & 19 deletions xds/internal/balancer/outlierdetection/balancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -593,29 +593,11 @@ func (b *outlierDetectionBalancer) Target() string {
func (b *outlierDetectionBalancer) handleSubConnUpdate(u *scUpdate) {
scw := u.scw
scw.clearHealthListener()

if scw.listener == nil {
return
}

// If the health listener is being used for ejection, forward the
// connectivity updates unconditionally.
if scw.healthListenerEnabled {
b.child.updateSubConnState(scw, u.state)
return
}

// Raw connectivity listener is being used for ejection.
if scw.ejected {
return
}
b.child.updateSubConnState(scw, u.state)
}

func (b *outlierDetectionBalancer) handleSubConnHealthUpdate(u *scHealthUpdate) {
if !u.scw.ejected {
b.child.updateSubConnHealthState(u.scw, u.state)
}
b.child.updateSubConnHealthState(u.scw, u.state)
}

// handleEjectedUpdate handles any SubConns that get ejected/unejected, and
Expand Down
8 changes: 8 additions & 0 deletions xds/internal/balancer/outlierdetection/subconn_wrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,9 @@ func (scw *subConnWrapper) RegisterHealthListener(listener func(balancer.SubConn
// sends updates the health listener.
func (scw *subConnWrapper) updateSubConnHealthState(scs balancer.SubConnState) {
scw.latestHealthState = scs
if scw.ejected {
return
}

Check warning on line 145 in xds/internal/balancer/outlierdetection/subconn_wrapper.go

View check run for this annotation

Codecov / codecov/patch

xds/internal/balancer/outlierdetection/subconn_wrapper.go#L144-L145

Added lines #L144 - L145 were not covered by tests
scw.mu.Lock()
defer scw.mu.Unlock()
if scw.healthListener != nil {
Expand All @@ -151,6 +154,11 @@ func (scw *subConnWrapper) updateSubConnHealthState(scs balancer.SubConnState) {
// unejection and updates the raw connectivity listener.
func (scw *subConnWrapper) updateSubConnConnectivityState(scs balancer.SubConnState) {
scw.latestRawConnectivityState = scs
// If the raw connectivity listener is used for ejection, and the SubConn is
// ejected, don't send the update.
if scw.ejected && !scw.healthListenerEnabled {
return
}
if scw.listener != nil {
scw.listener(scs)
}
Expand Down

0 comments on commit 1af2206

Please sign in to comment.