summary refs log tree commit diff
path: root/synapse/storage
diff options
context:
space:
mode:
authorErik Johnston <erikj@jki.re>2016-09-14 16:50:37 +0100
committerGitHub <noreply@github.com>2016-09-14 16:50:37 +0100
commit264a48aedf1d73e1abde834aa270c0240e7da623 (patch)
tree97e62eeca42faaaaa79ad58f43849cab42896d03 /synapse/storage
parentMerge pull request #1118 from matrix-org/erikj/public_rooms_splitout (diff)
parentAmalgamate two identical consecutive if statements (diff)
downloadsynapse-264a48aedf1d73e1abde834aa270c0240e7da623.tar.xz
Merge pull request #1117 from matrix-org/erikj/fix_state
Ensure we don't mutate state cache entries
Diffstat (limited to 'synapse/storage')
-rw-r--r--synapse/storage/state.py28
1 files changed, 17 insertions, 11 deletions
diff --git a/synapse/storage/state.py b/synapse/storage/state.py
index fdbdade536..7eb342674c 100644
--- a/synapse/storage/state.py
+++ b/synapse/storage/state.py
@@ -817,16 +817,24 @@ class StateStore(SQLBaseStore):
 
     @defer.inlineCallbacks
     def _background_index_state(self, progress, batch_size):
-        def reindex_txn(txn):
+        def reindex_txn(conn):
+            conn.rollback()
             if isinstance(self.database_engine, PostgresEngine):
-                txn.execute(
-                    "CREATE INDEX CONCURRENTLY state_groups_state_type_idx"
-                    " ON state_groups_state(state_group, type, state_key)"
-                )
-                txn.execute(
-                    "DROP INDEX IF EXISTS state_groups_state_id"
-                )
+                # postgres insists on autocommit for the index
+                conn.set_session(autocommit=True)
+                try:
+                    txn = conn.cursor()
+                    txn.execute(
+                        "CREATE INDEX CONCURRENTLY state_groups_state_type_idx"
+                        " ON state_groups_state(state_group, type, state_key)"
+                    )
+                    txn.execute(
+                        "DROP INDEX IF EXISTS state_groups_state_id"
+                    )
+                finally:
+                    conn.set_session(autocommit=False)
             else:
+                txn = conn.cursor()
                 txn.execute(
                     "CREATE INDEX state_groups_state_type_idx"
                     " ON state_groups_state(state_group, type, state_key)"
@@ -835,9 +843,7 @@ class StateStore(SQLBaseStore):
                     "DROP INDEX IF EXISTS state_groups_state_id"
                 )
 
-        yield self.runInteraction(
-            self.STATE_GROUP_INDEX_UPDATE_NAME, reindex_txn
-        )
+        yield self.runWithConnection(reindex_txn)
 
         yield self._end_background_update(self.STATE_GROUP_INDEX_UPDATE_NAME)