summary refs log tree commit diff
diff options
context:
space:
mode:
authorMatthew Hodgson <matthew@matrix.org>2018-01-09 16:55:51 +0000
committerMatthew Hodgson <matthew@matrix.org>2018-01-09 16:55:51 +0000
commita66f489678dc05fa89e6849405c37a9a390e62fc (patch)
tree404debd1e308eae3a4d7e1eccd9a1dc21d5e4589
parentswitch back from GIST to GIN indexes (diff)
downloadsynapse-a66f489678dc05fa89e6849405c37a9a390e62fc.tar.xz
fix GIST->GIN switch
-rw-r--r--synapse/storage/schema/delta/38/postgres_fts_gist.sql6
-rw-r--r--synapse/storage/schema/delta/46/postgres_fts_gin.sql17
-rw-r--r--synapse/storage/search.py28
3 files changed, 37 insertions, 14 deletions
diff --git a/synapse/storage/schema/delta/38/postgres_fts_gist.sql b/synapse/storage/schema/delta/38/postgres_fts_gist.sql
index f090a7b75a..5fe27d6877 100644
--- a/synapse/storage/schema/delta/38/postgres_fts_gist.sql
+++ b/synapse/storage/schema/delta/38/postgres_fts_gist.sql
@@ -13,5 +13,7 @@
  * limitations under the License.
  */
 
- INSERT into background_updates (update_name, progress_json)
-     VALUES ('event_search_postgres_gist', '{}');
+-- We no longer do this given we back it out again in schema 46
+
+-- INSERT into background_updates (update_name, progress_json)
+--     VALUES ('event_search_postgres_gist', '{}');
diff --git a/synapse/storage/schema/delta/46/postgres_fts_gin.sql b/synapse/storage/schema/delta/46/postgres_fts_gin.sql
new file mode 100644
index 0000000000..31d7a817eb
--- /dev/null
+++ b/synapse/storage/schema/delta/46/postgres_fts_gin.sql
@@ -0,0 +1,17 @@
+/* Copyright 2018 New Vector Ltd
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+INSERT into background_updates (update_name, progress_json)
+    VALUES ('event_search_postgres_gin', '{}');
diff --git a/synapse/storage/search.py b/synapse/storage/search.py
index ba7141563e..d3e76b58d6 100644
--- a/synapse/storage/search.py
+++ b/synapse/storage/search.py
@@ -146,24 +146,28 @@ class SearchStore(BackgroundUpdateStore):
 
     @defer.inlineCallbacks
     def _background_reindex_gin_search(self, progress, batch_size):
-        '''This handles old synapses which used GIST indexes; converting them
-        back to be GIN as per the actual schema.  Otherwise it crashes out
-        as a NOOP
+        '''This handles old synapses which used GIST indexes, if any;
+        converting them back to be GIN as per the actual schema.
         '''
 
         def create_index(conn):
-            conn.rollback()
-            conn.set_session(autocommit=True)
-            c = conn.cursor()
+            try:
+                conn.rollback()
+                conn.set_session(autocommit=True)
+                c = conn.cursor()
 
-            c.execute(
-                "CREATE INDEX CONCURRENTLY event_search_fts_idx"
-                " ON event_search USING GIN (vector)"
-            )
+                c.execute(
+                    "CREATE INDEX CONCURRENTLY event_search_fts_idx"
+                    " ON event_search USING GIN (vector)"
+                )
 
-            c.execute("DROP INDEX event_search_fts_idx_gist")
+                c.execute("DROP INDEX event_search_fts_idx_gist")
 
-            conn.set_session(autocommit=False)
+                conn.set_session(autocommit=False)
+            except e:
+                logger.warn(
+                    "Ignoring error %s when trying to switch from GIST to GIN" % (e,)
+                )
 
         if isinstance(self.database_engine, PostgresEngine):
             yield self.runWithConnection(create_index)