mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-08 03:33:56 +00:00
Merge pull request #118189 from Miciah/118188-TopologyAwareHints-take-lock-in-HasPopulatedHints
TopologyAwareHints: Take lock in HasPopulatedHints
This commit is contained in:
commit
10a252aa54
@ -153,8 +153,10 @@ func (t *TopologyCache) AddHints(logger klog.Logger, si *SliceInfo) ([]*discover
|
|||||||
return slicesToCreate, slicesToUpdate, events
|
return slicesToCreate, slicesToUpdate, events
|
||||||
}
|
}
|
||||||
|
|
||||||
hintsEnabled := t.hintsPopulatedByService.Has(si.ServiceKey)
|
t.lock.Lock()
|
||||||
t.SetHints(si.ServiceKey, si.AddressType, allocatedHintsByZone)
|
defer t.lock.Unlock()
|
||||||
|
hintsEnabled := t.hasPopulatedHintsLocked(si.ServiceKey)
|
||||||
|
t.setHintsLocked(si.ServiceKey, si.AddressType, allocatedHintsByZone)
|
||||||
|
|
||||||
// if hints were not enabled before, we publish an event to indicate we enabled them.
|
// if hints were not enabled before, we publish an event to indicate we enabled them.
|
||||||
if !hintsEnabled {
|
if !hintsEnabled {
|
||||||
@ -174,6 +176,10 @@ func (t *TopologyCache) SetHints(serviceKey string, addrType discovery.AddressTy
|
|||||||
t.lock.Lock()
|
t.lock.Lock()
|
||||||
defer t.lock.Unlock()
|
defer t.lock.Unlock()
|
||||||
|
|
||||||
|
t.setHintsLocked(serviceKey, addrType, allocatedHintsByZone)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t *TopologyCache) setHintsLocked(serviceKey string, addrType discovery.AddressType, allocatedHintsByZone EndpointZoneInfo) {
|
||||||
_, ok := t.endpointsByService[serviceKey]
|
_, ok := t.endpointsByService[serviceKey]
|
||||||
if !ok {
|
if !ok {
|
||||||
t.endpointsByService[serviceKey] = map[discovery.AddressType]EndpointZoneInfo{}
|
t.endpointsByService[serviceKey] = map[discovery.AddressType]EndpointZoneInfo{}
|
||||||
@ -262,6 +268,13 @@ func (t *TopologyCache) SetNodes(logger klog.Logger, nodes []*v1.Node) {
|
|||||||
|
|
||||||
// HasPopulatedHints checks whether there are populated hints for a given service in the cache.
|
// HasPopulatedHints checks whether there are populated hints for a given service in the cache.
|
||||||
func (t *TopologyCache) HasPopulatedHints(serviceKey string) bool {
|
func (t *TopologyCache) HasPopulatedHints(serviceKey string) bool {
|
||||||
|
t.lock.Lock()
|
||||||
|
defer t.lock.Unlock()
|
||||||
|
|
||||||
|
return t.hasPopulatedHintsLocked(serviceKey)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t *TopologyCache) hasPopulatedHintsLocked(serviceKey string) bool {
|
||||||
return t.hintsPopulatedByService.Has(serviceKey)
|
return t.hintsPopulatedByService.Has(serviceKey)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -690,6 +690,9 @@ func TestTopologyCacheRace(t *testing.T) {
|
|||||||
go func() {
|
go func() {
|
||||||
cache.AddHints(logger, sliceInfo)
|
cache.AddHints(logger, sliceInfo)
|
||||||
}()
|
}()
|
||||||
|
go func() {
|
||||||
|
cache.HasPopulatedHints(sliceInfo.ServiceKey)
|
||||||
|
}()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Test Helpers
|
// Test Helpers
|
||||||
|
Loading…
Reference in New Issue
Block a user