Skip to content

Commit f8c1d38

Browse files
richvdhphil-flex
authored andcommitted
Fix processing of groups stream, and use symbolic names for streams (matrix-org#7117)
`groups` != `receipts` Introduced in matrix-org#6964
1 parent a9c7f1a commit f8c1d38

3 files changed

Lines changed: 76 additions & 30 deletions

File tree

changelog.d/7117.bugfix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix a bug which meant that groups updates were not correctly replicated between workers.

synapse/app/generic_worker.py

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,23 @@
6565
from synapse.replication.slave.storage.room import RoomStore
6666
from synapse.replication.slave.storage.transactions import SlavedTransactionStore
6767
from synapse.replication.tcp.client import ReplicationClientHandler
68-
from synapse.replication.tcp.streams._base import (
68+
from synapse.replication.tcp.streams import (
69+
AccountDataStream,
6970
DeviceListsStream,
71+
GroupServerStream,
72+
PresenceStream,
73+
PushersStream,
74+
PushRulesStream,
7075
ReceiptsStream,
76+
TagAccountDataStream,
7177
ToDeviceStream,
78+
TypingStream,
79+
)
80+
from synapse.replication.tcp.streams.events import (
81+
EventsStream,
82+
EventsStreamEventRow,
83+
EventsStreamRow,
7284
)
73-
from synapse.replication.tcp.streams.events import EventsStreamEventRow, EventsStreamRow
7485
from synapse.rest.admin import register_servlets_for_media_repo
7586
from synapse.rest.client.v1 import events
7687
from synapse.rest.client.v1.initial_sync import InitialSyncRestServlet
@@ -632,7 +643,7 @@ async def process_and_notify(self, stream_name, token, rows):
632643
if self.send_handler:
633644
self.send_handler.process_replication_rows(stream_name, token, rows)
634645

635-
if stream_name == "events":
646+
if stream_name == EventsStream.NAME:
636647
# We shouldn't get multiple rows per token for events stream, so
637648
# we don't need to optimise this for multiple rows.
638649
for row in rows:
@@ -655,44 +666,44 @@ async def process_and_notify(self, stream_name, token, rows):
655666
)
656667

657668
await self.pusher_pool.on_new_notifications(token, token)
658-
elif stream_name == "push_rules":
669+
elif stream_name == PushRulesStream.NAME:
659670
self.notifier.on_new_event(
660671
"push_rules_key", token, users=[row.user_id for row in rows]
661672
)
662-
elif stream_name in ("account_data", "tag_account_data"):
673+
elif stream_name in (AccountDataStream.NAME, TagAccountDataStream.NAME):
663674
self.notifier.on_new_event(
664675
"account_data_key", token, users=[row.user_id for row in rows]
665676
)
666-
elif stream_name == "receipts":
677+
elif stream_name == ReceiptsStream.NAME:
667678
self.notifier.on_new_event(
668679
"receipt_key", token, rooms=[row.room_id for row in rows]
669680
)
670681
await self.pusher_pool.on_new_receipts(
671682
token, token, {row.room_id for row in rows}
672683
)
673-
elif stream_name == "typing":
684+
elif stream_name == TypingStream.NAME:
674685
self.typing_handler.process_replication_rows(token, rows)
675686
self.notifier.on_new_event(
676687
"typing_key", token, rooms=[row.room_id for row in rows]
677688
)
678-
elif stream_name == "to_device":
689+
elif stream_name == ToDeviceStream.NAME:
679690
entities = [row.entity for row in rows if row.entity.startswith("@")]
680691
if entities:
681692
self.notifier.on_new_event("to_device_key", token, users=entities)
682-
elif stream_name == "device_lists":
693+
elif stream_name == DeviceListsStream.NAME:
683694
all_room_ids = set()
684695
for row in rows:
685696
if row.entity.startswith("@"):
686697
room_ids = await self.store.get_rooms_for_user(row.entity)
687698
all_room_ids.update(room_ids)
688699
self.notifier.on_new_event("device_list_key", token, rooms=all_room_ids)
689-
elif stream_name == "presence":
700+
elif stream_name == PresenceStream.NAME:
690701
await self.presence_handler.process_replication_rows(token, rows)
691-
elif stream_name == "receipts":
702+
elif stream_name == GroupServerStream.NAME:
692703
self.notifier.on_new_event(
693704
"groups_key", token, users=[row.user_id for row in rows]
694705
)
695-
elif stream_name == "pushers":
706+
elif stream_name == PushersStream.NAME:
696707
for row in rows:
697708
if row.deleted:
698709
self.stop_pusher(row.user_id, row.app_id, row.pushkey)

synapse/replication/tcp/streams/__init__.py

Lines changed: 52 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -24,27 +24,61 @@
2424
current_token: The function that returns the current token for the stream
2525
update_function: The function that returns a list of updates between two tokens
2626
"""
27-
28-
from . import _base, events, federation
27+
from synapse.replication.tcp.streams._base import (
28+
AccountDataStream,
29+
BackfillStream,
30+
CachesStream,
31+
DeviceListsStream,
32+
GroupServerStream,
33+
PresenceStream,
34+
PublicRoomsStream,
35+
PushersStream,
36+
PushRulesStream,
37+
ReceiptsStream,
38+
TagAccountDataStream,
39+
ToDeviceStream,
40+
TypingStream,
41+
UserSignatureStream,
42+
)
43+
from synapse.replication.tcp.streams.events import EventsStream
44+
from synapse.replication.tcp.streams.federation import FederationStream
2945

3046
STREAMS_MAP = {
3147
stream.NAME: stream
3248
for stream in (
33-
events.EventsStream,
34-
_base.BackfillStream,
35-
_base.PresenceStream,
36-
_base.TypingStream,
37-
_base.ReceiptsStream,
38-
_base.PushRulesStream,
39-
_base.PushersStream,
40-
_base.CachesStream,
41-
_base.PublicRoomsStream,
42-
_base.DeviceListsStream,
43-
_base.ToDeviceStream,
44-
federation.FederationStream,
45-
_base.TagAccountDataStream,
46-
_base.AccountDataStream,
47-
_base.GroupServerStream,
48-
_base.UserSignatureStream,
49+
EventsStream,
50+
BackfillStream,
51+
PresenceStream,
52+
TypingStream,
53+
ReceiptsStream,
54+
PushRulesStream,
55+
PushersStream,
56+
CachesStream,
57+
PublicRoomsStream,
58+
DeviceListsStream,
59+
ToDeviceStream,
60+
FederationStream,
61+
TagAccountDataStream,
62+
AccountDataStream,
63+
GroupServerStream,
64+
UserSignatureStream,
4965
)
5066
}
67+
68+
__all__ = [
69+
"STREAMS_MAP",
70+
"BackfillStream",
71+
"PresenceStream",
72+
"TypingStream",
73+
"ReceiptsStream",
74+
"PushRulesStream",
75+
"PushersStream",
76+
"CachesStream",
77+
"PublicRoomsStream",
78+
"DeviceListsStream",
79+
"ToDeviceStream",
80+
"TagAccountDataStream",
81+
"AccountDataStream",
82+
"GroupServerStream",
83+
"UserSignatureStream",
84+
]

0 commit comments

Comments
 (0)