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 store operations atomic #480

Merged
merged 8 commits into from
Nov 10, 2022
Merged

Make store operations atomic #480

merged 8 commits into from
Nov 10, 2022

Conversation

rklaehn
Copy link
Contributor

@rklaehn rklaehn commented Nov 9, 2022

This makes store operations atomic by just using an in memory mutex.

This means that as soon as a db is being opened twice at the same time, it will be corrupted. But that is the case anyway because we are already relying on in process atomicity with the (former) AtomicU64 for the id counter.

I am working on a solution that is using rocksdb transactions on a separate branch, but it seems that this will take a bit longer because I can't get the atomicity test to pass despite using transactions with snapshots.

So this is a stopgap measure that makes our store not break until we sort things out more permanently.

It also implements n0-computer/beetle#112

Note: I tried using tokio async mutexes, but that gets you into trouble again because LocalStore is not Send.

@rklaehn rklaehn marked this pull request as ready for review November 9, 2022 15:20
@rklaehn rklaehn requested a review from flub November 9, 2022 15:34
@rklaehn
Copy link
Contributor Author

rklaehn commented Nov 9, 2022

@b5 as promised, this is the interim solution since fixing this with rocksdb transactions is not as straightforward as hoped for

iroh-store/src/store.rs Outdated Show resolved Hide resolved
iroh-store/src/store.rs Show resolved Hide resolved
iroh-store/src/store.rs Outdated Show resolved Hide resolved
iroh-store/src/store.rs Outdated Show resolved Hide resolved
flub
flub previously approved these changes Nov 10, 2022
iroh-store/src/store.rs Show resolved Hide resolved
flub
flub previously approved these changes Nov 10, 2022
@rklaehn
Copy link
Contributor Author

rklaehn commented Nov 10, 2022

@flub Was trying out tokio mutex, but when reading up on it I found this in the docs:

https://docs.rs/tokio/latest/tokio/sync/struct.Mutex.html#which-kind-of-mutex-should-you-use

So they explicitly mention that using a parking_lot mutex is fine in many cases.

@flub
Copy link
Contributor

flub commented Nov 10, 2022

https://docs.rs/tokio/latest/tokio/sync/struct.Mutex.html#which-kind-of-mutex-should-you-use

So they explicitly mention that using a parking_lot mutex is fine in many cases.

Yes, I think in the design of this PR using a parking_lot mutex is probably better since it is supposed to have less overhead and they are blocking inside a spawn_blocking call anyway.

This isn't quite what they discuss in that document though, that is about when they think it is reasonable to take a (sync) mutex while executing in one of the main async runtime threads I think. Which is a bit of a different trade-off.

Maybe that will fix the mysterious linker error. Shame, since it is much
faster than std::sync locks.
@rklaehn rklaehn merged commit ac8ec35 into main Nov 10, 2022
@rklaehn rklaehn deleted the rklaehn/store-atomic branch November 10, 2022 18:19
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