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

feat(event cache): automatically shrink a room's linked chunk when all subscribers are gone #4703

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

bnjbvr
Copy link
Member

@bnjbvr bnjbvr commented Feb 20, 2025

On top of #4694.

Every subscriber to a RoomEventCache now gets a shared reference to a RAII AutoShrinkLinkedChunk guard; when the last one is dropped, it's spawning a task (from the Drop 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 per RoomEventCache, 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.

@bnjbvr bnjbvr requested a review from a team as a code owner February 20, 2025 16:13
@bnjbvr bnjbvr requested review from Hywan and removed request for a team February 20, 2025 16:13
Copy link

codecov bot commented Feb 20, 2025

Codecov Report

Attention: Patch coverage is 92.39130% with 7 lines in your changes missing coverage. Please review.

Project coverage is 85.91%. Comparing base (23f72ba) to head (0fb6f35).
Report is 4 commits behind head on main.

Files with missing lines Patch % Lines
crates/matrix-sdk/src/event_cache/room/mod.rs 86.00% 7 Missing ⚠️
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.
📢 Have feedback on the report? Share it here.

Comment on lines +78 to +82
// 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™.
Copy link
Member

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.

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