summary refs log tree commit diff
diff options
context:
space:
mode:
authorOlivier Wilkinson (reivilibre) <olivier@librepush.net>2021-09-07 09:08:53 +0100
committerOlivier Wilkinson (reivilibre) <olivier@librepush.net>2021-09-07 09:08:53 +0100
commit699f2197e31cd831b5910498513bd0464c02a245 (patch)
treedecf57a6b4fbf3d6b551caaea9220b1527bdb88a
parentPopulate the multi-key response cache with keys for our request (diff)
downloadsynapse-699f2197e31cd831b5910498513bd0464c02a245.tar.xz
Add a comment detailing the flow of this function
-rw-r--r--synapse/storage/databases/state/store.py26
1 files changed, 26 insertions, 0 deletions
diff --git a/synapse/storage/databases/state/store.py b/synapse/storage/databases/state/store.py
index 9650da9fb6..97594d9b7f 100644
--- a/synapse/storage/databases/state/store.py
+++ b/synapse/storage/databases/state/store.py
@@ -249,6 +249,32 @@ class StateGroupDataStore(StateBackgroundUpdateStore, SQLBaseStore):
                 from the database.
         Returns:
             Dict of state group to state map.
+
+
+        The flow for this function looks as follows:
+
+                * Query the immediate caches (self._state_group_cache,
+                |                             self._state_group_members_cache).
+        NONSTOP |
+                |
+                * Query the in-flight cache (self._state_group_inflight_cache)
+                | for immediate-cache misses.
+        NONSTOP |
+                |
+                * Service cache misses:
+                |   - Expand the state filter (to help cache hit ratio).
+                |   - Start a new transaction to fetch outstanding groups.
+                |   - Register entries in the in-flight cache for this transaction.
+                |   - (When the transaction is finished) Register entries in
+                |     the immediate caches.
+                |
+                * Wait for in-flight requests to finish...
+                |
+                * Assemble everything together and filter out anything we didn't
+                  ask for.
+
+        The sections marked NONSTOP must not contain any `await`s, otherwise
+        race conditions could occur and the cache could be made less effective.
         """
 
         def try_combine_inflight_requests(