Skip to content
This repository was archived by the owner on Apr 26, 2024. It is now read-only.

Commit 49ef8ec

Browse files
authored
Fix a cache-invalidation bug for worker-based deployments (#5920)
Some of the caches on worker processes were not being correctly invalidated when a room's state was changed in a way that did not affect the membership list of the room. We need to make sure we send out cache invalidations even when no memberships are changing.
1 parent a3f0635 commit 49ef8ec

File tree

2 files changed

+17
-8
lines changed

2 files changed

+17
-8
lines changed

changelog.d/5920.bugfix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix a cache-invalidation bug for worker-based deployments.

synapse/storage/_base.py

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1395,14 +1395,22 @@ def _invalidate_state_caches_and_stream(self, txn, room_id, members_changed):
13951395
"""
13961396
txn.call_after(self._invalidate_state_caches, room_id, members_changed)
13971397

1398-
# We need to be careful that the size of the `members_changed` list
1399-
# isn't so large that it causes problems sending over replication, so we
1400-
# send them in chunks.
1401-
# Max line length is 16K, and max user ID length is 255, so 50 should
1402-
# be safe.
1403-
for chunk in batch_iter(members_changed, 50):
1404-
keys = itertools.chain([room_id], chunk)
1405-
self._send_invalidation_to_replication(txn, _CURRENT_STATE_CACHE_NAME, keys)
1398+
if members_changed:
1399+
# We need to be careful that the size of the `members_changed` list
1400+
# isn't so large that it causes problems sending over replication, so we
1401+
# send them in chunks.
1402+
# Max line length is 16K, and max user ID length is 255, so 50 should
1403+
# be safe.
1404+
for chunk in batch_iter(members_changed, 50):
1405+
keys = itertools.chain([room_id], chunk)
1406+
self._send_invalidation_to_replication(
1407+
txn, _CURRENT_STATE_CACHE_NAME, keys
1408+
)
1409+
else:
1410+
# if no members changed, we still need to invalidate the other caches.
1411+
self._send_invalidation_to_replication(
1412+
txn, _CURRENT_STATE_CACHE_NAME, [room_id]
1413+
)
14061414

14071415
def _invalidate_state_caches(self, room_id, members_changed):
14081416
"""Invalidates caches that are based on the current state, but does

0 commit comments

Comments
 (0)