Skip to content

Commit a0f51b0

Browse files
authored
Fix bug where we failed to delete old push actions (matrix-org#13194)
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.
1 parent 68db233 commit a0f51b0

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

changelog.d/13194.bugfix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix bug where rows were not deleted from `event_push_actions` table on large servers. Introduced in v1.62.0.

synapse/storage/databases/main/event_push_actions.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1114,7 +1114,7 @@ def remove_old_push_actions_that_have_rotated_txn(
11141114
txn.execute(
11151115
"""
11161116
SELECT stream_ordering FROM event_push_actions
1117-
WHERE stream_ordering < ? AND highlight = 0
1117+
WHERE stream_ordering <= ? AND highlight = 0
11181118
ORDER BY stream_ordering ASC LIMIT 1 OFFSET ?
11191119
""",
11201120
(
@@ -1129,10 +1129,12 @@ def remove_old_push_actions_that_have_rotated_txn(
11291129
else:
11301130
stream_ordering = max_stream_ordering_to_delete
11311131

1132+
# We need to use a inclusive bound here to handle the case where a
1133+
# single stream ordering has more than `batch_size` rows.
11321134
txn.execute(
11331135
"""
11341136
DELETE FROM event_push_actions
1135-
WHERE stream_ordering < ? AND highlight = 0
1137+
WHERE stream_ordering <= ? AND highlight = 0
11361138
""",
11371139
(stream_ordering,),
11381140
)

0 commit comments

Comments
 (0)