summary refs log tree commit diff
diff options
context:
space:
mode:
authorOlivier Wilkinson (reivilibre) <oliverw@matrix.org>2022-07-05 12:23:29 +0100
committerOlivier Wilkinson (reivilibre) <oliverw@matrix.org>2022-07-07 16:05:22 +0100
commit2b0ebf1b4d39f5561a186a30d5b488a7fae58bde (patch)
tree1942a9bfaf4de3c1b933e0f4c0b9b7445f4094be
parentDBG retry until fail (diff)
downloadsynapse-2b0ebf1b4d39f5561a186a30d5b488a7fae58bde.tar.xz
DBG cache
-rw-r--r--synapse/storage/databases/main/roommember.py2
-rw-r--r--synapse/util/caches/deferred_cache.py7
-rw-r--r--synapse/util/caches/descriptors.py5
3 files changed, 13 insertions, 1 deletions
diff --git a/synapse/storage/databases/main/roommember.py b/synapse/storage/databases/main/roommember.py
index 31bc8c5601..0e1255b300 100644
--- a/synapse/storage/databases/main/roommember.py
+++ b/synapse/storage/databases/main/roommember.py
@@ -476,7 +476,7 @@ class RoomMemberWorkerStore(EventsWorkerStore):
 
         return results_dict.get("membership"), results_dict.get("event_id")
 
-    @cached(max_entries=500000, iterable=True, prune_unread_entries=False)
+    @cached(max_entries=500000, iterable=True, prune_unread_entries=False, debug_invalidations=True)
     async def get_rooms_for_user_with_stream_ordering(
         self, user_id: str
     ) -> FrozenSet[GetRoomsForUserWithStreamOrdering]:
diff --git a/synapse/util/caches/deferred_cache.py b/synapse/util/caches/deferred_cache.py
index 1d6ec22191..c020223586 100644
--- a/synapse/util/caches/deferred_cache.py
+++ b/synapse/util/caches/deferred_cache.py
@@ -15,6 +15,7 @@
 # limitations under the License.
 
 import enum
+import logging
 import threading
 from typing import (
     Callable,
@@ -66,6 +67,7 @@ class DeferredCache(Generic[KT, VT]):
         "cache",
         "thread",
         "_pending_deferred_cache",
+        "debug_invalidations"
     )
 
     def __init__(
@@ -76,6 +78,7 @@ class DeferredCache(Generic[KT, VT]):
         iterable: bool = False,
         apply_cache_factor_from_config: bool = True,
         prune_unread_entries: bool = True,
+        debug_invalidations: bool = False,
     ):
         """
         Args:
@@ -119,6 +122,7 @@ class DeferredCache(Generic[KT, VT]):
         )
 
         self.thread: Optional[threading.Thread] = None
+        self.debug_invalidations = debug_invalidations
 
     @property
     def max_entries(self) -> int:
@@ -310,6 +314,9 @@ class DeferredCache(Generic[KT, VT]):
         self.check_thread()
         self.cache.del_multi(key)
 
+        if self.debug_invalidations:
+            logging.debug("Invalidating key %r in cache %s", key)
+
         # if we have a pending lookup for this key, remove it from the
         # _pending_deferred_cache, which will (a) stop it being returned
         # for future queries and (b) stop it being persisted as a proper entry
diff --git a/synapse/util/caches/descriptors.py b/synapse/util/caches/descriptors.py
index 867f315b2a..47c0b69cf4 100644
--- a/synapse/util/caches/descriptors.py
+++ b/synapse/util/caches/descriptors.py
@@ -301,6 +301,7 @@ class DeferredCacheDescriptor(_CacheDescriptorBase):
         cache_context: bool = False,
         iterable: bool = False,
         prune_unread_entries: bool = True,
+        debug_invalidations: bool = False
     ):
         super().__init__(
             orig,
@@ -318,6 +319,7 @@ class DeferredCacheDescriptor(_CacheDescriptorBase):
         self.tree = tree
         self.iterable = iterable
         self.prune_unread_entries = prune_unread_entries
+        self.debug_invalidations = debug_invalidations
 
     def __get__(self, obj: Optional[Any], owner: Optional[Type]) -> Callable[..., Any]:
         cache: DeferredCache[CacheKey, Any] = DeferredCache(
@@ -326,6 +328,7 @@ class DeferredCacheDescriptor(_CacheDescriptorBase):
             tree=self.tree,
             iterable=self.iterable,
             prune_unread_entries=self.prune_unread_entries,
+            debug_invalidations=self.debug_invalidations,
         )
 
         get_cache_key = self.cache_key_builder
@@ -577,6 +580,7 @@ def cached(
     cache_context: bool = False,
     iterable: bool = False,
     prune_unread_entries: bool = True,
+    debug_invalidations: bool = False,
 ) -> Callable[[F], _CachedFunction[F]]:
     func = lambda orig: DeferredCacheDescriptor(
         orig,
@@ -587,6 +591,7 @@ def cached(
         cache_context=cache_context,
         iterable=iterable,
         prune_unread_entries=prune_unread_entries,
+        debug_invalidations=debug_invalidations
     )
 
     return cast(Callable[[F], _CachedFunction[F]], func)