From df3dbb68b58b2b446b83d863db86ba253d6d31fe Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Thu, 28 Mar 2024 15:46:15 +0000 Subject: [PATCH 1/6] Add push rules worker to complement --- docker/configure_workers_and_start.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/docker/configure_workers_and_start.py b/docker/configure_workers_and_start.py index 3917d9ae7eb..77534a4f4fd 100755 --- a/docker/configure_workers_and_start.py +++ b/docker/configure_workers_and_start.py @@ -310,6 +310,13 @@ "shared_extra_conf": {}, "worker_extra_conf": "", }, + "push_rules": { + "app": "synapse.app.generic_worker", + "listener_resources": ["client", "replication"], + "endpoint_patterns": ["^/_matrix/client/(api/v1|r0|v3|unstable)/pushrules/"], + "shared_extra_conf": {}, + "worker_extra_conf": "", + }, } # Templates for sections that may be inserted multiple times in config files @@ -401,6 +408,7 @@ def add_worker_roles_to_shared_config( "receipts", "to_device", "typing", + "push_rules", ] # Worker-type specific sharding config. Now a single worker can fulfill multiple From 485b141c5d000de3d3a10f779c54517ec4b22a69 Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Thu, 28 Mar 2024 15:46:30 +0000 Subject: [PATCH 2/6] Fix doc --- docs/workers.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/workers.md b/docs/workers.md index 5ea8ad59bda..6abfbedc692 100644 --- a/docs/workers.md +++ b/docs/workers.md @@ -537,7 +537,7 @@ the stream writer for the `presence` stream: The following endpoints should be routed directly to the worker configured as the stream writer for the `push` stream: - ^/_matrix/client/(api/v1|r0|v3|unstable)/push_rules/ + ^/_matrix/client/(api/v1|r0|v3|unstable)/pushrules/ #### Restrict outbound federation traffic to a specific set of workers From b7291ae8a5a4ed9e492c352912f7ec0294fa8513 Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Thu, 28 Mar 2024 15:47:36 +0000 Subject: [PATCH 3/6] Newsfile --- changelog.d/17038.feature | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog.d/17038.feature diff --git a/changelog.d/17038.feature b/changelog.d/17038.feature new file mode 100644 index 00000000000..bd419c817dc --- /dev/null +++ b/changelog.d/17038.feature @@ -0,0 +1 @@ +Add support for moving `/push_rules` off of main process. From 91415d3fb85eb77b782e7aa023e386bd092e2b7d Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Thu, 28 Mar 2024 15:51:15 +0000 Subject: [PATCH 4/6] Rename stream --- docs/workers.md | 2 +- synapse/config/workers.py | 8 ++++---- synapse/handlers/room_member.py | 4 ++-- synapse/replication/tcp/handler.py | 2 +- synapse/rest/client/push_rule.py | 4 +++- synapse/storage/databases/main/push_rule.py | 4 +++- 6 files changed, 14 insertions(+), 10 deletions(-) diff --git a/docs/workers.md b/docs/workers.md index 6abfbedc692..ab9c1db86b6 100644 --- a/docs/workers.md +++ b/docs/workers.md @@ -532,7 +532,7 @@ the stream writer for the `presence` stream: ^/_matrix/client/(api/v1|r0|v3|unstable)/presence/ -##### The `push` stream +##### The `push_rules` stream The following endpoints should be routed directly to the worker configured as the stream writer for the `push` stream: diff --git a/synapse/config/workers.py b/synapse/config/workers.py index 9f81a73d6f6..7ecf349e4ad 100644 --- a/synapse/config/workers.py +++ b/synapse/config/workers.py @@ -156,7 +156,7 @@ class WriterLocations: can only be a single instance. presence: The instances that write to the presence stream. Currently can only be a single instance. - push: The instances that write to the push stream. Currently + push_rules: The instances that write to the push stream. Currently can only be a single instance. """ @@ -184,7 +184,7 @@ class WriterLocations: default=["master"], converter=_instance_to_list_converter, ) - push: List[str] = attr.ib( + push_rules: List[str] = attr.ib( default=["master"], converter=_instance_to_list_converter, ) @@ -347,7 +347,7 @@ def read_config(self, config: JsonDict, **kwargs: Any) -> None: "account_data", "receipts", "presence", - "push", + "push_rules", ): instances = _instance_to_list_converter(getattr(self.writers, stream)) for instance in instances: @@ -385,7 +385,7 @@ def read_config(self, config: JsonDict, **kwargs: Any) -> None: "Must only specify one instance to handle `presence` messages." ) - if len(self.writers.push) != 1: + if len(self.writers.push_rules) != 1: raise ConfigError( "Must only specify one instance to handle `push` messages." ) diff --git a/synapse/handlers/room_member.py b/synapse/handlers/room_member.py index ee2e807afcf..0c06948e370 100644 --- a/synapse/handlers/room_member.py +++ b/synapse/handlers/room_member.py @@ -182,8 +182,8 @@ def __init__(self, hs: "HomeServer"): hs.config.server.forgotten_room_retention_period ) - self._is_push_writer = hs.get_instance_name() in hs.config.worker.writers.push - self._push_writer = hs.config.worker.writers.push[0] + self._is_push_writer = hs.get_instance_name() in hs.config.worker.writers.push_rules + self._push_writer = hs.config.worker.writers.push_rules[0] self._copy_push_client = ReplicationCopyPusherRestServlet.make_client(hs) def _on_user_joined_room(self, event_id: str, room_id: str) -> None: diff --git a/synapse/replication/tcp/handler.py b/synapse/replication/tcp/handler.py index 4342d6ce701..72a42cb6cc4 100644 --- a/synapse/replication/tcp/handler.py +++ b/synapse/replication/tcp/handler.py @@ -180,7 +180,7 @@ def __init__(self, hs: "HomeServer"): continue if isinstance(stream, PushRulesStream): - if hs.get_instance_name() in hs.config.worker.writers.push: + if hs.get_instance_name() in hs.config.worker.writers.push_rules: self._streams_to_replicate.append(stream) continue diff --git a/synapse/rest/client/push_rule.py b/synapse/rest/client/push_rule.py index 9c9bfc97948..af042504c9b 100644 --- a/synapse/rest/client/push_rule.py +++ b/synapse/rest/client/push_rule.py @@ -59,7 +59,9 @@ def __init__(self, hs: "HomeServer"): self.auth = hs.get_auth() self.store = hs.get_datastores().main self.notifier = hs.get_notifier() - self._is_push_worker = hs.get_instance_name() in hs.config.worker.writers.push + self._is_push_worker = ( + hs.get_instance_name() in hs.config.worker.writers.push_rules + ) self._push_rules_handler = hs.get_push_rules_handler() self._push_rule_linearizer = Linearizer(name="push_rules") diff --git a/synapse/storage/databases/main/push_rule.py b/synapse/storage/databases/main/push_rule.py index ed734f03ac6..660c8345181 100644 --- a/synapse/storage/databases/main/push_rule.py +++ b/synapse/storage/databases/main/push_rule.py @@ -136,7 +136,9 @@ def __init__( ): super().__init__(database, db_conn, hs) - self._is_push_writer = hs.get_instance_name() in hs.config.worker.writers.push + self._is_push_writer = ( + hs.get_instance_name() in hs.config.worker.writers.push_rules + ) # In the worker store this is an ID tracker which we overwrite in the non-worker # class below that is used on the main process. From bc3ff0dac60734a02e48eed094ffa5d63a7e8c80 Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Thu, 28 Mar 2024 15:53:43 +0000 Subject: [PATCH 5/6] Fixup changelogs --- changelog.d/17037.feature | 2 +- changelog.d/17038.feature | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/changelog.d/17037.feature b/changelog.d/17037.feature index bd419c817dc..498221e19eb 100644 --- a/changelog.d/17037.feature +++ b/changelog.d/17037.feature @@ -1 +1 @@ -Add support for moving `/push_rules` off of main process. +Add support for moving `/pushrules` off of main process. diff --git a/changelog.d/17038.feature b/changelog.d/17038.feature index bd419c817dc..498221e19eb 100644 --- a/changelog.d/17038.feature +++ b/changelog.d/17038.feature @@ -1 +1 @@ -Add support for moving `/push_rules` off of main process. +Add support for moving `/pushrules` off of main process. From f6671abdf35340384c24cc5f7430a254529fc81c Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Thu, 28 Mar 2024 15:57:56 +0000 Subject: [PATCH 6/6] Lint --- synapse/handlers/room_member.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/synapse/handlers/room_member.py b/synapse/handlers/room_member.py index 0c06948e370..601d37341b6 100644 --- a/synapse/handlers/room_member.py +++ b/synapse/handlers/room_member.py @@ -182,7 +182,9 @@ def __init__(self, hs: "HomeServer"): hs.config.server.forgotten_room_retention_period ) - self._is_push_writer = hs.get_instance_name() in hs.config.worker.writers.push_rules + self._is_push_writer = ( + hs.get_instance_name() in hs.config.worker.writers.push_rules + ) self._push_writer = hs.config.worker.writers.push_rules[0] self._copy_push_client = ReplicationCopyPusherRestServlet.make_client(hs)