-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make BackedUpItems thread safe #8366
Make BackedUpItems thread safe #8366
Conversation
a9342af
to
ec5d953
Compare
ec5d953
to
f7f2402
Compare
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #8366 +/- ##
==========================================
+ Coverage 58.98% 59.04% +0.06%
==========================================
Files 368 369 +1
Lines 39000 39046 +46
==========================================
+ Hits 23004 23056 +52
+ Misses 14532 14527 -5
+ Partials 1464 1463 -1 ☔ View full report in Codecov by Sentry. |
pkg/backup/backed_up_items_map.go
Outdated
return len(m.BackedUpItems) | ||
} | ||
|
||
func (m *backedUpItemsMap) ItemInBackup(key itemKey) bool { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am fine with the current names. But just thought of ItemInBackup
<-> IsItemBackedup
and AddItem
<-> MarkItemBackedup
f7f2402
to
d2da99d
Compare
Minor updates, but I didn't use |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://pkg.go.dev/k8s.io/apimachinery/pkg/util/sets#Set has some of the functions being defined here. If the functions for backedUpItemsMap might grow, it might be wise to use the package there. Otherwise this lgtm.
pkg/backup/backed_up_items_map.go
Outdated
func (m *backedUpItemsMap) CopyItemList() map[itemKey]struct{} { | ||
m.RLock() | ||
defer m.RUnlock() | ||
returnMap := map[itemKey]struct{}{} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
returnMap := map[itemKey]struct{}{} | |
returnMap := make(map[itemKey]struct{}, len(m.BackedUpItems)) |
pkg/backup/backed_up_items_map.go
Outdated
// backedUpItemsMap keeps track of the items already backed up for the current Velero Backup | ||
type backedUpItemsMap struct { | ||
*sync.RWMutex | ||
BackedUpItems map[itemKey]struct{} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a need to expose "BackedUpItems"? i.e. BackedUpItems -> backedUpItems
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't referenced from outside, so you're right -- no need to expose.
pkg/backup/backed_up_items_map.go
Outdated
} | ||
} | ||
|
||
func (m *backedUpItemsMap) CopyItemList() map[itemKey]struct{} { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not call it "CopyItemMap"? In the func the variable it returns is even called "returnMap"
pkg/backup/backed_up_items_map.go
Outdated
return returnMap | ||
} | ||
|
||
func (m *backedUpItemsMap) ResourceList() map[string][]string { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- If the func returns a map, it would be better to call lit "ResourceMap()"
- It would be better to add some comments to explain what the key and value look like in the returned map.
pkg/backup/backed_up_items_map.go
Outdated
return len(m.BackedUpItems) | ||
} | ||
|
||
func (m *backedUpItemsMap) ItemInBackup(key itemKey) bool { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would call it "Has(key)" but it's trivial...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also like Contains()
Signed-off-by: Scott Seago <[email protected]>
015b1e6
d18cf3c
to
015b1e6
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm, thanks Scott!
Thank you for contributing to Velero!
Please add a summary of your change
This PR synchronizes access to backupRequest.BackedUpItems with an RWMutex so that multiple ItemBlock processing goroutines will be able to access it.
Does your change fix a particular issue?
Fixes #7148
Please indicate you've done the following:
make new-changelog
) or comment/kind changelog-not-required
on this PR.site/content/docs/main
.