Skip to content

mlock support#10

Merged
jehiah merged 2 commits into
masterfrom
mlock_10
Aug 5, 2016
Merged

mlock support#10
jehiah merged 2 commits into
masterfrom
mlock_10

Conversation

@jehiah

@jehiah jehiah commented Aug 5, 2016

Copy link
Copy Markdown
Owner

This fixes #9

Comment thread sorted_db/db.go
// Remap DB to the same backing file
func (db *DB) Remap() error {
db.RLock()
db.mutex.RLock()

@noam-c noam-c Aug 5, 2016

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remap calls Open after this which will take out it's own Lock, so we have to release the RLock first

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@jehiah
jehiah merged commit a51d668 into master Aug 5, 2016
@jehiah
jehiah deleted the mlock_10 branch August 5, 2016 13:20
@evanbattaglia

Copy link
Copy Markdown

What do your additional changes do? FWIW we've been using my code in #9 in production for a few months without any issue...

@jehiah

jehiah commented Aug 5, 2016

Copy link
Copy Markdown
Owner Author

@evanbattaglia functionally equivalent, just slightly different implementation to not change the function signature of New(), and to expose it separately from the library into main().

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants