-
Notifications
You must be signed in to change notification settings - Fork 268
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
feat: Implement cross-process lock for the EventCache
#4192
feat: Implement cross-process lock for the EventCache
#4192
Conversation
c5dbe73
to
4e2bea3
Compare
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #4192 +/- ##
==========================================
- Coverage 84.89% 84.89% -0.01%
==========================================
Files 272 272
Lines 29142 29208 +66
==========================================
+ Hits 24739 24795 +56
- Misses 4403 4413 +10 ☔ View full report in Codecov by Sentry. |
This patch replaces a `&*` by a `.as_ref()` and a `.deref()`. The result is the same but it's just simpler for newcomers to understand what happens.
The idea is to avoid name conflicts when implementing other traits that use the `Error` associated type.
666eba4
to
8aee160
Compare
3d624d0
to
f2ef774
Compare
0c52043
to
4808481
Compare
4808481
to
c8f2321
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.
Great! It's nice that we can reuse so much code for the cross-process locking 🥳
"default-key".to_owned(), | ||
"matrix-sdk-base".to_owned(), |
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.
The values provided here are scary, and should be controllable by the callers, otherwise it's not possible to distinguish a process from another. The key could be a constant used everywhere in the codebase (maybe buried into a single place, and then passed around — or buried a single time when creating an EventCacheStoreLock
from an event cache store impl), but the holder's value has to be provided by the embedder.
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 would like to address that as a follow-up PR: I want to introduce a "process holder name" inside the client that can be used by all cross-process lock, otherwise things start to be really clumsy. What do you think?
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.
@bnjbvr and I have agreed to remove these values with a configuration in the Client
. I'm already working on this as a follow-up PR.
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.
Here it is, #4224
This code is shared by all `MemoryStore` implementations.
47b4510
to
42d0dc4
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.
lgtm, thanks!
This PR must be reviewed commit-by-commit.
It introduces the
LockableEventCacheStore
type, which wrapsDynEventCacheStore
, and that implementsBackingStore
so that it can be used inside theCrossProcessStoreLock
.It then introduces the
EventCacheStoreLock
type, which glue all pieces together: theCrossProcessStoreLock
and theLockableEventCacheStore
. It exposes a single method:lock(&'a self) -> Result<EventCacheStoreLockGuard<'a>, _>
, which allows to take the lock. The guard derefs toDynEventCacheStore
. The resulting API is straightforward to use according to me:client.event_cache_store().lock().await?
, pretty Rust idiomatic.Finally, the PR replaces all uses of
DynEventCacheStore
byEventCacheStoreLock
. There is no more publicDynEventCacheStore
, expect viaEventCacheStoreLock
.A follow-up patch must update
matrix_sdk::event_cache
to refresh the in-memory data of the event cache when the lock holder has changed. I believe it's nice to introduce that in another PR instead of increasing the number of patches in this one.EventCache
storage #3280