build combines sub-states into one. Caller must hold wbsa.mu.
()
| 250 | // |
| 251 | // Caller must hold wbsa.mu. |
| 252 | func (wbsa *Aggregator) build() balancer.State { |
| 253 | wbsa.logger.Infof("Child pickers with config: %+v", wbsa.idToPickerState) |
| 254 | |
| 255 | if len(wbsa.idToPickerState) == 0 { |
| 256 | // This is the case when all sub-balancers are removed. |
| 257 | return balancer.State{ |
| 258 | ConnectivityState: connectivity.TransientFailure, |
| 259 | Picker: base.NewErrPicker(errors.New("weighted-target: no targets to pick from")), |
| 260 | } |
| 261 | } |
| 262 | |
| 263 | // Make sure picker's return error is consistent with the aggregatedState. |
| 264 | pickers := make([]weightedPickerState, 0, len(wbsa.idToPickerState)) |
| 265 | |
| 266 | switch aggState := wbsa.csEvltr.CurrentState(); aggState { |
| 267 | case connectivity.Connecting: |
| 268 | return balancer.State{ |
| 269 | ConnectivityState: aggState, |
| 270 | Picker: base.NewErrPicker(balancer.ErrNoSubConnAvailable)} |
| 271 | case connectivity.TransientFailure: |
| 272 | // this means that all sub-balancers are now in TransientFailure. |
| 273 | for _, ps := range wbsa.idToPickerState { |
| 274 | pickers = append(pickers, *ps) |
| 275 | } |
| 276 | return balancer.State{ |
| 277 | ConnectivityState: aggState, |
| 278 | Picker: newWeightedPickerGroup(pickers, wbsa.newWRR)} |
| 279 | default: |
| 280 | for _, ps := range wbsa.idToPickerState { |
| 281 | if ps.stateToAggregate == connectivity.Ready { |
| 282 | pickers = append(pickers, *ps) |
| 283 | } |
| 284 | } |
| 285 | return balancer.State{ |
| 286 | ConnectivityState: aggState, |
| 287 | Picker: newWeightedPickerGroup(pickers, wbsa.newWRR)} |
| 288 | } |
| 289 | |
| 290 | } |
| 291 | |
| 292 | type weightedPickerGroup struct { |
| 293 | w wrr.WRR |
no test coverage detected