Commit 01d6ac64 authored by Kubernetes Submit Queue's avatar Kubernetes Submit Queue Committed by GitHub

Merge pull request #29898 from matttproud/refactor/simplify/garbagecollector

Automatic merge from submit-queue pkg/controller/garbagecollector: simplify mutexes. pkg/controller/garbagecollector: simplified synchronization and made idiomatic. Similar to #29598, we can rely on the zero-value construction behavior to embed `sync.Mutex` into parent structs. <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.kubernetes.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.kubernetes.io/reviews/kubernetes/kubernetes/29898) <!-- Reviewable:end -->
parents 733fc698 1ca99119
...@@ -68,7 +68,7 @@ func (s objectReference) String() string { ...@@ -68,7 +68,7 @@ func (s objectReference) String() string {
type node struct { type node struct {
identity objectReference identity objectReference
// dependents will be read by the orphan() routine, we need to protect it with a lock. // dependents will be read by the orphan() routine, we need to protect it with a lock.
dependentsLock *sync.RWMutex dependentsLock sync.RWMutex
dependents map[*node]struct{} dependents map[*node]struct{}
// When processing an Update event, we need to compare the updated // When processing an Update event, we need to compare the updated
// ownerReferences with the owners recorded in the graph. // ownerReferences with the owners recorded in the graph.
...@@ -152,8 +152,7 @@ func (p *Propagator) addDependentToOwners(n *node, owners []metatypes.OwnerRefer ...@@ -152,8 +152,7 @@ func (p *Propagator) addDependentToOwners(n *node, owners []metatypes.OwnerRefer
OwnerReference: owner, OwnerReference: owner,
Namespace: n.identity.Namespace, Namespace: n.identity.Namespace,
}, },
dependentsLock: &sync.RWMutex{}, dependents: make(map[*node]struct{}),
dependents: make(map[*node]struct{}),
} }
glog.V(6).Infof("add virtual node.identity: %s\n\n", ownerNode.identity) glog.V(6).Infof("add virtual node.identity: %s\n\n", ownerNode.identity)
p.uidToNode.Write(ownerNode) p.uidToNode.Write(ownerNode)
...@@ -380,9 +379,8 @@ func (p *Propagator) processEvent() { ...@@ -380,9 +379,8 @@ func (p *Propagator) processEvent() {
}, },
Namespace: accessor.GetNamespace(), Namespace: accessor.GetNamespace(),
}, },
dependentsLock: &sync.RWMutex{}, dependents: make(map[*node]struct{}),
dependents: make(map[*node]struct{}), owners: accessor.GetOwnerReferences(),
owners: accessor.GetOwnerReferences(),
} }
p.insertNode(newNode) p.insertNode(newNode)
// the underlying delta_fifo may combine a creation and deletion into one event // the underlying delta_fifo may combine a creation and deletion into one event
......
...@@ -314,7 +314,7 @@ func TestDependentsRace(t *testing.T) { ...@@ -314,7 +314,7 @@ func TestDependentsRace(t *testing.T) {
} }
const updates = 100 const updates = 100
owner := &node{dependentsLock: &sync.RWMutex{}, dependents: make(map[*node]struct{})} owner := &node{dependents: make(map[*node]struct{})}
ownerUID := types.UID("owner") ownerUID := types.UID("owner")
gc.propagator.uidToNode.Write(owner) gc.propagator.uidToNode.Write(owner)
go func() { go func() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment