-
Notifications
You must be signed in to change notification settings - Fork 269
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(event cache): automatically shrink a room's linked chunk when all subscribers are gone #4703
base: main
Are you sure you want to change the base?
Conversation
…orage updates And rename it accordingly to `RoomEvents::store_updates`. Note: no changelog, because this is an internal API only.
…isteners are left
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #4703 +/- ##
==========================================
+ Coverage 85.89% 85.91% +0.02%
==========================================
Files 292 292
Lines 33907 33968 +61
==========================================
+ Hits 29124 29185 +61
Misses 4783 4783 ☔ View full report in Codecov by Sentry. |
// I hear you from the future: "but, spawning a detached task in a drop | ||
// implementation is real bad! Maybe there will be multiple shrinks | ||
// happening at the same time, and that's bad!". However, this can't | ||
// happen, because the whole `state` variable is guarded by a fair lock, | ||
// which will run queries in the order they happen. Should be fine™. |
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.
You forgot to explain why you need to spawn
here. It's because drop
cannot be async, and you're doing async operations.
On top of #4694.
Every subscriber to a
RoomEventCache
now gets a shared reference to a RAIIAutoShrinkLinkedChunk
guard; when the last one is dropped, it's spawning a task (from theDrop
impl — sigh to no async drop) that will shrink the linked chunk to the last chunk.This is a poor man's implementation that doesn't cause too much operational overhead, in particular, because it doesn't require a new task listening to commands to shrink the linked chunk. (This new task should then live in the main
EventCache
instance, so as not to have one such task perRoomEventCache
, aka per room.)In the worst case, we can tweak the implementation and (mostly) keep the test, because it's testing the behavior we'd want here.
Part of #3280.