summary refs log tree commit diff
path: root/synapse/storage/state.py
diff options
context:
space:
mode:
authorErik Johnston <erik@matrix.org>2016-09-14 10:18:30 +0100
committerErik Johnston <erik@matrix.org>2016-09-14 10:18:30 +0100
commit00f51493f5726210bf649889ed3c03b56fddbe1d (patch)
treeca53263f57f0abc8b1f5822ea6b62f9cffbf4980 /synapse/storage/state.py
parentEnsure we don't mutate state cache entries (diff)
downloadsynapse-00f51493f5726210bf649889ed3c03b56fddbe1d.tar.xz
Fix reindex
Diffstat (limited to '')
-rw-r--r--synapse/storage/state.py31
1 files changed, 16 insertions, 15 deletions
diff --git a/synapse/storage/state.py b/synapse/storage/state.py
index ec8c62b653..7eb342674c 100644
--- a/synapse/storage/state.py
+++ b/synapse/storage/state.py
@@ -819,11 +819,11 @@ class StateStore(SQLBaseStore):
     def _background_index_state(self, progress, batch_size):
         def reindex_txn(conn):
             conn.rollback()
-            # postgres insists on autocommit for the index
-            conn.set_session(autocommit=True)
-            try:
-                txn = conn.cursor()
-                if isinstance(self.database_engine, PostgresEngine):
+            if isinstance(self.database_engine, PostgresEngine):
+                # 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)"
@@ -831,16 +831,17 @@ class StateStore(SQLBaseStore):
                     txn.execute(
                         "DROP INDEX IF EXISTS state_groups_state_id"
                     )
-                else:
-                    txn.execute(
-                        "CREATE INDEX 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)
+                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)"
+                )
+                txn.execute(
+                    "DROP INDEX IF EXISTS state_groups_state_id"
+                )
 
         yield self.runWithConnection(reindex_txn)