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

Fix crashes on multi thread calls to read/write/destroy #168

Merged
merged 6 commits into from
May 11, 2020

Conversation

pilgr
Copy link
Owner

@pilgr pilgr commented Feb 29, 2020

Multi thread access to assertInit was causing race conditions on creating Paper dir which caused exception like RuntimeException("Couldn't create Paper dir:..). That was easy fixed with adding synchronized to the function.

The other problem raised after that: what happened if destroy is called while read/write still in progress? That caused many issues on reading/writing to file. Since destroy makes changes for all keys, and read/write synchronized by particular key, I've introduced a new global Semaphore to lock all per-key operations while global operation is in progress. Also global operations (like destroy and getAllKeys) won't be started before currently running per-key operations (read, write etc) are completed.

Fix #66
Fix #108
Fix #114
Fix #159
Fix #160

Copy link

@wassil wassil left a comment

Choose a reason for hiding this comment

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

LGTM, thank you for doing this!

paperdb/src/main/java/io/paperdb/DbStoragePlainFile.java Outdated Show resolved Hide resolved
paperdb/src/main/java/io/paperdb/KeyLocker.java Outdated Show resolved Hide resolved
@pilgr pilgr force-pushed the fix-multi-thread-paper-db-creation branch from 2dbaf67 to df7b7c7 Compare May 11, 2020 19:47
@pilgr pilgr merged commit 9f40a51 into development May 11, 2020
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.

2 participants