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

Commit af54167

Browse files
authored
Enable passing typing stream writers as a list. (#11237)
This makes the typing stream writer config match the other stream writers that only currently support a single worker.
1 parent 2735b3e commit af54167

File tree

8 files changed

+24
-16
lines changed

8 files changed

+24
-16
lines changed

changelog.d/11237.misc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Allow `stream_writers.typing` config to be a list of one worker.

synapse/config/workers.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ class WriterLocations:
6363
6464
Attributes:
6565
events: The instances that write to the event and backfill streams.
66-
typing: The instance that writes to the typing stream.
66+
typing: The instances that write to the typing stream. Currently
67+
can only be a single instance.
6768
to_device: The instances that write to the to_device stream. Currently
6869
can only be a single instance.
6970
account_data: The instances that write to the account data streams. Currently
@@ -75,9 +76,15 @@ class WriterLocations:
7576
"""
7677

7778
events = attr.ib(
78-
default=["master"], type=List[str], converter=_instance_to_list_converter
79+
default=["master"],
80+
type=List[str],
81+
converter=_instance_to_list_converter,
82+
)
83+
typing = attr.ib(
84+
default=["master"],
85+
type=List[str],
86+
converter=_instance_to_list_converter,
7987
)
80-
typing = attr.ib(default="master", type=str)
8188
to_device = attr.ib(
8289
default=["master"],
8390
type=List[str],
@@ -217,6 +224,11 @@ def read_config(self, config, **kwargs):
217224
% (instance, stream)
218225
)
219226

227+
if len(self.writers.typing) != 1:
228+
raise ConfigError(
229+
"Must only specify one instance to handle `typing` messages."
230+
)
231+
220232
if len(self.writers.to_device) != 1:
221233
raise ConfigError(
222234
"Must only specify one instance to handle `to_device` messages."

synapse/federation/federation_server.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1232,10 +1232,6 @@ def register_query_handler(
12321232

12331233
self.query_handlers[query_type] = handler
12341234

1235-
def register_instance_for_edu(self, edu_type: str, instance_name: str) -> None:
1236-
"""Register that the EDU handler is on a different instance than master."""
1237-
self._edu_type_to_instance[edu_type] = [instance_name]
1238-
12391235
def register_instances_for_edu(
12401236
self, edu_type: str, instance_names: List[str]
12411237
) -> None:

synapse/handlers/typing.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ def __init__(self, hs: "HomeServer"):
6262
if hs.should_send_federation():
6363
self.federation = hs.get_federation_sender()
6464

65-
if hs.config.worker.writers.typing != hs.get_instance_name():
66-
hs.get_federation_registry().register_instance_for_edu(
65+
if hs.get_instance_name() not in hs.config.worker.writers.typing:
66+
hs.get_federation_registry().register_instances_for_edu(
6767
"m.typing",
6868
hs.config.worker.writers.typing,
6969
)
@@ -205,7 +205,7 @@ class TypingWriterHandler(FollowerTypingHandler):
205205
def __init__(self, hs: "HomeServer"):
206206
super().__init__(hs)
207207

208-
assert hs.config.worker.writers.typing == hs.get_instance_name()
208+
assert hs.get_instance_name() in hs.config.worker.writers.typing
209209

210210
self.auth = hs.get_auth()
211211
self.notifier = hs.get_notifier()

synapse/replication/tcp/handler.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ def __init__(self, hs: "HomeServer"):
138138
if isinstance(stream, TypingStream):
139139
# Only add TypingStream as a source on the instance in charge of
140140
# typing.
141-
if hs.config.worker.writers.typing == hs.get_instance_name():
141+
if hs.get_instance_name() in hs.config.worker.writers.typing:
142142
self._streams_to_replicate.append(stream)
143143

144144
continue

synapse/replication/tcp/streams/_base.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -328,8 +328,7 @@ class TypingStream(Stream):
328328
ROW_TYPE = TypingStreamRow
329329

330330
def __init__(self, hs: "HomeServer"):
331-
writer_instance = hs.config.worker.writers.typing
332-
if writer_instance == hs.get_instance_name():
331+
if hs.get_instance_name() in hs.config.worker.writers.typing:
333332
# On the writer, query the typing handler
334333
typing_writer_handler = hs.get_typing_writer_handler()
335334
update_function: Callable[

synapse/rest/client/room.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -914,7 +914,7 @@ def __init__(self, hs: "HomeServer"):
914914
# If we're not on the typing writer instance we should scream if we get
915915
# requests.
916916
self._is_typing_writer = (
917-
hs.config.worker.writers.typing == hs.get_instance_name()
917+
hs.get_instance_name() in hs.config.worker.writers.typing
918918
)
919919

920920
async def on_PUT(

synapse/server.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,7 @@ def get_presence_handler(self) -> BasePresenceHandler:
463463

464464
@cache_in_self
465465
def get_typing_writer_handler(self) -> TypingWriterHandler:
466-
if self.config.worker.writers.typing == self.get_instance_name():
466+
if self.get_instance_name() in self.config.worker.writers.typing:
467467
return TypingWriterHandler(self)
468468
else:
469469
raise Exception("Workers cannot write typing")
@@ -474,7 +474,7 @@ def get_presence_router(self) -> PresenceRouter:
474474

475475
@cache_in_self
476476
def get_typing_handler(self) -> FollowerTypingHandler:
477-
if self.config.worker.writers.typing == self.get_instance_name():
477+
if self.get_instance_name() in self.config.worker.writers.typing:
478478
# Use get_typing_writer_handler to ensure that we use the same
479479
# cached version.
480480
return self.get_typing_writer_handler()

0 commit comments

Comments
 (0)