-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Remove worker_replication_*
settings
#15491
Changes from 11 commits
0c0c0cb
d6071f7
da357b0
1d62101
1c1044c
76928ca
940514d
a78a82b
7dcf949
dec47e7
7655e97
34f7454
a0ff5c4
e3f7936
f6c24e4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Remove need for `worker_replication_*` based settings in worker configuration yaml by placing this data directly on the `instance_map` instead. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3846,15 +3846,20 @@ federation_sender_instances: | |
### `instance_map` | ||
|
||
When using workers this should be a map from [`worker_name`](#worker_name) to the | ||
HTTP replication listener of the worker, if configured. | ||
HTTP replication listener of the worker, if configured, and to the main process. | ||
Each worker declared under [`stream_writers`](../../workers.md#stream-writers) needs | ||
a HTTP replication listener, and that listener should be included in the `instance_map`. | ||
(The main process also needs an HTTP replication listener, but it should not be | ||
listed in the `instance_map`.) | ||
The main process also needs an entry on the `instance_map`, and it should be listed under | ||
`main` **if even one other worker exists**. Ensure the port matches with what is declared | ||
inside the `listener` block for a `replication` listener. | ||
|
||
|
||
Example configuration: | ||
```yaml | ||
instance_map: | ||
main: | ||
host: localhost | ||
port: 8030 | ||
worker1: | ||
host: localhost | ||
port: 8034 | ||
|
@@ -3864,7 +3869,8 @@ instance_map: | |
|
||
Experimental: When using workers you can define which workers should | ||
handle writing to streams such as event persistence and typing notifications. | ||
Any worker specified here must also be in the [`instance_map`](#instance_map). | ||
Any worker specified here must also be in the [`instance_map`](#instance_map), the | ||
exception being the main process. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. to be honest I feel like this phrasing just adds more confusion, I'd probably settle towards the little innocent lie that you need to have all the workers, even main, defined in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This particular block was about There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess I'm not sure I'm following 'the exception being the main process' here There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The exception is that the main process doesn't need to be anywhere on the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it would be in order to just remove the words 'the exception being the main process' — if you see what I mean, the implication is going the other way to what you're saying. What you mean is 'Any worker in the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, I'm convinced. Fixed in f6c24e4 |
||
|
||
See the list of available streams in the | ||
[worker documentation](../../workers.md#stream-writers). | ||
|
@@ -3986,6 +3992,7 @@ worker_name: generic_worker1 | |
``` | ||
--- | ||
### `worker_replication_host` | ||
*Deprecated as of version 1.83.0. Place `host` under `main` entry on the [`instance_map`](#instance_map) in your shared yaml configuration instead.* | ||
|
||
The HTTP replication endpoint that it should talk to on the main Synapse process. | ||
The main Synapse process defines this with a `replication` resource in | ||
|
@@ -3997,6 +4004,7 @@ worker_replication_host: 127.0.0.1 | |
``` | ||
--- | ||
### `worker_replication_http_port` | ||
*Deprecated as of version 1.83.0. Place `port` under `main` entry on the [`instance_map`](#instance_map) in your shared yaml configuration instead.* | ||
|
||
The HTTP replication port that it should talk to on the main Synapse process. | ||
The main Synapse process defines this with a `replication` resource in | ||
|
@@ -4008,6 +4016,7 @@ worker_replication_http_port: 9093 | |
``` | ||
--- | ||
### `worker_replication_http_tls` | ||
*Deprecated as of version 1.83.0. Place `tls` under `main` entry on the [`instance_map`](#instance_map) in your shared yaml configuration instead.* | ||
|
||
Whether TLS should be used for talking to the HTTP replication port on the main | ||
Synapse process. | ||
|
@@ -4033,9 +4042,9 @@ A worker can handle HTTP requests. To do so, a `worker_listeners` option | |
must be declared, in the same way as the [`listeners` option](#listeners) | ||
realtyem marked this conversation as resolved.
Show resolved
Hide resolved
|
||
in the shared config. | ||
|
||
Workers declared in [`stream_writers`](#stream_writers) will need to include a | ||
`replication` listener here, in order to accept internal HTTP requests from | ||
other workers. | ||
Workers declared in [`stream_writers`](#stream_writers) and [`instance_map`](#instance_map) | ||
realtyem marked this conversation as resolved.
Show resolved
Hide resolved
|
||
will need to include a `replication` listener here, in order to accept internal HTTP | ||
requests from other workers. | ||
|
||
Example configuration: | ||
```yaml | ||
|
Original file line number | Diff line number | Diff line change | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -39,6 +39,19 @@ | |||||||||||||
Synapse version. Please use ``%s: name_of_worker`` instead. | ||||||||||||||
""" | ||||||||||||||
|
||||||||||||||
_MISSING_MAIN_PROCESS_INSTANCE_MAP_DATA = """ | ||||||||||||||
Missing data for a worker to connect to main process. Please include '%s' in the | ||||||||||||||
`instance_map` declared in your shared yaml configuration, or optionally(as a deprecated | ||||||||||||||
solution) in every worker's yaml as various `worker_replication_*` settings as defined | ||||||||||||||
in workers documentation here: | ||||||||||||||
`https://matrix-org.github.io/synapse/latest/workers.html#worker-configuration` | ||||||||||||||
""" | ||||||||||||||
# This allows for a handy knob when it's time to change from 'master' to | ||||||||||||||
# something with less 'history' | ||||||||||||||
MAIN_PROCESS_INSTANCE_NAME = "master" | ||||||||||||||
# Use this to adjust what the main process is known as in the yaml instance_map | ||||||||||||||
MAIN_PROCESS_INSTANCE_MAP_NAME = "main" | ||||||||||||||
|
||||||||||||||
logger = logging.getLogger(__name__) | ||||||||||||||
|
||||||||||||||
|
||||||||||||||
|
@@ -161,27 +174,15 @@ def read_config(self, config: JsonDict, **kwargs: Any) -> None: | |||||||||||||
raise ConfigError("worker_log_config must be a string") | ||||||||||||||
self.worker_log_config = worker_log_config | ||||||||||||||
|
||||||||||||||
# The host used to connect to the main synapse | ||||||||||||||
self.worker_replication_host = config.get("worker_replication_host", None) | ||||||||||||||
|
||||||||||||||
# The port on the main synapse for TCP replication | ||||||||||||||
if "worker_replication_port" in config: | ||||||||||||||
raise ConfigError(DIRECT_TCP_ERROR, ("worker_replication_port",)) | ||||||||||||||
|
||||||||||||||
# The port on the main synapse for HTTP replication endpoint | ||||||||||||||
self.worker_replication_http_port = config.get("worker_replication_http_port") | ||||||||||||||
|
||||||||||||||
# The tls mode on the main synapse for HTTP replication endpoint. | ||||||||||||||
# For backward compatibility this defaults to False. | ||||||||||||||
self.worker_replication_http_tls = config.get( | ||||||||||||||
"worker_replication_http_tls", False | ||||||||||||||
) | ||||||||||||||
|
||||||||||||||
# The shared secret used for authentication when connecting to the main synapse. | ||||||||||||||
self.worker_replication_secret = config.get("worker_replication_secret", None) | ||||||||||||||
|
||||||||||||||
self.worker_name = config.get("worker_name", self.worker_app) | ||||||||||||||
self.instance_name = self.worker_name or "master" | ||||||||||||||
self.instance_name = self.worker_name or MAIN_PROCESS_INSTANCE_NAME | ||||||||||||||
|
||||||||||||||
# FIXME: Remove this check after a suitable amount of time. | ||||||||||||||
self.worker_main_http_uri = config.get("worker_main_http_uri", None) | ||||||||||||||
|
@@ -215,12 +216,55 @@ def read_config(self, config: JsonDict, **kwargs: Any) -> None: | |||||||||||||
) | ||||||||||||||
|
||||||||||||||
# A map from instance name to host/port of their HTTP replication endpoint. | ||||||||||||||
# Check if the main process is declared. Inject it into the map if it's not, | ||||||||||||||
# based first on if a 'main' block is declared then on 'worker_replication_*' | ||||||||||||||
# data. If both are available, default to instance_map. The main process | ||||||||||||||
# itself doesn't need this data as it would never have to talk to itself. | ||||||||||||||
instance_map: Dict[str, Any] = config.get("instance_map", {}) | ||||||||||||||
|
||||||||||||||
if instance_map and self.instance_name is not MAIN_PROCESS_INSTANCE_NAME: | ||||||||||||||
# The host used to connect to the main synapse | ||||||||||||||
main_host = config.get("worker_replication_host", None) | ||||||||||||||
|
||||||||||||||
# The port on the main synapse for HTTP replication endpoint | ||||||||||||||
main_port = config.get("worker_replication_http_port") | ||||||||||||||
|
||||||||||||||
# The tls mode on the main synapse for HTTP replication endpoint. | ||||||||||||||
# For backward compatibility this defaults to False. | ||||||||||||||
main_tls = config.get("worker_replication_http_tls", False) | ||||||||||||||
|
||||||||||||||
# For now, accept 'main' in the instance_map, but the replication system | ||||||||||||||
# expects 'master', force that into being until it's changed later. | ||||||||||||||
if MAIN_PROCESS_INSTANCE_MAP_NAME in instance_map: | ||||||||||||||
instance_map.setdefault(MAIN_PROCESS_INSTANCE_NAME, {}) | ||||||||||||||
for k, v in instance_map[MAIN_PROCESS_INSTANCE_MAP_NAME].items(): | ||||||||||||||
instance_map[MAIN_PROCESS_INSTANCE_NAME].setdefault(k, v) | ||||||||||||||
del instance_map[MAIN_PROCESS_INSTANCE_MAP_NAME] | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. wondering what's wrong with
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's been a few weeks, but IIRC it was giving me a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Whatever I had done before must not have been this. You got it(plus formatting changes cuz lint) in f6c24e4 |
||||||||||||||
|
||||||||||||||
# This is the backwards compatibility bit that handles the | ||||||||||||||
# worker_replication_* bits using setdefault() to not overwrite anything. | ||||||||||||||
elif main_host is not None and main_port is not None: | ||||||||||||||
instance_map.setdefault( | ||||||||||||||
MAIN_PROCESS_INSTANCE_NAME, | ||||||||||||||
{ | ||||||||||||||
"host": main_host, | ||||||||||||||
"port": main_port, | ||||||||||||||
"tls": main_tls, | ||||||||||||||
}, | ||||||||||||||
) | ||||||||||||||
|
||||||||||||||
else: | ||||||||||||||
# If we've gotten here, it means that the main process is not on the | ||||||||||||||
# instance_map and that not enough worker_replication_* variables | ||||||||||||||
# were declared in the worker's yaml. | ||||||||||||||
raise ConfigError( | ||||||||||||||
_MISSING_MAIN_PROCESS_INSTANCE_MAP_DATA | ||||||||||||||
% MAIN_PROCESS_INSTANCE_MAP_NAME | ||||||||||||||
) | ||||||||||||||
|
||||||||||||||
self.instance_map: Dict[ | ||||||||||||||
str, InstanceLocationConfig | ||||||||||||||
] = parse_and_validate_mapping( | ||||||||||||||
config.get("instance_map", {}), | ||||||||||||||
InstanceLocationConfig, | ||||||||||||||
) | ||||||||||||||
] = parse_and_validate_mapping(instance_map, InstanceLocationConfig) | ||||||||||||||
|
||||||||||||||
# Map from type of streams to source, c.f. WriterLocations. | ||||||||||||||
writers = config.get("stream_writers") or {} | ||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd probably rejig the title and try and make it clearer that the 3 settings not only can be removed, but should be removed because they are now deprecated (though it's also worth being fair that there is still backwards compat for now).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So...
## Worker YAML setting removal and deprecations
...instead? I guess I don't follow
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess your PR title has it more or less spot on... how about:
## Deprecation of `worker_replication_*` configuration options
Then just make the upgrade notes as clear as possible about what you need to migrate (e.g. a before and after example)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Gave this a shot in e3f7936