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.
joriks/clearer_logging_file_origin
Richard van der Hoff 2019-08-28 10:18:16 +01:00 committed by GitHub
parent a3f0635686
commit 49ef8ec399
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 8 deletions

1
changelog.d/5920.bugfix Normal file
View File

@ -0,0 +1 @@
Fix a cache-invalidation bug for worker-based deployments.

View File

@ -1395,14 +1395,22 @@ class SQLBaseStore(object):
""" """
txn.call_after(self._invalidate_state_caches, room_id, members_changed) txn.call_after(self._invalidate_state_caches, room_id, members_changed)
# We need to be careful that the size of the `members_changed` list if members_changed:
# isn't so large that it causes problems sending over replication, so we # We need to be careful that the size of the `members_changed` list
# send them in chunks. # isn't so large that it causes problems sending over replication, so we
# Max line length is 16K, and max user ID length is 255, so 50 should # send them in chunks.
# be safe. # Max line length is 16K, and max user ID length is 255, so 50 should
for chunk in batch_iter(members_changed, 50): # be safe.
keys = itertools.chain([room_id], chunk) for chunk in batch_iter(members_changed, 50):
self._send_invalidation_to_replication(txn, _CURRENT_STATE_CACHE_NAME, keys) keys = itertools.chain([room_id], chunk)
self._send_invalidation_to_replication(
txn, _CURRENT_STATE_CACHE_NAME, keys
)
else:
# if no members changed, we still need to invalidate the other caches.
self._send_invalidation_to_replication(
txn, _CURRENT_STATE_CACHE_NAME, [room_id]
)
def _invalidate_state_caches(self, room_id, members_changed): def _invalidate_state_caches(self, room_id, members_changed):
"""Invalidates caches that are based on the current state, but does """Invalidates caches that are based on the current state, but does