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

Fix remove_stale_pushers job on SQLite. #10843

Merged
merged 6 commits into from
Sep 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/10843.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix a bug causing the `remove_stale_pushers` background job to repeatedly fail and log errors. This bug affected Synapse servers that had been upgraded from version 1.28 or older and are using SQLite.
21 changes: 12 additions & 9 deletions synapse/storage/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -1632,7 +1632,7 @@ def simple_select_many_txn(
txn: LoggingTransaction,
table: str,
column: str,
iterable: Iterable[Any],
iterable: Collection[Any],
keyvalues: Dict[str, Any],
retcols: Iterable[str],
) -> List[Dict[str, Any]]:
Expand Down Expand Up @@ -1891,29 +1891,32 @@ def simple_delete_many_txn(
txn: LoggingTransaction,
table: str,
column: str,
iterable: Iterable[Any],
values: Collection[Any],
keyvalues: Dict[str, Any],
) -> int:
"""Executes a DELETE query on the named table.

Filters rows by if value of `column` is in `iterable`.
Deletes the rows:
- whose value of `column` is in `values`; AND
- that match extra column-value pairs specified in `keyvalues`.

Args:
txn: Transaction object
table: string giving the table name
column: column name to test for inclusion against `iterable`
iterable: list
keyvalues: dict of column names and values to select the rows with
column: column name to test for inclusion against `values`
values: values of `column` which choose rows to delete
keyvalues: dict of extra column names and values to select the rows
with. They will be ANDed together with the main predicate.

Returns:
Number rows deleted
"""
if not iterable:
if not values:
return 0

sql = "DELETE FROM %s" % table

clause, values = make_in_list_sql_clause(txn.database_engine, column, iterable)
clause, values = make_in_list_sql_clause(txn.database_engine, column, values)
clauses = [clause]

for key, value in keyvalues.items():
Expand Down Expand Up @@ -2098,7 +2101,7 @@ def simple_search_list_txn(


def make_in_list_sql_clause(
database_engine: BaseDatabaseEngine, column: str, iterable: Iterable
database_engine: BaseDatabaseEngine, column: str, iterable: Collection[Any]
) -> Tuple[str, list]:
"""Returns an SQL clause that checks the given column is in the iterable.

Expand Down
2 changes: 1 addition & 1 deletion synapse/storage/databases/main/account_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,7 @@ def _add_account_data_for_user(
txn,
table="ignored_users",
column="ignored_user_id",
iterable=previously_ignored_users - currently_ignored_users,
values=previously_ignored_users - currently_ignored_users,
keyvalues={"ignorer_user_id": user_id},
)

Expand Down
2 changes: 1 addition & 1 deletion synapse/storage/databases/main/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -667,7 +667,7 @@ def _add_chain_cover_index(
table="event_auth_chain_to_calculate",
keyvalues={},
column="event_id",
iterable=new_chain_tuples,
values=new_chain_tuples,
)

# Now we need to calculate any new links between chains caused by
Expand Down
4 changes: 2 additions & 2 deletions synapse/storage/databases/main/events_bg_updates.py
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@ def _cleanup_extremities_bg_update_txn(txn):
txn=txn,
table="event_forward_extremities",
column="event_id",
iterable=to_delete,
values=to_delete,
keyvalues={},
)

Expand Down Expand Up @@ -520,7 +520,7 @@ def _cleanup_extremities_bg_update_txn(txn):
txn=txn,
table="_extremities_to_check",
column="event_id",
iterable=original_set,
values=original_set,
keyvalues={},
)

Expand Down
4 changes: 2 additions & 2 deletions synapse/storage/databases/main/pusher.py
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ def _delete_pushers(txn) -> int:
txn,
table="pushers",
column="user_name",
iterable=users,
values=users,
keyvalues={},
)

Expand Down Expand Up @@ -373,7 +373,7 @@ def _delete_pushers(txn) -> int:
txn,
table="pushers",
column="id",
iterable=(pusher_id for pusher_id, token in pushers if token is None),
values=[pusher_id for pusher_id, token in pushers if token is None],
keyvalues={},
)

Expand Down
4 changes: 2 additions & 2 deletions synapse/storage/databases/main/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -473,15 +473,15 @@ def _background_remove_left_rooms_txn(txn):
txn,
table="current_state_events",
column="room_id",
iterable=to_delete,
values=to_delete,
keyvalues={},
)

self.db_pool.simple_delete_many_txn(
txn,
table="event_forward_extremities",
column="room_id",
iterable=to_delete,
values=to_delete,
keyvalues={},
)

Expand Down
6 changes: 3 additions & 3 deletions synapse/storage/databases/main/ui_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ def _delete_old_ui_auth_sessions_txn(
txn,
table="ui_auth_sessions_ips",
column="session_id",
iterable=session_ids,
values=session_ids,
keyvalues={},
)

Expand Down Expand Up @@ -377,7 +377,7 @@ def _delete_old_ui_auth_sessions_txn(
txn,
table="ui_auth_sessions_credentials",
column="session_id",
iterable=session_ids,
values=session_ids,
keyvalues={},
)

Expand All @@ -386,7 +386,7 @@ def _delete_old_ui_auth_sessions_txn(
txn,
table="ui_auth_sessions",
column="session_id",
iterable=session_ids,
values=session_ids,
keyvalues={},
)

Expand Down
6 changes: 3 additions & 3 deletions synapse/storage/databases/state/store.py
Original file line number Diff line number Diff line change
Expand Up @@ -664,7 +664,7 @@ def _purge_room_state_txn(
txn,
table="state_groups_state",
column="state_group",
iterable=state_groups_to_delete,
values=state_groups_to_delete,
keyvalues={},
)

Expand All @@ -675,7 +675,7 @@ def _purge_room_state_txn(
txn,
table="state_group_edges",
column="state_group",
iterable=state_groups_to_delete,
values=state_groups_to_delete,
keyvalues={},
)

Expand All @@ -686,6 +686,6 @@ def _purge_room_state_txn(
txn,
table="state_groups",
column="id",
iterable=state_groups_to_delete,
values=state_groups_to_delete,
keyvalues={},
)