Skip to content

Commit c0a8c38

Browse files
committed
dfawley review 2
1 parent 42925ab commit c0a8c38

File tree

3 files changed

+16
-10
lines changed

3 files changed

+16
-10
lines changed

xds/internal/balancer/clusterimpl/clusterimpl.go

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -414,16 +414,25 @@ type scWrapper struct {
414414
balancer.SubConn
415415
// locality needs to be atomic because it can be updated while being read by
416416
// the picker.
417-
locality atomic.Value // type clients.Locality
417+
locality atomic.Pointer[clients.Locality]
418418
}
419419

420420
func (scw *scWrapper) updateLocalityID(lID clients.Locality) {
421-
scw.locality.Store(lID)
421+
// Store a pointer to a new, heap-allocated clients.Locality because the
422+
// pointer (scw.locality) is stored in an atomic.Pointer, and must remain
423+
// valid for concurrent access by other goroutines even after this function
424+
// returns.
425+
l := new(clients.Locality)
426+
*l = lID
427+
scw.locality.Store(l)
422428
}
423429

424430
func (scw *scWrapper) localityID() clients.Locality {
425-
lID, _ := scw.locality.Load().(clients.Locality)
426-
return lID
431+
lID := scw.locality.Load()
432+
if lID == nil {
433+
return clients.Locality{}
434+
}
435+
return *lID
427436
}
428437

429438
func (b *clusterImplBalancer) NewSubConn(addrs []resolver.Address, opts balancer.NewSubConnOptions) (balancer.SubConn, error) {
@@ -444,7 +453,7 @@ func (b *clusterImplBalancer) NewSubConn(addrs []resolver.Address, opts balancer
444453
// address's locality. https://github.com/grpc/grpc-go/issues/7339
445454
addr := connectedAddress(state)
446455
lID := xdsinternal.GetLocalityID(addr)
447-
if xdsinternal.IsLocalityEmpty(lID) {
456+
if (lID == clients.Locality{}) {
448457
if b.logger.V(2) {
449458
b.logger.Infof("Locality ID for %s unexpectedly empty", addr)
450459
}

xds/internal/clients/lrsclient/load_store.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ func newLoadStore() *LoadStore {
7272
//
7373
// The provided context must have a deadline or timeout set to prevent Stop
7474
// from blocking indefinitely if the final send attempt fails to complete.
75+
//
76+
// Calling Stop on an already stopped LoadStore is a no-op.
7577
func (ls *LoadStore) Stop(ctx context.Context) {
7678
ls.stop(ctx)
7779
}

xds/internal/internal.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,6 @@ func IsLocalityEqual(l clients.Locality, o any) bool {
4141
return l.Region == ol.Region && l.Zone == ol.Zone && l.SubZone == ol.SubZone
4242
}
4343

44-
// IsLocalityEmpty returns whether or not the clients.locality is empty.
45-
func IsLocalityEmpty(l clients.Locality) bool {
46-
return l.Region == "" && l.Zone == "" && l.SubZone == ""
47-
}
48-
4944
// LocalityFromString converts a string representation of clients.locality as
5045
// specified in gRFC A76, into a LocalityID struct.
5146
func LocalityFromString(s string) (ret clients.Locality, _ error) {

0 commit comments

Comments
 (0)