add sync map to fix cocurrent write #2918
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What type of this PR
Examples of user facing changes:
Which issue(s) this PR fixes:
Fixes #2907
WHAT
馃 Generated by Copilot at 67e9f20
This pull request enhances the pod deletion logic in the
Controller
type by using async.Map
for thedeletingPodObjMap
field. This improves the thread-safety and performance of the controller when handling pod deletion events. The pull request modifiespkg/controller/controller.go
andpkg/controller/pod.go
to use thesync.Map
type.馃 Generated by Copilot at 67e9f20
HOW
馃 Generated by Copilot at 67e9f20
sync.Map
fordeletingPodObjMap
field ofController
type to improve thread-safety and avoid concurrent map access errors (link, link)Store
method ofsync.Map
to atomically set the value for a key indeletingPodObjMap
in various functions that enqueue pod events (link, link, link, link, link, link, link, link)Load
method ofsync.Map
to atomically get the value for a key indeletingPodObjMap
in functions that process pod deletion events (link, link)Delete
method ofsync.Map
to atomically remove the value for a key indeletingPodObjMap
inprocessNextDeletePodWorkItem
function (link)Load
method to handle the case where the key is not found indeletingPodObjMap
inhandleDeletePod
function (link)