Skip to content

Commit ad81c20

Browse files
authored
pickfirstleaf: minor simplification to reconcileSubConnsLocked method (#7731)
1 parent b850ea5 commit ad81c20

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

balancer/pickfirst/pickfirstleaf/pickfirstleaf.go

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -314,21 +314,22 @@ func deDupAddresses(addrs []resolver.Address) []resolver.Address {
314314
return retAddrs
315315
}
316316

317+
// reconcileSubConnsLocked updates the active subchannels based on a new address
318+
// list from the resolver. It does this by:
319+
// - closing subchannels: any existing subchannels associated with addresses
320+
// that are no longer in the updated list are shut down.
321+
// - removing subchannels: entries for these closed subchannels are removed
322+
// from the subchannel map.
323+
//
324+
// This ensures that the subchannel map accurately reflects the current set of
325+
// addresses received from the name resolver.
317326
func (b *pickfirstBalancer) reconcileSubConnsLocked(newAddrs []resolver.Address) {
318-
// Remove old subConns that were not in new address list.
319-
oldAddrsMap := resolver.NewAddressMap()
320-
for _, k := range b.subConns.Keys() {
321-
oldAddrsMap.Set(k, true)
322-
}
323-
324-
// Flatten the new endpoint addresses.
325327
newAddrsMap := resolver.NewAddressMap()
326328
for _, addr := range newAddrs {
327329
newAddrsMap.Set(addr, true)
328330
}
329331

330-
// Shut them down and remove them.
331-
for _, oldAddr := range oldAddrsMap.Keys() {
332+
for _, oldAddr := range b.subConns.Keys() {
332333
if _, ok := newAddrsMap.Get(oldAddr); ok {
333334
continue
334335
}

0 commit comments

Comments
 (0)