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

Commit

Permalink
Fix bug where we failed to delete old push actions (#13194)
Browse files Browse the repository at this point in the history
This happened if we encountered a stream ordering in `event_push_actions` that had more rows than the batch size of the delete, as If we don't delete any rows in an iteration then the next time round we get the exact same stream ordering and get stuck.
  • Loading branch information
erikjohnston authored Jul 6, 2022
1 parent 68db233 commit a0f51b0
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
1 change: 1 addition & 0 deletions changelog.d/13194.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix bug where rows were not deleted from `event_push_actions` table on large servers. Introduced in v1.62.0.
6 changes: 4 additions & 2 deletions synapse/storage/databases/main/event_push_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -1114,7 +1114,7 @@ def remove_old_push_actions_that_have_rotated_txn(
txn.execute(
"""
SELECT stream_ordering FROM event_push_actions
WHERE stream_ordering < ? AND highlight = 0
WHERE stream_ordering <= ? AND highlight = 0
ORDER BY stream_ordering ASC LIMIT 1 OFFSET ?
""",
(
Expand All @@ -1129,10 +1129,12 @@ def remove_old_push_actions_that_have_rotated_txn(
else:
stream_ordering = max_stream_ordering_to_delete

# We need to use a inclusive bound here to handle the case where a
# single stream ordering has more than `batch_size` rows.
txn.execute(
"""
DELETE FROM event_push_actions
WHERE stream_ordering < ? AND highlight = 0
WHERE stream_ordering <= ? AND highlight = 0
""",
(stream_ordering,),
)
Expand Down

0 comments on commit a0f51b0

Please sign in to comment.