@@ -122,7 +122,7 @@ func (pickfirstBuilder) Build(cc balancer.ClientConn, bo balancer.BuildOptions)
122122 target : bo .Target .String (),
123123 metricsRecorder : cc .MetricsRecorder (),
124124
125- subConns : resolver .NewAddressMap (),
125+ subConns : resolver .NewAddressMapV2 [ * scData ] (),
126126 state : connectivity .Connecting ,
127127 cancelConnectionTimer : func () {},
128128 }
@@ -220,7 +220,7 @@ type pickfirstBalancer struct {
220220 // updates.
221221 state connectivity.State
222222 // scData for active subonns mapped by address.
223- subConns * resolver.AddressMap
223+ subConns * resolver.AddressMapV2 [ * scData ]
224224 addressList addressList
225225 firstPass bool
226226 numTF int
@@ -319,7 +319,7 @@ func (b *pickfirstBalancer) UpdateClientConnState(state balancer.ClientConnState
319319 prevAddr := b .addressList .currentAddress ()
320320 prevSCData , found := b .subConns .Get (prevAddr )
321321 prevAddrsCount := b .addressList .size ()
322- isPrevRawConnectivityStateReady := found && prevSCData .( * scData ). rawConnectivityState == connectivity .Ready
322+ isPrevRawConnectivityStateReady := found && prevSCData .rawConnectivityState == connectivity .Ready
323323 b .addressList .updateAddrs (newAddrs )
324324
325325 // If the previous ready SubConn exists in new address list,
@@ -381,21 +381,21 @@ func (b *pickfirstBalancer) startFirstPassLocked() {
381381 b .numTF = 0
382382 // Reset the connection attempt record for existing SubConns.
383383 for _ , sd := range b .subConns .Values () {
384- sd .( * scData ). connectionFailedInFirstPass = false
384+ sd .connectionFailedInFirstPass = false
385385 }
386386 b .requestConnectionLocked ()
387387}
388388
389389func (b * pickfirstBalancer ) closeSubConnsLocked () {
390390 for _ , sd := range b .subConns .Values () {
391- sd .( * scData ). subConn .Shutdown ()
391+ sd .subConn .Shutdown ()
392392 }
393- b .subConns = resolver .NewAddressMap ()
393+ b .subConns = resolver .NewAddressMapV2 [ * scData ] ()
394394}
395395
396396// deDupAddresses ensures that each address appears only once in the slice.
397397func deDupAddresses (addrs []resolver.Address ) []resolver.Address {
398- seenAddrs := resolver .NewAddressMap ()
398+ seenAddrs := resolver .NewAddressMapV2 [ * scData ] ()
399399 retAddrs := []resolver.Address {}
400400
401401 for _ , addr := range addrs {
@@ -481,7 +481,7 @@ func addressFamily(address string) ipAddrFamily {
481481// This ensures that the subchannel map accurately reflects the current set of
482482// addresses received from the name resolver.
483483func (b * pickfirstBalancer ) reconcileSubConnsLocked (newAddrs []resolver.Address ) {
484- newAddrsMap := resolver .NewAddressMap ()
484+ newAddrsMap := resolver .NewAddressMapV2 [ bool ] ()
485485 for _ , addr := range newAddrs {
486486 newAddrsMap .Set (addr , true )
487487 }
@@ -491,7 +491,7 @@ func (b *pickfirstBalancer) reconcileSubConnsLocked(newAddrs []resolver.Address)
491491 continue
492492 }
493493 val , _ := b .subConns .Get (oldAddr )
494- val .( * scData ). subConn .Shutdown ()
494+ val .subConn .Shutdown ()
495495 b .subConns .Delete (oldAddr )
496496 }
497497}
@@ -500,13 +500,12 @@ func (b *pickfirstBalancer) reconcileSubConnsLocked(newAddrs []resolver.Address)
500500// becomes ready, which means that all other subConn must be shutdown.
501501func (b * pickfirstBalancer ) shutdownRemainingLocked (selected * scData ) {
502502 b .cancelConnectionTimer ()
503- for _ , v := range b .subConns .Values () {
504- sd := v .(* scData )
503+ for _ , sd := range b .subConns .Values () {
505504 if sd .subConn != selected .subConn {
506505 sd .subConn .Shutdown ()
507506 }
508507 }
509- b .subConns = resolver .NewAddressMap ()
508+ b .subConns = resolver .NewAddressMapV2 [ * scData ] ()
510509 b .subConns .Set (selected .addr , selected )
511510}
512511
@@ -539,26 +538,25 @@ func (b *pickfirstBalancer) requestConnectionLocked() {
539538 b .subConns .Set (curAddr , sd )
540539 }
541540
542- scd := sd .(* scData )
543- switch scd .rawConnectivityState {
541+ switch sd .rawConnectivityState {
544542 case connectivity .Idle :
545- scd .subConn .Connect ()
543+ sd .subConn .Connect ()
546544 b .scheduleNextConnectionLocked ()
547545 return
548546 case connectivity .TransientFailure :
549547 // The SubConn is being re-used and failed during a previous pass
550548 // over the addressList. It has not completed backoff yet.
551549 // Mark it as having failed and try the next address.
552- scd .connectionFailedInFirstPass = true
553- lastErr = scd .lastErr
550+ sd .connectionFailedInFirstPass = true
551+ lastErr = sd .lastErr
554552 continue
555553 case connectivity .Connecting :
556554 // Wait for the connection attempt to complete or the timer to fire
557555 // before attempting the next address.
558556 b .scheduleNextConnectionLocked ()
559557 return
560558 default :
561- b .logger .Errorf ("SubConn with unexpected state %v present in SubConns map." , scd .rawConnectivityState )
559+ b .logger .Errorf ("SubConn with unexpected state %v present in SubConns map." , sd .rawConnectivityState )
562560 return
563561
564562 }
@@ -753,8 +751,7 @@ func (b *pickfirstBalancer) endFirstPassIfPossibleLocked(lastErr error) {
753751 }
754752 // Connect() has been called on all the SubConns. The first pass can be
755753 // ended if all the SubConns have reported a failure.
756- for _ , v := range b .subConns .Values () {
757- sd := v .(* scData )
754+ for _ , sd := range b .subConns .Values () {
758755 if ! sd .connectionFailedInFirstPass {
759756 return
760757 }
@@ -765,8 +762,7 @@ func (b *pickfirstBalancer) endFirstPassIfPossibleLocked(lastErr error) {
765762 Picker : & picker {err : lastErr },
766763 })
767764 // Start re-connecting all the SubConns that are already in IDLE.
768- for _ , v := range b .subConns .Values () {
769- sd := v .(* scData )
765+ for _ , sd := range b .subConns .Values () {
770766 if sd .rawConnectivityState == connectivity .Idle {
771767 sd .subConn .Connect ()
772768 }
0 commit comments