@@ -122,7 +122,7 @@ func (pickfirstBuilder) Build(cc balancer.ClientConn, bo balancer.BuildOptions)
122
122
target : bo .Target .String (),
123
123
metricsRecorder : cc .MetricsRecorder (),
124
124
125
- subConns : resolver .NewAddressMap (),
125
+ subConns : resolver .NewAddressMapV2 [ * scData ] (),
126
126
state : connectivity .Connecting ,
127
127
cancelConnectionTimer : func () {},
128
128
}
@@ -220,7 +220,7 @@ type pickfirstBalancer struct {
220
220
// updates.
221
221
state connectivity.State
222
222
// scData for active subonns mapped by address.
223
- subConns * resolver.AddressMap
223
+ subConns * resolver.AddressMapV2 [ * scData ]
224
224
addressList addressList
225
225
firstPass bool
226
226
numTF int
@@ -319,7 +319,7 @@ func (b *pickfirstBalancer) UpdateClientConnState(state balancer.ClientConnState
319
319
prevAddr := b .addressList .currentAddress ()
320
320
prevSCData , found := b .subConns .Get (prevAddr )
321
321
prevAddrsCount := b .addressList .size ()
322
- isPrevRawConnectivityStateReady := found && prevSCData .( * scData ). rawConnectivityState == connectivity .Ready
322
+ isPrevRawConnectivityStateReady := found && prevSCData .rawConnectivityState == connectivity .Ready
323
323
b .addressList .updateAddrs (newAddrs )
324
324
325
325
// If the previous ready SubConn exists in new address list,
@@ -381,21 +381,21 @@ func (b *pickfirstBalancer) startFirstPassLocked() {
381
381
b .numTF = 0
382
382
// Reset the connection attempt record for existing SubConns.
383
383
for _ , sd := range b .subConns .Values () {
384
- sd .( * scData ). connectionFailedInFirstPass = false
384
+ sd .connectionFailedInFirstPass = false
385
385
}
386
386
b .requestConnectionLocked ()
387
387
}
388
388
389
389
func (b * pickfirstBalancer ) closeSubConnsLocked () {
390
390
for _ , sd := range b .subConns .Values () {
391
- sd .( * scData ). subConn .Shutdown ()
391
+ sd .subConn .Shutdown ()
392
392
}
393
- b .subConns = resolver .NewAddressMap ()
393
+ b .subConns = resolver .NewAddressMapV2 [ * scData ] ()
394
394
}
395
395
396
396
// deDupAddresses ensures that each address appears only once in the slice.
397
397
func deDupAddresses (addrs []resolver.Address ) []resolver.Address {
398
- seenAddrs := resolver .NewAddressMap ()
398
+ seenAddrs := resolver .NewAddressMapV2 [ * scData ] ()
399
399
retAddrs := []resolver.Address {}
400
400
401
401
for _ , addr := range addrs {
@@ -481,7 +481,7 @@ func addressFamily(address string) ipAddrFamily {
481
481
// This ensures that the subchannel map accurately reflects the current set of
482
482
// addresses received from the name resolver.
483
483
func (b * pickfirstBalancer ) reconcileSubConnsLocked (newAddrs []resolver.Address ) {
484
- newAddrsMap := resolver .NewAddressMap ()
484
+ newAddrsMap := resolver .NewAddressMapV2 [ bool ] ()
485
485
for _ , addr := range newAddrs {
486
486
newAddrsMap .Set (addr , true )
487
487
}
@@ -491,7 +491,7 @@ func (b *pickfirstBalancer) reconcileSubConnsLocked(newAddrs []resolver.Address)
491
491
continue
492
492
}
493
493
val , _ := b .subConns .Get (oldAddr )
494
- val .( * scData ). subConn .Shutdown ()
494
+ val .subConn .Shutdown ()
495
495
b .subConns .Delete (oldAddr )
496
496
}
497
497
}
@@ -500,13 +500,12 @@ func (b *pickfirstBalancer) reconcileSubConnsLocked(newAddrs []resolver.Address)
500
500
// becomes ready, which means that all other subConn must be shutdown.
501
501
func (b * pickfirstBalancer ) shutdownRemainingLocked (selected * scData ) {
502
502
b .cancelConnectionTimer ()
503
- for _ , v := range b .subConns .Values () {
504
- sd := v .(* scData )
503
+ for _ , sd := range b .subConns .Values () {
505
504
if sd .subConn != selected .subConn {
506
505
sd .subConn .Shutdown ()
507
506
}
508
507
}
509
- b .subConns = resolver .NewAddressMap ()
508
+ b .subConns = resolver .NewAddressMapV2 [ * scData ] ()
510
509
b .subConns .Set (selected .addr , selected )
511
510
}
512
511
@@ -539,26 +538,25 @@ func (b *pickfirstBalancer) requestConnectionLocked() {
539
538
b .subConns .Set (curAddr , sd )
540
539
}
541
540
542
- scd := sd .(* scData )
543
- switch scd .rawConnectivityState {
541
+ switch sd .rawConnectivityState {
544
542
case connectivity .Idle :
545
- scd .subConn .Connect ()
543
+ sd .subConn .Connect ()
546
544
b .scheduleNextConnectionLocked ()
547
545
return
548
546
case connectivity .TransientFailure :
549
547
// The SubConn is being re-used and failed during a previous pass
550
548
// over the addressList. It has not completed backoff yet.
551
549
// 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
554
552
continue
555
553
case connectivity .Connecting :
556
554
// Wait for the connection attempt to complete or the timer to fire
557
555
// before attempting the next address.
558
556
b .scheduleNextConnectionLocked ()
559
557
return
560
558
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 )
562
560
return
563
561
564
562
}
@@ -753,8 +751,7 @@ func (b *pickfirstBalancer) endFirstPassIfPossibleLocked(lastErr error) {
753
751
}
754
752
// Connect() has been called on all the SubConns. The first pass can be
755
753
// 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 () {
758
755
if ! sd .connectionFailedInFirstPass {
759
756
return
760
757
}
@@ -765,8 +762,7 @@ func (b *pickfirstBalancer) endFirstPassIfPossibleLocked(lastErr error) {
765
762
Picker : & picker {err : lastErr },
766
763
})
767
764
// 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 () {
770
766
if sd .rawConnectivityState == connectivity .Idle {
771
767
sd .subConn .Connect ()
772
768
}
0 commit comments