Skip to content

Commit 9c46304

Browse files
authored
xds/cdsbalancer: stop handling subconn state updates (#6509)
1 parent e9a4e94 commit 9c46304

File tree

2 files changed

+1
-83
lines changed

2 files changed

+1
-83
lines changed

xds/internal/balancer/cdsbalancer/cdsbalancer.go

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -149,13 +149,6 @@ type ccUpdate struct {
149149
err error
150150
}
151151

152-
// scUpdate wraps a subConn update received from gRPC. This is directly passed
153-
// on to the cluster_resolver balancer.
154-
type scUpdate struct {
155-
subConn balancer.SubConn
156-
state balancer.SubConnState
157-
}
158-
159152
type exitIdle struct{}
160153

161154
// cdsBalancer implements a CDS based LB policy. It instantiates a
@@ -415,14 +408,6 @@ func (b *cdsBalancer) run() {
415408
switch update := u.(type) {
416409
case *ccUpdate:
417410
b.handleClientConnUpdate(update)
418-
case *scUpdate:
419-
// SubConn updates are passthrough and are simply handed over to
420-
// the underlying cluster_resolver balancer.
421-
if b.childLB == nil {
422-
b.logger.Errorf("Received SubConn update with no child policy: %+v", update)
423-
break
424-
}
425-
b.childLB.UpdateSubConnState(update.subConn, update.state)
426411
case exitIdle:
427412
if b.childLB == nil {
428413
b.logger.Errorf("Received ExitIdle with no child policy")
@@ -540,11 +525,7 @@ func (b *cdsBalancer) ResolverError(err error) {
540525

541526
// UpdateSubConnState handles subConn updates from gRPC.
542527
func (b *cdsBalancer) UpdateSubConnState(sc balancer.SubConn, state balancer.SubConnState) {
543-
if b.closed.HasFired() {
544-
b.logger.Warningf("Received subConn update after close: {%v, %v}", sc, state)
545-
return
546-
}
547-
b.updateCh.Put(&scUpdate{subConn: sc, state: state})
528+
b.logger.Errorf("UpdateSubConnState(%v, %+v) called unexpectedly", sc, state)
548529
}
549530

550531
// Close cancels the CDS watch, closes the child policy and closes the

xds/internal/balancer/cdsbalancer/cdsbalancer_test.go

Lines changed: 0 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ import (
2727
"github.com/google/go-cmp/cmp"
2828
"github.com/google/go-cmp/cmp/cmpopts"
2929
"google.golang.org/grpc/balancer"
30-
"google.golang.org/grpc/connectivity"
3130
"google.golang.org/grpc/internal"
3231
"google.golang.org/grpc/internal/grpctest"
3332
internalserviceconfig "google.golang.org/grpc/internal/serviceconfig"
@@ -175,20 +174,6 @@ func (tb *testEDSBalancer) waitForClientConnUpdate(ctx context.Context, wantCCS
175174
return nil
176175
}
177176

178-
// waitForSubConnUpdate verifies if the testEDSBalancer receives the provided
179-
// SubConn update before the context expires.
180-
func (tb *testEDSBalancer) waitForSubConnUpdate(ctx context.Context, wantSCS subConnWithState) error {
181-
scs, err := tb.scStateCh.Receive(ctx)
182-
if err != nil {
183-
return err
184-
}
185-
gotSCS := scs.(subConnWithState)
186-
if !cmp.Equal(gotSCS, wantSCS, cmp.AllowUnexported(subConnWithState{})) {
187-
return fmt.Errorf("received SubConnState: %+v, want %+v", gotSCS, wantSCS)
188-
}
189-
return nil
190-
}
191-
192177
// waitForResolverError verifies if the testEDSBalancer receives the provided
193178
// resolver error before the context expires.
194179
func (tb *testEDSBalancer) waitForResolverError(ctx context.Context, wantErr error) error {
@@ -698,45 +683,6 @@ func (s) TestResolverError(t *testing.T) {
698683
}
699684
}
700685

701-
// TestUpdateSubConnState verifies the UpdateSubConnState() method in the CDS
702-
// balancer.
703-
func (s) TestUpdateSubConnState(t *testing.T) {
704-
// This creates a CDS balancer, pushes a ClientConnState update with a fake
705-
// xdsClient, and makes sure that the CDS balancer registers a watch on the
706-
// provided xdsClient.
707-
xdsC, cdsB, edsB, _, cancel := setupWithWatch(t)
708-
defer func() {
709-
cancel()
710-
cdsB.Close()
711-
}()
712-
713-
// Here we invoke the watch callback registered on the fake xdsClient. This
714-
// will trigger the watch handler on the CDS balancer, which will attempt to
715-
// create a new EDS balancer. The fake EDS balancer created above will be
716-
// returned to the CDS balancer, because we have overridden the
717-
// newChildBalancer function as part of test setup.
718-
cdsUpdate := xdsresource.ClusterUpdate{
719-
ClusterName: serviceName,
720-
LBPolicy: wrrLocalityLBConfigJSON,
721-
}
722-
wantCCS := edsCCS(serviceName, nil, false, wrrLocalityLBConfigJSON, noopODLBCfgJSON)
723-
ctx, ctxCancel := context.WithTimeout(context.Background(), defaultTestTimeout)
724-
defer ctxCancel()
725-
if err := invokeWatchCbAndWait(ctx, xdsC, cdsWatchInfo{cdsUpdate, nil}, wantCCS, edsB); err != nil {
726-
t.Fatal(err)
727-
}
728-
729-
// Push a subConn state change to the CDS balancer.
730-
var sc balancer.SubConn
731-
state := balancer.SubConnState{ConnectivityState: connectivity.Ready}
732-
cdsB.UpdateSubConnState(sc, state)
733-
734-
// Make sure that the update is forwarded to the EDS balancer.
735-
if err := edsB.waitForSubConnUpdate(ctx, subConnWithState{sc: sc, state: state}); err != nil {
736-
t.Fatal(err)
737-
}
738-
}
739-
740686
// TestCircuitBreaking verifies that the CDS balancer correctly updates a
741687
// service's counter on watch updates.
742688
func (s) TestCircuitBreaking(t *testing.T) {
@@ -829,15 +775,6 @@ func (s) TestClose(t *testing.T) {
829775
t.Fatalf("UpdateClientConnState() after close returned %v, want %v", err, errBalancerClosed)
830776
}
831777

832-
// Make sure that the UpdateSubConnState() method on the CDS balancer does
833-
// not forward the update to the EDS balancer.
834-
cdsB.UpdateSubConnState(&testutils.TestSubConn{}, balancer.SubConnState{})
835-
sCtx, sCancel = context.WithTimeout(context.Background(), defaultTestShortTimeout)
836-
defer sCancel()
837-
if err := edsB.waitForSubConnUpdate(sCtx, subConnWithState{}); err != context.DeadlineExceeded {
838-
t.Fatal("UpdateSubConnState() forwarded to EDS balancer after Close()")
839-
}
840-
841778
// Make sure that the ResolverErr() method on the CDS balancer does not
842779
// forward the update to the EDS balancer.
843780
rErr := errors.New("cdsBalancer resolver error")

0 commit comments

Comments
 (0)