-
Notifications
You must be signed in to change notification settings - Fork 307
Add a value-based lock in the CryptoStore
s
#2049
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
Add a value-based lock in the CryptoStore
s
#2049
Conversation
Haha, the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks mostly good, left a couple of nits and some questions.
Codecov ReportPatch coverage:
Additional details and impacted files@@ Coverage Diff @@
## main #2049 +/- ##
==========================================
- Coverage 76.01% 75.84% -0.18%
==========================================
Files 151 152 +1
Lines 16581 16654 +73
==========================================
+ Hits 12604 12631 +27
- Misses 3977 4023 +46
☔ View full report in Codecov by Sentry. |
Signed-off-by: Benjamin Bouvier <[email protected]>
Signed-off-by: Benjamin Bouvier <[email protected]>
Signed-off-by: Benjamin Bouvier <[email protected]>
Signed-off-by: Benjamin Bouvier <[email protected]>
Signed-off-by: Benjamin Bouvier <[email protected]>
… lock Signed-off-by: Benjamin Bouvier <[email protected]>
Signed-off-by: Benjamin Bouvier <[email protected]>
Signed-off-by: Benjamin Bouvier <[email protected]>
Signed-off-by: Benjamin Bouvier <[email protected]>
Signed-off-by: Benjamin Bouvier <[email protected]>
Signed-off-by: Benjamin Bouvier <[email protected]>
9674be7
to
1a6e382
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is mostly fine, if you think the enum idea is not worth it then feel free to proceed.
Signed-off-by: Benjamin Bouvier <[email protected]>
Signed-off-by: Benjamin Bouvier <[email protected]>
This implements a value-based lock in the crypto stores. The intent is to use that for multiple processes to be able to make writes into the store concurrently, while still cooperating on who does them. In particular, we need this for #1928, since we may have up to two different processes trying to write into the crypto store at the same time.
New methods in the
CryptoStore
traitThe idea is to introduce two new methods touching custom values in the crypto store:
upsert
used in theset_custom_value
)Those two operations match the semantics we want:
By looking at the number of lines affected by the query, we can infer whether the insert/remove happened or not, that is, if we managed to take the lock or not.
High-level APIs
I've also added an high-level API,
CryptoStoreLock
, that helps managing such a lock, and adds some niceties on top of that:I've also attempted to make a
CryptoStoreLockGuard
, that would be RAII struct taking the lock upon creation and releasing it upon drop, but:async Drop
s are not a thing yet, in native RustAs a matter of fact, I think we should probably not have the
CryptoStoreLockGuard
at all, since it's causing more problems than it fixes. I don't know how big an ergonomic issue it will be, though.Test program
There's also a test program in which I shamelessly show my rudimentary unix skills; I've put it in the
labs/
directory but this could as well be a large integration test. A parent program initially fills a custom crypto store, then creates apipe()
for 1-way communication with a child created withfork()
; then the parent sends commands to the child. These commands consist in reading and writing into the crypto store, using a lock. And while the child attempts to perform these operations, the parent tries hard to get the lock at the same time. This helps figuring out a few issues and making sure that cross-process locking would work as intended.