Fix remove_stale_pushers job on SQLite. (#10843)

This commit is contained in:
reivilibre 2021-09-20 10:26:13 +01:00 committed by GitHub
parent 6b6bb81b23
commit 437961744c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 27 additions and 23 deletions

1
changelog.d/10843.bugfix Normal file
View File

@ -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.

View File

@ -1632,7 +1632,7 @@ class DatabasePool:
txn: LoggingTransaction, txn: LoggingTransaction,
table: str, table: str,
column: str, column: str,
iterable: Iterable[Any], iterable: Collection[Any],
keyvalues: Dict[str, Any], keyvalues: Dict[str, Any],
retcols: Iterable[str], retcols: Iterable[str],
) -> List[Dict[str, Any]]: ) -> List[Dict[str, Any]]:
@ -1891,29 +1891,32 @@ class DatabasePool:
txn: LoggingTransaction, txn: LoggingTransaction,
table: str, table: str,
column: str, column: str,
iterable: Iterable[Any], values: Collection[Any],
keyvalues: Dict[str, Any], keyvalues: Dict[str, Any],
) -> int: ) -> int:
"""Executes a DELETE query on the named table. """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: Args:
txn: Transaction object txn: Transaction object
table: string giving the table name table: string giving the table name
column: column name to test for inclusion against `iterable` column: column name to test for inclusion against `values`
iterable: list values: values of `column` which choose rows to delete
keyvalues: dict of column names and values to select the rows with keyvalues: dict of extra column names and values to select the rows
with. They will be ANDed together with the main predicate.
Returns: Returns:
Number rows deleted Number rows deleted
""" """
if not iterable: if not values:
return 0 return 0
sql = "DELETE FROM %s" % table 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] clauses = [clause]
for key, value in keyvalues.items(): for key, value in keyvalues.items():
@ -2098,7 +2101,7 @@ class DatabasePool:
def make_in_list_sql_clause( def make_in_list_sql_clause(
database_engine: BaseDatabaseEngine, column: str, iterable: Iterable database_engine: BaseDatabaseEngine, column: str, iterable: Collection[Any]
) -> Tuple[str, list]: ) -> Tuple[str, list]:
"""Returns an SQL clause that checks the given column is in the iterable. """Returns an SQL clause that checks the given column is in the iterable.

View File

@ -494,7 +494,7 @@ class AccountDataWorkerStore(SQLBaseStore):
txn, txn,
table="ignored_users", table="ignored_users",
column="ignored_user_id", column="ignored_user_id",
iterable=previously_ignored_users - currently_ignored_users, values=previously_ignored_users - currently_ignored_users,
keyvalues={"ignorer_user_id": user_id}, keyvalues={"ignorer_user_id": user_id},
) )

View File

@ -667,7 +667,7 @@ class PersistEventsStore:
table="event_auth_chain_to_calculate", table="event_auth_chain_to_calculate",
keyvalues={}, keyvalues={},
column="event_id", column="event_id",
iterable=new_chain_tuples, values=new_chain_tuples,
) )
# Now we need to calculate any new links between chains caused by # Now we need to calculate any new links between chains caused by

View File

@ -490,7 +490,7 @@ class EventsBackgroundUpdatesStore(SQLBaseStore):
txn=txn, txn=txn,
table="event_forward_extremities", table="event_forward_extremities",
column="event_id", column="event_id",
iterable=to_delete, values=to_delete,
keyvalues={}, keyvalues={},
) )
@ -520,7 +520,7 @@ class EventsBackgroundUpdatesStore(SQLBaseStore):
txn=txn, txn=txn,
table="_extremities_to_check", table="_extremities_to_check",
column="event_id", column="event_id",
iterable=original_set, values=original_set,
keyvalues={}, keyvalues={},
) )

View File

@ -324,7 +324,7 @@ class PusherWorkerStore(SQLBaseStore):
txn, txn,
table="pushers", table="pushers",
column="user_name", column="user_name",
iterable=users, values=users,
keyvalues={}, keyvalues={},
) )
@ -373,7 +373,7 @@ class PusherWorkerStore(SQLBaseStore):
txn, txn,
table="pushers", table="pushers",
column="id", 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={}, keyvalues={},
) )

View File

@ -473,7 +473,7 @@ class MainStateBackgroundUpdateStore(RoomMemberWorkerStore):
txn, txn,
table="current_state_events", table="current_state_events",
column="room_id", column="room_id",
iterable=to_delete, values=to_delete,
keyvalues={}, keyvalues={},
) )
@ -481,7 +481,7 @@ class MainStateBackgroundUpdateStore(RoomMemberWorkerStore):
txn, txn,
table="event_forward_extremities", table="event_forward_extremities",
column="room_id", column="room_id",
iterable=to_delete, values=to_delete,
keyvalues={}, keyvalues={},
) )

View File

@ -326,7 +326,7 @@ class UIAuthWorkerStore(SQLBaseStore):
txn, txn,
table="ui_auth_sessions_ips", table="ui_auth_sessions_ips",
column="session_id", column="session_id",
iterable=session_ids, values=session_ids,
keyvalues={}, keyvalues={},
) )
@ -377,7 +377,7 @@ class UIAuthWorkerStore(SQLBaseStore):
txn, txn,
table="ui_auth_sessions_credentials", table="ui_auth_sessions_credentials",
column="session_id", column="session_id",
iterable=session_ids, values=session_ids,
keyvalues={}, keyvalues={},
) )
@ -386,7 +386,7 @@ class UIAuthWorkerStore(SQLBaseStore):
txn, txn,
table="ui_auth_sessions", table="ui_auth_sessions",
column="session_id", column="session_id",
iterable=session_ids, values=session_ids,
keyvalues={}, keyvalues={},
) )

View File

@ -664,7 +664,7 @@ class StateGroupDataStore(StateBackgroundUpdateStore, SQLBaseStore):
txn, txn,
table="state_groups_state", table="state_groups_state",
column="state_group", column="state_group",
iterable=state_groups_to_delete, values=state_groups_to_delete,
keyvalues={}, keyvalues={},
) )
@ -675,7 +675,7 @@ class StateGroupDataStore(StateBackgroundUpdateStore, SQLBaseStore):
txn, txn,
table="state_group_edges", table="state_group_edges",
column="state_group", column="state_group",
iterable=state_groups_to_delete, values=state_groups_to_delete,
keyvalues={}, keyvalues={},
) )
@ -686,6 +686,6 @@ class StateGroupDataStore(StateBackgroundUpdateStore, SQLBaseStore):
txn, txn,
table="state_groups", table="state_groups",
column="id", column="id",
iterable=state_groups_to_delete, values=state_groups_to_delete,
keyvalues={}, keyvalues={},
) )