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

Commit 4379617

Browse files
authored
Fix remove_stale_pushers job on SQLite. (#10843)
1 parent 6b6bb81 commit 4379617

File tree

9 files changed

+27
-23
lines changed

9 files changed

+27
-23
lines changed

changelog.d/10843.bugfix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
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.

synapse/storage/database.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1632,7 +1632,7 @@ def simple_select_many_txn(
16321632
txn: LoggingTransaction,
16331633
table: str,
16341634
column: str,
1635-
iterable: Iterable[Any],
1635+
iterable: Collection[Any],
16361636
keyvalues: Dict[str, Any],
16371637
retcols: Iterable[str],
16381638
) -> List[Dict[str, Any]]:
@@ -1891,29 +1891,32 @@ def simple_delete_many_txn(
18911891
txn: LoggingTransaction,
18921892
table: str,
18931893
column: str,
1894-
iterable: Iterable[Any],
1894+
values: Collection[Any],
18951895
keyvalues: Dict[str, Any],
18961896
) -> int:
18971897
"""Executes a DELETE query on the named table.
18981898
1899-
Filters rows by if value of `column` is in `iterable`.
1899+
Deletes the rows:
1900+
- whose value of `column` is in `values`; AND
1901+
- that match extra column-value pairs specified in `keyvalues`.
19001902
19011903
Args:
19021904
txn: Transaction object
19031905
table: string giving the table name
1904-
column: column name to test for inclusion against `iterable`
1905-
iterable: list
1906-
keyvalues: dict of column names and values to select the rows with
1906+
column: column name to test for inclusion against `values`
1907+
values: values of `column` which choose rows to delete
1908+
keyvalues: dict of extra column names and values to select the rows
1909+
with. They will be ANDed together with the main predicate.
19071910
19081911
Returns:
19091912
Number rows deleted
19101913
"""
1911-
if not iterable:
1914+
if not values:
19121915
return 0
19131916

19141917
sql = "DELETE FROM %s" % table
19151918

1916-
clause, values = make_in_list_sql_clause(txn.database_engine, column, iterable)
1919+
clause, values = make_in_list_sql_clause(txn.database_engine, column, values)
19171920
clauses = [clause]
19181921

19191922
for key, value in keyvalues.items():
@@ -2098,7 +2101,7 @@ def simple_search_list_txn(
20982101

20992102

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

synapse/storage/databases/main/account_data.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -494,7 +494,7 @@ def _add_account_data_for_user(
494494
txn,
495495
table="ignored_users",
496496
column="ignored_user_id",
497-
iterable=previously_ignored_users - currently_ignored_users,
497+
values=previously_ignored_users - currently_ignored_users,
498498
keyvalues={"ignorer_user_id": user_id},
499499
)
500500

synapse/storage/databases/main/events.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -667,7 +667,7 @@ def _add_chain_cover_index(
667667
table="event_auth_chain_to_calculate",
668668
keyvalues={},
669669
column="event_id",
670-
iterable=new_chain_tuples,
670+
values=new_chain_tuples,
671671
)
672672

673673
# Now we need to calculate any new links between chains caused by

synapse/storage/databases/main/events_bg_updates.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,7 @@ def _cleanup_extremities_bg_update_txn(txn):
490490
txn=txn,
491491
table="event_forward_extremities",
492492
column="event_id",
493-
iterable=to_delete,
493+
values=to_delete,
494494
keyvalues={},
495495
)
496496

@@ -520,7 +520,7 @@ def _cleanup_extremities_bg_update_txn(txn):
520520
txn=txn,
521521
table="_extremities_to_check",
522522
column="event_id",
523-
iterable=original_set,
523+
values=original_set,
524524
keyvalues={},
525525
)
526526

synapse/storage/databases/main/pusher.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ def _delete_pushers(txn) -> int:
324324
txn,
325325
table="pushers",
326326
column="user_name",
327-
iterable=users,
327+
values=users,
328328
keyvalues={},
329329
)
330330

@@ -373,7 +373,7 @@ def _delete_pushers(txn) -> int:
373373
txn,
374374
table="pushers",
375375
column="id",
376-
iterable=(pusher_id for pusher_id, token in pushers if token is None),
376+
values=[pusher_id for pusher_id, token in pushers if token is None],
377377
keyvalues={},
378378
)
379379

synapse/storage/databases/main/state.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -473,15 +473,15 @@ def _background_remove_left_rooms_txn(txn):
473473
txn,
474474
table="current_state_events",
475475
column="room_id",
476-
iterable=to_delete,
476+
values=to_delete,
477477
keyvalues={},
478478
)
479479

480480
self.db_pool.simple_delete_many_txn(
481481
txn,
482482
table="event_forward_extremities",
483483
column="room_id",
484-
iterable=to_delete,
484+
values=to_delete,
485485
keyvalues={},
486486
)
487487

synapse/storage/databases/main/ui_auth.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ def _delete_old_ui_auth_sessions_txn(
326326
txn,
327327
table="ui_auth_sessions_ips",
328328
column="session_id",
329-
iterable=session_ids,
329+
values=session_ids,
330330
keyvalues={},
331331
)
332332

@@ -377,7 +377,7 @@ def _delete_old_ui_auth_sessions_txn(
377377
txn,
378378
table="ui_auth_sessions_credentials",
379379
column="session_id",
380-
iterable=session_ids,
380+
values=session_ids,
381381
keyvalues={},
382382
)
383383

@@ -386,7 +386,7 @@ def _delete_old_ui_auth_sessions_txn(
386386
txn,
387387
table="ui_auth_sessions",
388388
column="session_id",
389-
iterable=session_ids,
389+
values=session_ids,
390390
keyvalues={},
391391
)
392392

synapse/storage/databases/state/store.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -664,7 +664,7 @@ def _purge_room_state_txn(
664664
txn,
665665
table="state_groups_state",
666666
column="state_group",
667-
iterable=state_groups_to_delete,
667+
values=state_groups_to_delete,
668668
keyvalues={},
669669
)
670670

@@ -675,7 +675,7 @@ def _purge_room_state_txn(
675675
txn,
676676
table="state_group_edges",
677677
column="state_group",
678-
iterable=state_groups_to_delete,
678+
values=state_groups_to_delete,
679679
keyvalues={},
680680
)
681681

@@ -686,6 +686,6 @@ def _purge_room_state_txn(
686686
txn,
687687
table="state_groups",
688688
column="id",
689-
iterable=state_groups_to_delete,
689+
values=state_groups_to_delete,
690690
keyvalues={},
691691
)

0 commit comments

Comments
 (0)