summary refs log tree commit diff
path: root/synapse
diff options
context:
space:
mode:
authorRichard van der Hoff <1389908+richvdh@users.noreply.github.com>2022-05-27 11:31:08 +0200
committerGitHub <noreply@github.com>2022-05-27 10:31:08 +0100
commitf1605b7447196d2b13cfbaf70483aa9f2f1a34b4 (patch)
tree7635cd2004b0e52f00a0ee9d7148dac8da439775 /synapse
parentRefactor have_seen_events to reduce OOMs (#12886) (diff)
downloadsynapse-f1605b7447196d2b13cfbaf70483aa9f2f1a34b4.tar.xz
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
Diffstat (limited to 'synapse')
-rw-r--r--synapse/storage/databases/main/purge_events.py19
1 files changed, 10 insertions, 9 deletions
diff --git a/synapse/storage/databases/main/purge_events.py b/synapse/storage/databases/main/purge_events.py
index c94d5f9f81..2353c120e9 100644
--- a/synapse/storage/databases/main/purge_events.py
+++ b/synapse/storage/databases/main/purge_events.py
@@ -322,12 +322,7 @@ class PurgeEventsStore(StateGroupWorkerStore, CacheInvalidationWorkerStore):
         )
 
     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(
             """
@@ -387,7 +382,7 @@ class PurgeEventsStore(StateGroupWorkerStore, CacheInvalidationWorkerStore):
                 (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",
@@ -395,8 +390,13 @@ class PurgeEventsStore(StateGroupWorkerStore, CacheInvalidationWorkerStore):
             "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",
@@ -416,8 +416,9 @@ class PurgeEventsStore(StateGroupWorkerStore, CacheInvalidationWorkerStore):
             "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,))