summary refs log tree commit diff
path: root/synapse/storage/engines/postgres.py
diff options
context:
space:
mode:
authorErik Johnston <erik@matrix.org>2015-04-27 13:22:30 +0100
committerErik Johnston <erik@matrix.org>2015-04-27 13:22:30 +0100
commit2732be83d9e883184f4a783fb7ba15487f30c20d (patch)
tree55ca53c5d3f1c0641d65cbe040ebe32d5ee4992c /synapse/storage/engines/postgres.py
parentHandle the fact that postgres databases can be restarted from under us (diff)
downloadsynapse-2732be83d9e883184f4a783fb7ba15487f30c20d.tar.xz
Shuffle operations so that locking upsert happens last in the txn. This ensures the lock is held for the least amount of time possible.
Diffstat (limited to 'synapse/storage/engines/postgres.py')
-rw-r--r--synapse/storage/engines/postgres.py3
1 files changed, 3 insertions, 0 deletions
diff --git a/synapse/storage/engines/postgres.py b/synapse/storage/engines/postgres.py
index 00dbae7b60..b8cca9b187 100644
--- a/synapse/storage/engines/postgres.py
+++ b/synapse/storage/engines/postgres.py
@@ -42,3 +42,6 @@ class PostgresEngine(object):
 
     def is_connection_closed(self, conn):
         return bool(conn)
+
+    def lock_table(self, txn, table):
+        txn.execute("LOCK TABLE %s in EXCLUSIVE MODE" % (table,))