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

Commit

Permalink
Fix room deletion (#12889)
Browse files Browse the repository at this point in the history
* Fix room deletion

ae7858f broke room deletion by attempting to delete the entry from `rooms`
before the tables that reference it.

* faster_joins: remove database rows on purge
  • Loading branch information
richvdh authored May 27, 2022
1 parent bc1beeb commit f1605b7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
1 change: 1 addition & 0 deletions changelog.d/12889.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix a bug introduced in Synapse 1.59.0 which caused room deletion to fail with a foreign key violation.
19 changes: 10 additions & 9 deletions synapse/storage/databases/main/purge_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,12 +322,7 @@ async def purge_room(self, room_id: str) -> List[int]:
)

def _purge_room_txn(self, txn: LoggingTransaction, room_id: str) -> List[int]:
# We *immediately* delete the room from the rooms table. This ensures
# that we don't race when persisting events (as that transaction checks
# that the room exists).
txn.execute("DELETE FROM rooms WHERE room_id = ?", (room_id,))

# Next, we fetch all the state groups that should be deleted, before
# First, fetch all the state groups that should be deleted, before
# we delete that information.
txn.execute(
"""
Expand Down Expand Up @@ -387,16 +382,21 @@ def _purge_room_txn(self, txn: LoggingTransaction, room_id: str) -> List[int]:
(room_id,),
)

# and finally, the tables with an index on room_id (or no useful index)
# next, the tables with an index on room_id (or no useful index)
for table in (
"current_state_events",
"destination_rooms",
"event_backward_extremities",
"event_forward_extremities",
"event_push_actions",
"event_search",
"partial_state_events",
"events",
"federation_inbound_events_staging",
"group_rooms",
"local_current_membership",
"partial_state_rooms_servers",
"partial_state_rooms",
"receipts_graph",
"receipts_linearized",
"room_aliases",
Expand All @@ -416,8 +416,9 @@ def _purge_room_txn(self, txn: LoggingTransaction, room_id: str) -> List[int]:
"group_summary_rooms",
"room_account_data",
"room_tags",
"local_current_membership",
"federation_inbound_events_staging",
# "rooms" happens last, to keep the foreign keys in the other tables
# happy
"rooms",
):
logger.info("[purge] removing %s from %s", room_id, table)
txn.execute("DELETE FROM %s WHERE room_id=?" % (table,), (room_id,))
Expand Down

0 comments on commit f1605b7

Please sign in to comment.