0
0
Fork 1
mirror of https://mau.dev/maunium/synapse.git synced 2024-12-15 12:03:52 +01:00

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,
table: str,
column: str,
iterable: Iterable[Any],
iterable: Collection[Any],
keyvalues: Dict[str, Any],
retcols: Iterable[str],
) -> List[Dict[str, Any]]:
@ -1891,29 +1891,32 @@ class DatabasePool:
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():
@ -2098,7 +2101,7 @@ class DatabasePool:
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.

View file

@ -494,7 +494,7 @@ class AccountDataWorkerStore(SQLBaseStore):
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},
)

View file

@ -667,7 +667,7 @@ class PersistEventsStore:
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

View file

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

View file

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

View file

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

View file

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

View file

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