-
Notifications
You must be signed in to change notification settings - Fork 59
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
added function for histograms merge #73
added function for histograms merge #73
Conversation
h.mu.Lock() | ||
defer h.mu.Unlock() | ||
|
||
b.mu.RLock() |
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.
does Lock cover RLock as well?
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/sync#RWMutex.Lock
Lock locks rw for writing. If the lock is already locked for reading or writing, Lock blocks until the lock is available.
so just Lock is enough
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.
there're locks on different objects - write lock on a target histogram and read lock on src histogram
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.
oh sorry, makes sense ;)
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.
potentially, it may cause deadlock.
If goroutine 1 calls merge at histogram A for histogram B and goroutine 2 calls merge at histogram B for histogram A.
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
The Histogram.Merge() function is needed for VictoriaMetrics/VictoriaMetrics#6314 Updates #73
@AndrewChubatiuk , @f41gh7 , @tenmozes , please see the follow-up commit - 7a44715 |
Added function to merge histograms