(s balancer.ClientConnState)
| 93 | } |
| 94 | |
| 95 | func (b *baseBalancer) UpdateClientConnState(s balancer.ClientConnState) error { |
| 96 | // TODO: handle s.ResolverState.ServiceConfig? |
| 97 | if logger.V(2) { |
| 98 | logger.Info("base.baseBalancer: got new ClientConn state: ", s) |
| 99 | } |
| 100 | // Successful resolution; clear resolver error and ensure we return nil. |
| 101 | b.resolverErr = nil |
| 102 | // addrsSet is the set converted from addrs, it's used for quick lookup of an address. |
| 103 | addrsSet := resolver.NewAddressMapV2[any]() |
| 104 | for _, a := range s.ResolverState.Addresses { |
| 105 | addrsSet.Set(a, nil) |
| 106 | if _, ok := b.subConns.Get(a); !ok { |
| 107 | // a is a new address (not existing in b.subConns). |
| 108 | var sc balancer.SubConn |
| 109 | opts := balancer.NewSubConnOptions{ |
| 110 | HealthCheckEnabled: b.config.HealthCheck, |
| 111 | StateListener: func(scs balancer.SubConnState) { b.updateSubConnState(sc, scs) }, |
| 112 | } |
| 113 | sc, err := b.cc.NewSubConn([]resolver.Address{a}, opts) |
| 114 | if err != nil { |
| 115 | logger.Warningf("base.baseBalancer: failed to create new SubConn: %v", err) |
| 116 | continue |
| 117 | } |
| 118 | b.subConns.Set(a, sc) |
| 119 | b.scStates[sc] = connectivity.Idle |
| 120 | b.csEvltr.RecordTransition(connectivity.Shutdown, connectivity.Idle) |
| 121 | sc.Connect() |
| 122 | } |
| 123 | } |
| 124 | for a, sc := range b.subConns.All() { |
| 125 | // a was removed by resolver. |
| 126 | if _, ok := addrsSet.Get(a); !ok { |
| 127 | sc.Shutdown() |
| 128 | b.subConns.Delete(a) |
| 129 | // Keep the state of this sc in b.scStates until sc's state becomes Shutdown. |
| 130 | // The entry will be deleted in updateSubConnState. |
| 131 | } |
| 132 | } |
| 133 | // If resolver state contains no addresses, return an error so ClientConn |
| 134 | // will trigger re-resolve. Also records this as a resolver error, so when |
| 135 | // the overall state turns transient failure, the error message will have |
| 136 | // the zero address information. |
| 137 | if len(s.ResolverState.Addresses) == 0 { |
| 138 | b.ResolverError(errors.New("produced zero addresses")) |
| 139 | return balancer.ErrBadResolverState |
| 140 | } |
| 141 | |
| 142 | b.regeneratePicker() |
| 143 | b.cc.UpdateState(balancer.State{ConnectivityState: b.state, Picker: b.picker}) |
| 144 | return nil |
| 145 | } |
| 146 | |
| 147 | // mergeErrors builds an error from the last connection error and the last |
| 148 | // resolver error. Must only be called if b.state is TransientFailure. |
nothing calls this directly
no test coverage detected