summary refs log tree commit diff
diff options
context:
space:
mode:
authorRichard van der Hoff <richard@matrix.org>2018-02-09 12:13:34 +0000
committerRichard van der Hoff <richard@matrix.org>2018-02-09 13:07:41 +0000
commit39a6b3549638c70e3aaf51b361576fbd729eb655 (patch)
treea65b0630417fa93202be575bbf98b06260ef451f
parentdelete_local_events for purge_history (diff)
downloadsynapse-39a6b3549638c70e3aaf51b361576fbd729eb655.tar.xz
purge: move room_depth update to end
... to avoid locking the table for too long
Diffstat (limited to '')
-rw-r--r--synapse/storage/events.py18
1 files changed, 12 insertions, 6 deletions
diff --git a/synapse/storage/events.py b/synapse/storage/events.py
index 11a2ff2d8a..238a2006b8 100644
--- a/synapse/storage/events.py
+++ b/synapse/storage/events.py
@@ -2255,12 +2255,6 @@ class EventsStore(SQLBaseStore):
                 event_id,
             ))
 
-        logger.info("[purge] updating room_depth")
-        txn.execute(
-            "UPDATE room_depth SET min_depth = ? WHERE room_id = ?",
-            (topological_ordering, room_id,)
-        )
-
         # Delete all remote non-state events
         for table in (
             "events",
@@ -2298,6 +2292,18 @@ class EventsStore(SQLBaseStore):
             ]
         )
 
+        # synapse tries to take out an exclusive lock on room_depth whenever it
+        # persists events (because upsert), and once we run this update, we
+        # will block that for the rest of our transaction.
+        #
+        # So, let's stick it at the end so that we don't block event
+        # persistence.
+        logger.info("[purge] updating room_depth")
+        txn.execute(
+            "UPDATE room_depth SET min_depth = ? WHERE room_id = ?",
+            (topological_ordering, room_id,)
+        )
+
         logger.info("[purge] done")
 
     @defer.inlineCallbacks