Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Commit

Permalink
Fix errors related to ambiguous db_autocommit
Browse files Browse the repository at this point in the history
  • Loading branch information
David Robertson committed Oct 1, 2022
1 parent 9c34f6e commit 907041c
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 27 deletions.
59 changes: 35 additions & 24 deletions synapse/storage/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -1213,15 +1213,16 @@ async def simple_upsert(
# 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
Expand Down Expand Up @@ -1436,16 +1437,17 @@ async def simple_upsert_many(
# 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,
key_values,
value_names,
value_values,
lock=lock,
db_autocommit=autocommit,
)

def simple_upsert_many_txn(
Expand Down Expand Up @@ -1622,14 +1624,15 @@ async def simple_select_one(
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
Expand Down Expand Up @@ -1673,14 +1676,15 @@ async def simple_select_one_onecol(
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
Expand Down Expand Up @@ -1764,13 +1768,14 @@ async def simple_select_onecol(
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(
Expand All @@ -1794,13 +1799,14 @@ async def simple_select_list(
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
Expand Down Expand Up @@ -1864,15 +1870,16 @@ async def simple_select_many_batch(
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)
Expand Down Expand Up @@ -2050,13 +2057,14 @@ async def simple_update_one(
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
Expand Down Expand Up @@ -2115,12 +2123,13 @@ async def simple_delete_one(
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
Expand Down Expand Up @@ -2160,8 +2169,8 @@ async def simple_delete(
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
Expand Down Expand Up @@ -2210,14 +2219,15 @@ async def simple_delete_many(
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
Expand Down Expand Up @@ -2403,14 +2413,15 @@ async def simple_search_list(
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
Expand Down
3 changes: 2 additions & 1 deletion synapse/storage/databases/main/event_federation.py
Original file line number Diff line number Diff line change
Expand Up @@ -1503,11 +1503,12 @@ async def record_event_failed_pull_attempt(
"""
await self.db_pool.runInteraction(
"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(
Expand Down
5 changes: 3 additions & 2 deletions synapse/storage/util/id_generators.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 907041c

Please sign in to comment.