feat(sdk): All caches have an auto-shrink mechanism#6690
Draft
Hywan wants to merge 7 commits into
Draft
Conversation
…rs` to `subscriber.rs`. This patch moves the `room/subscriber.rs` module to `subscriber.rs`. It's the first step to generalise it to more caches.
…ntCacheUpdate>`. This patch changes `RoomEventCacheSubscriber` to be `Subscriber<RoomEventCacheUpdate>`: it is now generic over the kind of update.
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #6690 +/- ##
==========================================
- Coverage 89.91% 89.91% -0.01%
==========================================
Files 396 396
Lines 110475 110688 +213
Branches 110475 110688 +213
==========================================
+ Hits 99338 99523 +185
- Misses 7371 7382 +11
- Partials 3766 3783 +17 ☔ View full report in Codecov by Harness. |
This patch adds a small, but exhaustive, unit test suite for the `Subscriber` type.
…ent_cache::caches::subscriber`. This patch reorganises the code a little bit. The `AutoShrinkChannelPayload` type from `event_cache` to `event_cache::caches::subscriber`.
This patch renames the `AutoShrinkChannelPayload` type to `AutoShrinkMessage`: - it's shorter, - the “Channel” part isn't really important here, - across the SDK, we usually refer to this kind of value as _message_ instead of _payload_.
This patch changes `AutoShrinkMessage` from being a type alias to
`OwnedRoomId` to an enum with a single variant for the moment: `Room {
room_id: OwnedRoomId }`. It's preparation work for supporting more cache
(such as thread).
9aabb02 to
dbbfd9a
Compare
…ith auto-shrink. This patch updates `ThreadEventCache::subscribe` to return a `Subscriber` instead of a `tokio::sync::mpsc::Receiver`. The API is strictly the same: only the type is different. Returning a `Subscriber` ensures the `ThreadEventCache` is automatically shrunk when all subscribers are gone away. This is matching the behaviour of `RoomEventCache::subscribe`. This is possible since `ThreadEventCache` now supports persistent storage: we can reload the cache to its last chunk. To achieve that, the `auto_shrink_sender` is now stored in `CachesInternals`. It is also part of the `ThreadEventCache` constructor. Also, the new `AutoShrinkMessage::Thread` variant has been added, and supported in `auto_shrink_linked_chunk_task`. Finally, a new `test_auto_shrink_after_all_subscribers_are_gone` has been added too.
2cfb994 to
ffb8479
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
During the big refactoring of the Event Cache, I noticed that the auto-shrink mechanism needs to be implement on all caches now. It was implemented on
RoomEventCachebefore, but we want to extend it toThreadEventCachenow its supports persistent storage (see #6317), and maybe onPinnedEventsCachetoo since it has its own storage too (note that this is less critical as it seems unlikely we will have that many pinned-events living in memory).Tasks
event_cache/caches/room/subscriber.rstoevent_cache/caches/subscriber.rsRoomEventCacheSubscribertoSubscriber<RoomEventCacheUpdate>, i.e. make it generic over any updates,Subscribertype only,AutoSkrinkPayloadto be an enum instead ofOwnedRoomId, something like:auto_shrink_linked_chunk_task,ThreadEventCache::subscribeto return aSubscriber<TimelineVectorDiffsinstead of aReceiver<TimelinevectorDiffs>,PinnedEventsCache::subscribeto return aSubscriber<TimelineVectorDiffsinstead of aReceiver<TimelinevectorDiffs>.Signed-off-by: