Skip to content
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 memory-safe against concurrent closure/operations #53

Merged
merged 3 commits into from
Mar 10, 2019

Conversation

Stebalien
Copy link
Member

Ideally, this would be implemented down in badger itself but there appear to have been some performance concerns.

Why not just avoid ever trying to operate on a closed datastore? Well, we try our best but I'd still like to avoid segfaulting on error. Especially because these concurrent operations can be unimportant reads.

Thoughts? I haven't benchmarked this but I really doubt taking a rwmutex will cost us much (given how we generally use datastores, that is).

Make badger memory-safe against concurrent operations and close.
We don't have to clone the value.
Copy link
Member

@magik6k magik6k left a comment

Choose a reason for hiding this comment

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

Some operations can take single-digit microseconds in optimal conditions (https://ipfs.io/ipfs/Qmc168UrkY3ngPuKpSJtkhxS1r7hZJxcZzcw1Nfan1yZ5w/ds-badger/has-bsize/record-size-nsop.png), but even in this case this should be around 1% perf hit.

@Stebalien Stebalien merged commit e0b8b90 into master Mar 10, 2019
@Stebalien Stebalien deleted the fix/shutdown-panic branch March 10, 2019 00:32
@ghost ghost removed the status/in-progress In progress label Mar 10, 2019
@raulk
Copy link
Member

raulk commented Mar 10, 2019

Out of curiosity, any particular reason we didn’t go with an atomic integer to control the closed state?

@Stebalien
Copy link
Member Author

That's basically what a RWMutex is. An atomic "readers" counter and a lock. We need some way for Close to wait for all readers to finish so we need some type of lock/channel for that and RWMutex is pretty efficient (atomic increment/decrement unless there's a writer waiting).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants