Conversation
| // Remap DB to the same backing file | ||
| func (db *DB) Remap() error { | ||
| db.RLock() | ||
| db.mutex.RLock() |
There was a problem hiding this comment.
Is there any reason the RUnlock calls in this function aren't done as part of a defer? Would it be a problem to keep the lock until the end of this function?
There was a problem hiding this comment.
I was following that pattern when writing RangeMatch but I had wanted to circle back and ask about it because I get the sense that using defer in Remap, Search, ForwardMatch, and RangeMatch would help guarantee that locks don't ever leak.
There was a problem hiding this comment.
Remap calls Open after this which will take out it's own Lock, so we have to release the RLock first
There was a problem hiding this comment.
Also personal coding style, I tend to avoid defer for hot functions when the function is also short and you don't loose much readability. While defer is cheap, it's not free. That's why Search, ForwardMatch and RangeMatch don't use it.
There was a problem hiding this comment.
Thanks, @jehiah. I pretty much copied your style for RangeMatch with the intent of circling back to ask you about it at some point. 😄
As someone fairly new to Go, I definitely appreciate the clarification.
|
What do your additional changes do? FWIW we've been using my code in #9 in production for a few months without any issue... |
|
@evanbattaglia functionally equivalent, just slightly different implementation to not change the function signature of |
This fixes #9