From 61b0ee6b0e0fd5a598ba9cef9513017ea37a6fb2 Mon Sep 17 00:00:00 2001 From: Keerthan Ekbote Date: Sat, 18 May 2024 10:12:51 +1000 Subject: [PATCH 1/2] add read locks to shallow copy and unionSortedSet --- contrib/pkg/sets/v2/sets.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/contrib/pkg/sets/v2/sets.go b/contrib/pkg/sets/v2/sets.go index b68d7279..052430c4 100644 --- a/contrib/pkg/sets/v2/sets.go +++ b/contrib/pkg/sets/v2/sets.go @@ -246,6 +246,8 @@ func (s *resourceSet[T]) Union(set ResourceSet[T]) ResourceSet[T] { // Assuming that the argument set is sorted by resource id, // this method will efficiently union the two sets together and return the unioned set. func (s *resourceSet[T]) unionSortedSet(set ResourceSet[T]) *resourceSet[T] { + s.lock.RLock() + defer s.lock.RUnlock() merged := make([]T, 0, len(s.set)+set.Len()) idx := 0 @@ -373,6 +375,8 @@ func (oldSet *resourceSet[T]) Clone() ResourceSet[T] { } func (oldSet *resourceSet[T]) ShallowCopy() ResourceSet[T] { + oldSet.lock.RLock() + defer oldSet.lock.RUnlock() newSet := make([]T, len(oldSet.set)) copy(newSet, oldSet.set) return &resourceSet[T]{ From 856a0f9a13a69e26ab91299cf233bcc77e1842d7 Mon Sep 17 00:00:00 2001 From: Keerthan Ekbote Date: Sat, 18 May 2024 10:13:30 +1000 Subject: [PATCH 2/2] add changelog --- changelog/v0.40.1/sets-union-addRlock.yaml | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 changelog/v0.40.1/sets-union-addRlock.yaml diff --git a/changelog/v0.40.1/sets-union-addRlock.yaml b/changelog/v0.40.1/sets-union-addRlock.yaml new file mode 100644 index 00000000..c4d0af80 --- /dev/null +++ b/changelog/v0.40.1/sets-union-addRlock.yaml @@ -0,0 +1,5 @@ +changelog: + - type: NON_USER_FACING + description: > + "Adds Read Lock to ShallowCopy and Union methods on sets" + skipCI: "false"