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

Commit 723ce73

Browse files
authored
Fix stuck notification counts on small servers (#13168)
1 parent 8d7491a commit 723ce73

File tree

3 files changed

+13
-7
lines changed

3 files changed

+13
-7
lines changed

changelog.d/13168.bugfix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix unread counts for users on small servers. Introduced in v1.62.0rc1.

synapse/storage/databases/main/event_push_actions.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -972,7 +972,12 @@ def _rotate_notifs_txn(self, txn: LoggingTransaction) -> bool:
972972
stream_row = txn.fetchone()
973973
if stream_row:
974974
(offset_stream_ordering,) = stream_row
975-
rotate_to_stream_ordering = offset_stream_ordering
975+
976+
# We need to bound by the current token to ensure that we handle
977+
# out-of-order writes correctly.
978+
rotate_to_stream_ordering = min(
979+
offset_stream_ordering, self._stream_id_gen.get_current_token()
980+
)
976981
caught_up = False
977982
else:
978983
rotate_to_stream_ordering = self._stream_id_gen.get_current_token()
@@ -1004,7 +1009,7 @@ def _rotate_notifs_before_txn(
10041009
SELECT user_id, room_id, count(*) as cnt,
10051010
max(stream_ordering) as stream_ordering
10061011
FROM event_push_actions
1007-
WHERE ? <= stream_ordering AND stream_ordering < ?
1012+
WHERE ? < stream_ordering AND stream_ordering <= ?
10081013
AND %s = 1
10091014
GROUP BY user_id, room_id
10101015
) AS upd

tests/storage/test_event_push_actions.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -146,12 +146,12 @@ def _mark_read(stream: int, depth: int) -> None:
146146
_assert_counts(0, 0)
147147
_inject_actions(1, PlAIN_NOTIF)
148148
_assert_counts(1, 0)
149-
_rotate(2)
149+
_rotate(1)
150150
_assert_counts(1, 0)
151151

152152
_inject_actions(3, PlAIN_NOTIF)
153153
_assert_counts(2, 0)
154-
_rotate(4)
154+
_rotate(3)
155155
_assert_counts(2, 0)
156156

157157
_inject_actions(5, PlAIN_NOTIF)
@@ -162,7 +162,7 @@ def _mark_read(stream: int, depth: int) -> None:
162162
_assert_counts(0, 0)
163163

164164
_inject_actions(6, PlAIN_NOTIF)
165-
_rotate(7)
165+
_rotate(6)
166166
_assert_counts(1, 0)
167167

168168
self.get_success(
@@ -178,13 +178,13 @@ def _mark_read(stream: int, depth: int) -> None:
178178

179179
_inject_actions(8, HIGHLIGHT)
180180
_assert_counts(1, 1)
181-
_rotate(9)
181+
_rotate(8)
182182
_assert_counts(1, 1)
183183

184184
# Check that adding another notification and rotating after highlight
185185
# works.
186186
_inject_actions(10, PlAIN_NOTIF)
187-
_rotate(11)
187+
_rotate(10)
188188
_assert_counts(2, 1)
189189

190190
# Check that sending read receipts at different points results in the

0 commit comments

Comments
 (0)