summary refs log tree commit diff
diff options
context:
space:
mode:
authorDavid Robertson <davidr@element.io>2022-10-01 22:54:49 +0100
committerDavid Robertson <davidr@element.io>2022-10-01 23:50:03 +0100
commitd75da0e392ad2a5ed82c292be1087871f3893f86 (patch)
tree5469d9d8ead34e237b02cbd6db2e2ca3b59a3d68
parentAnnotate runInteraction (diff)
downloadsynapse-d75da0e392ad2a5ed82c292be1087871f3893f86.tar.xz
Fix errors related to ambiguous db_autocommit
-rw-r--r--synapse/storage/database.py59
-rw-r--r--synapse/storage/databases/main/event_federation.py5
-rw-r--r--synapse/storage/util/id_generators.py5
3 files changed, 41 insertions, 28 deletions
diff --git a/synapse/storage/database.py b/synapse/storage/database.py
index 4036be5cc7..a547fabe42 100644
--- a/synapse/storage/database.py
+++ b/synapse/storage/database.py
@@ -1213,15 +1213,16 @@ class DatabasePool:
                 # We can autocommit if it is safe to upsert
                 autocommit = table not in self._unsafe_to_upsert_tables
 
-                return await self.runInteraction(
+                return await self.runInteraction_advanced(
                     desc,
+                    autocommit,
+                    None,
                     self.simple_upsert_txn,
                     table,
                     keyvalues,
                     values,
                     insertion_values,
                     lock=lock,
-                    db_autocommit=autocommit,
                 )
             except self.engine.module.IntegrityError as e:
                 attempts += 1
@@ -1436,8 +1437,10 @@ class DatabasePool:
         # We can autocommit if it safe to upsert
         autocommit = table not in self._unsafe_to_upsert_tables
 
-        await self.runInteraction(
+        await self.runInteraction_advanced(
             desc,
+            autocommit,
+            None,
             self.simple_upsert_many_txn,
             table,
             key_names,
@@ -1445,7 +1448,6 @@ class DatabasePool:
             value_names,
             value_values,
             lock=lock,
-            db_autocommit=autocommit,
         )
 
     def simple_upsert_many_txn(
@@ -1622,14 +1624,15 @@ class DatabasePool:
                 statement returns no rows
             desc: description of the transaction, for logging and metrics
         """
-        return await self.runInteraction(
+        return await self.runInteraction_advanced(
             desc,
+            True,
+            None,
             self.simple_select_one_txn,
             table,
             keyvalues,
             retcols,
             allow_none,
-            db_autocommit=True,
         )
 
     @overload
@@ -1673,14 +1676,15 @@ class DatabasePool:
                 statement returns no rows
             desc: description of the transaction, for logging and metrics
         """
-        return await self.runInteraction(
+        return await self.runInteraction_advanced(
             desc,
+            True,
+            None,
             self.simple_select_one_onecol_txn,
             table,
             keyvalues,
             retcol,
             allow_none=allow_none,
-            db_autocommit=True,
         )
 
     @overload
@@ -1764,13 +1768,14 @@ class DatabasePool:
         Returns:
             Results in a list
         """
-        return await self.runInteraction(
+        return await self.runInteraction_advanced(
             desc,
+            True,
+            None,
             self.simple_select_onecol_txn,
             table,
             keyvalues,
             retcol,
-            db_autocommit=True,
         )
 
     async def simple_select_list(
@@ -1794,13 +1799,14 @@ class DatabasePool:
         Returns:
             A list of dictionaries.
         """
-        return await self.runInteraction(
+        return await self.runInteraction_advanced(
             desc,
+            True,
+            None,
             self.simple_select_list_txn,
             table,
             keyvalues,
             retcols,
-            db_autocommit=True,
         )
 
     @classmethod
@@ -1864,15 +1870,16 @@ class DatabasePool:
         results: List[Dict[str, Any]] = []
 
         for chunk in batch_iter(iterable, batch_size):
-            rows = await self.runInteraction(
+            rows = await self.runInteraction_advanced(
                 desc,
+                True,
+                None,
                 self.simple_select_many_txn,
                 table,
                 column,
                 chunk,
                 keyvalues,
                 retcols,
-                db_autocommit=True,
             )
 
             results.extend(rows)
@@ -2050,13 +2057,14 @@ class DatabasePool:
             updatevalues: dict giving column names and values to update
             desc: description of the transaction, for logging and metrics
         """
-        await self.runInteraction(
+        await self.runInteraction_advanced(
             desc,
+            True,
+            None,
             self.simple_update_one_txn,
             table,
             keyvalues,
             updatevalues,
-            db_autocommit=True,
         )
 
     @classmethod
@@ -2115,12 +2123,13 @@ class DatabasePool:
             keyvalues: dict of column names and values to select the row with
             desc: description of the transaction, for logging and metrics
         """
-        await self.runInteraction(
+        await self.runInteraction_advanced(
             desc,
+            True,
+            None,
             self.simple_delete_one_txn,
             table,
             keyvalues,
-            db_autocommit=True,
         )
 
     @staticmethod
@@ -2160,8 +2169,8 @@ class DatabasePool:
         Returns:
             The number of deleted rows.
         """
-        return await self.runInteraction(
-            desc, self.simple_delete_txn, table, keyvalues, db_autocommit=True
+        return await self.runInteraction_advanced(
+            desc, True, None, self.simple_delete_txn, table, keyvalues
         )
 
     @staticmethod
@@ -2210,14 +2219,15 @@ class DatabasePool:
         Returns:
             Number rows deleted
         """
-        return await self.runInteraction(
+        return await self.runInteraction_advanced(
             desc,
+            True,
+            None,
             self.simple_delete_many_txn,
             table,
             column,
             iterable,
             keyvalues,
-            db_autocommit=True,
         )
 
     @staticmethod
@@ -2403,14 +2413,15 @@ class DatabasePool:
             A list of dictionaries or None.
         """
 
-        return await self.runInteraction(
+        return await self.runInteraction_advanced(
             desc,
+            True,
+            None,
             self.simple_search_list_txn,
             table,
             term,
             col,
             retcols,
-            db_autocommit=True,
         )
 
     @classmethod
diff --git a/synapse/storage/databases/main/event_federation.py b/synapse/storage/databases/main/event_federation.py
index 547df77424..ca0eb4f7f9 100644
--- a/synapse/storage/databases/main/event_federation.py
+++ b/synapse/storage/databases/main/event_federation.py
@@ -1501,13 +1501,14 @@ class EventFederationWorkerStore(SignatureWorkerStore, EventsWorkerStore, SQLBas
             event_id: The event that failed to be fetched or processed
             cause: The error message or reason that we failed to pull the event
         """
-        await self.db_pool.runInteraction(
+        await self.db_pool.runInteraction_advanced(
             "record_event_failed_pull_attempt",
+            True,  # Safe to autocommit as it's a single upsert
+            None,
             self._record_event_failed_pull_attempt_upsert_txn,
             room_id,
             event_id,
             cause,
-            db_autocommit=True,  # Safe as it's a single upsert
         )
 
     def _record_event_failed_pull_attempt_upsert_txn(
diff --git a/synapse/storage/util/id_generators.py b/synapse/storage/util/id_generators.py
index 18dece3399..fb5c0474cb 100644
--- a/synapse/storage/util/id_generators.py
+++ b/synapse/storage/util/id_generators.py
@@ -782,11 +782,12 @@ class _MultiWriterCtxManager:
     async def __aenter__(self) -> Union[int, List[int]]:
         # It's safe to run this in autocommit mode as fetching values from a
         # sequence ignores transaction semantics anyway.
-        self.stream_ids = await self.id_gen._db.runInteraction(
+        self.stream_ids = await self.id_gen._db.runInteraction_advanced(
             "_load_next_mult_id",
+            True,
+            None,
             self.id_gen._load_next_mult_id_txn,
             self.multiple_ids or 1,
-            db_autocommit=True,
         )
 
         if self.multiple_ids is None: