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

Commit f1605b7

Browse files
authored
Fix room deletion (#12889)
* 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
1 parent bc1beeb commit f1605b7

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

changelog.d/12889.bugfix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix a bug introduced in Synapse 1.59.0 which caused room deletion to fail with a foreign key violation.

synapse/storage/databases/main/purge_events.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -322,12 +322,7 @@ async def purge_room(self, room_id: str) -> List[int]:
322322
)
323323

324324
def _purge_room_txn(self, txn: LoggingTransaction, room_id: str) -> List[int]:
325-
# We *immediately* delete the room from the rooms table. This ensures
326-
# that we don't race when persisting events (as that transaction checks
327-
# that the room exists).
328-
txn.execute("DELETE FROM rooms WHERE room_id = ?", (room_id,))
329-
330-
# Next, we fetch all the state groups that should be deleted, before
325+
# First, fetch all the state groups that should be deleted, before
331326
# we delete that information.
332327
txn.execute(
333328
"""
@@ -387,16 +382,21 @@ def _purge_room_txn(self, txn: LoggingTransaction, room_id: str) -> List[int]:
387382
(room_id,),
388383
)
389384

390-
# and finally, the tables with an index on room_id (or no useful index)
385+
# next, the tables with an index on room_id (or no useful index)
391386
for table in (
392387
"current_state_events",
393388
"destination_rooms",
394389
"event_backward_extremities",
395390
"event_forward_extremities",
396391
"event_push_actions",
397392
"event_search",
393+
"partial_state_events",
398394
"events",
395+
"federation_inbound_events_staging",
399396
"group_rooms",
397+
"local_current_membership",
398+
"partial_state_rooms_servers",
399+
"partial_state_rooms",
400400
"receipts_graph",
401401
"receipts_linearized",
402402
"room_aliases",
@@ -416,8 +416,9 @@ def _purge_room_txn(self, txn: LoggingTransaction, room_id: str) -> List[int]:
416416
"group_summary_rooms",
417417
"room_account_data",
418418
"room_tags",
419-
"local_current_membership",
420-
"federation_inbound_events_staging",
419+
# "rooms" happens last, to keep the foreign keys in the other tables
420+
# happy
421+
"rooms",
421422
):
422423
logger.info("[purge] removing %s from %s", room_id, table)
423424
txn.execute("DELETE FROM %s WHERE room_id=?" % (table,), (room_id,))

0 commit comments

Comments
 (0)