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

Experimental MSC3890 Implementation: Fix deleting account data when using an account data writer worker #14869

Merged
merged 3 commits into from
Mar 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/14869.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix a bug introduced in v1.75.0rc1 that caused experimental support for deleting account data to raise an internal server error while using an account data writer worker.
7 changes: 0 additions & 7 deletions synapse/handlers/account_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,6 @@ async def remove_account_data_for_room(
max_stream_id = await self._store.remove_account_data_for_room(
user_id, room_id, account_data_type
)
if max_stream_id is None:
# The referenced account data did not exist, so no delete occurred.
return None

self._notifier.on_new_event(
StreamKeyType.ACCOUNT_DATA, max_stream_id, users=[user_id]
Expand Down Expand Up @@ -230,9 +227,6 @@ async def remove_account_data_for_user(
max_stream_id = await self._store.remove_account_data_for_user(
user_id, account_data_type
)
if max_stream_id is None:
# The referenced account data did not exist, so no delete occurred.
return None

self._notifier.on_new_event(
StreamKeyType.ACCOUNT_DATA, max_stream_id, users=[user_id]
Expand All @@ -248,7 +242,6 @@ async def remove_account_data_for_user(
instance_name=random.choice(self._account_data_writers),
user_id=user_id,
account_data_type=account_data_type,
content={},
)
return response["max_stream_id"]

Expand Down
34 changes: 15 additions & 19 deletions synapse/storage/databases/main/account_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -585,7 +585,7 @@ async def add_account_data_to_room(

async def remove_account_data_for_room(
self, user_id: str, room_id: str, account_data_type: str
) -> Optional[int]:
) -> int:
"""Delete the room account data for the user of a given type.

Args:
Expand Down Expand Up @@ -637,15 +637,13 @@ def _remove_account_data_for_room_txn(
next_id,
)

if not row_updated:
return None

self._account_data_stream_cache.entity_has_changed(user_id, next_id)
self.get_room_account_data_for_user.invalidate((user_id,))
self.get_account_data_for_room.invalidate((user_id, room_id))
self.get_account_data_for_room_and_type.prefill(
(user_id, room_id, account_data_type), {}
)
if row_updated:
self._account_data_stream_cache.entity_has_changed(user_id, next_id)
self.get_room_account_data_for_user.invalidate((user_id,))
self.get_account_data_for_room.invalidate((user_id, room_id))
self.get_account_data_for_room_and_type.prefill(
(user_id, room_id, account_data_type), {}
)

return self._account_data_id_gen.get_current_token()

Expand Down Expand Up @@ -753,7 +751,7 @@ async def remove_account_data_for_user(
self,
user_id: str,
account_data_type: str,
) -> Optional[int]:
) -> int:
"""
Delete a single piece of user account data by type.

Expand Down Expand Up @@ -840,14 +838,12 @@ def _remove_account_data_for_user_txn(
next_id,
)

if not row_updated:
return None

self._account_data_stream_cache.entity_has_changed(user_id, next_id)
self.get_global_account_data_for_user.invalidate((user_id,))
self.get_global_account_data_by_type_for_user.prefill(
(user_id, account_data_type), {}
)
if row_updated:
self._account_data_stream_cache.entity_has_changed(user_id, next_id)
self.get_global_account_data_for_user.invalidate((user_id,))
self.get_global_account_data_by_type_for_user.prefill(
(user_id, account_data_type), {}
)

return self._account_data_id_gen.get_current_token()

Expand Down