-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
have_seen_event
cache is not invalidated when we persist an event
#13856
Comments
Seems plausible: they only seem to be called by |
Not familiar with the event persistence code, but it looks like |
I wonder if we should be prefilling the cache in this case instead of invalidating it? Isn't it likely that we're going to immediately use that event if we just persisted it? |
I had the same thought, but I wasn't sure how easy it is to do that with the cachedList magic. |
have_seen_event
cache is not invalidated when we persist an eventhave_seen_event
cache is not invalidated on monolith instances when we persist an event
…vent Fix for #13856 Fixed by calling `_invalidate_caches_for_event` when we persist an event. And an additional fix in `_invalidate_caches_for_event` to make sure it uses the correct cache key. This seems like it would be an easy foot-gun for any `tree=True` cache. Wrong: ```py self.have_seen_event.invalidate((room_id, event_id)) ``` Correct: ```py self.have_seen_event.invalidate(((room_id, event_id),)) ```
Fix #13856 `_invalidate_caches_for_event` doesn't run in monolith mode which means we never even tried to clear the `have_seen_event` and other caches. And even in worker mode, it only runs on the workers, not the master (AFAICT). Additionally there is bug with the key being wrong so `_invalidate_caches_for_event` never invalidates the `have_seen_event` cache even when it does run. Wrong: ```py self.have_seen_event.invalidate((room_id, event_id)) ``` Correct: ```py self.have_seen_event.invalidate(((room_id, event_id),)) ```
have_seen_event
cache is not invalidated on monolith instances when we persist an eventhave_seen_event
cache is not invalidated when we persist an event
Changing the title back to " |
Thanks for the input @DMRobertson and @clokep! Really helped ease the pain making the fix in #13863 |
Fix #13856 `_invalidate_caches_for_event` doesn't run in monolith mode which means we never even tried to clear the `have_seen_event` and other caches. And even in worker mode, it only runs on the workers, not the master (AFAICT). Additionally there is bug with the key being wrong so `_invalidate_caches_for_event` never invalidates the `have_seen_event` cache even when it does run. Wrong: ```py self.have_seen_event.invalidate((room_id, event_id)) ``` Correct: ```py self.have_seen_event.invalidate(((room_id, event_id),)) ```
Fix #13856 Fix #13865 > Discovered while trying to make Synapse fast enough for [this MSC2716 test for importing many batches](matrix-org/complement#214 (comment)). As an example, disabling the `have_seen_event` cache saves 10 seconds for each `/messages` request in that MSC2716 Complement test because we're not making as many federation requests for `/state` (speeding up `have_seen_event` itself is related to #13625) > > But this will also make `/messages` faster in general so we can include it in the [faster `/messages` milestone](https://github.com/matrix-org/synapse/milestone/11). > > *-- #13856 ### The problem `_invalidate_caches_for_event` doesn't run in monolith mode which means we never even tried to clear the `have_seen_event` and other caches. And even in worker mode, it only runs on the workers, not the master (AFAICT). Additionally there was bug with the key being wrong so `_invalidate_caches_for_event` never invalidates the `have_seen_event` cache even when it does run. Because we were using the `@cachedList` wrong, it was putting items in the cache under keys like `((room_id, event_id),)` with a `set` in a `set` (ex. `(('!TnCIJPKzdQdUlIyXdQ:test', '$Iu0eqEBN7qcyF1S9B3oNB3I91v2o5YOgRNPwi_78s-k'),)`) and we we're trying to invalidate with just `(room_id, event_id)` which did nothing.
The
have_seen_event
cache is not invalidated when we persist an event.This is evident when a
/messages
request triggers a/backfill
and it claims that we have the same missing state and auth events each time we_process_pulled_event
from the backfill response even though we just fetched and persisted those same state and auth events from the previous event we processed.I see that we have one spot in Synapse where we invalidate the
have_seen_event
cache (besides when we purge a room) but if I add a log line to_invalidate_caches_for_event
, it never runs in my Complement tests. Does this have a bug where theCacheInvalidationWorkerStore
stuff never runs in monolith mode?synapse/synapse/storage/databases/main/cache.py
Lines 211 to 226 in 2b522cc
Discovered while trying to make Synapse fast enough for this MSC2716 test for importing many batches. As an example, disabling the
have_seen_event
cache saves 10 seconds for each/messages
request in that MSC2716 Complement test because we're not making as many federation requests for/state
(speeding uphave_seen_event
itself is related to #13625)But this will also make
/messages
faster in general so we can include it in the faster/messages
milestone.Dev notes
have_seen_event
cache originally added in #9953The text was updated successfully, but these errors were encountered: