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

Commit 699192f

Browse files
reivilibreH-Shay
andauthored
Add the update_user_directory_from_worker configuration option (superseding update_user_directory) to allow a generic worker to be designated as the worker to update the user directory. (#12654)
Co-authored-by: Shay <[email protected]>
1 parent 8ef0d85 commit 699192f

File tree

9 files changed

+76
-34
lines changed

9 files changed

+76
-34
lines changed

changelog.d/12654.feature

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add the `update_user_directory_from_worker` configuration option (superseding `update_user_directory`) to allow a generic worker to be designated as the worker to update the user directory.

docs/upgrade.md

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -101,29 +101,36 @@ To re-enable this functionality, set the
101101
homeserver config option to `true`.
102102
103103
104-
## Deprecation of the `synapse.app.appservice` worker application type
104+
## Deprecation of the `synapse.app.appservice` and `synapse.app.user_dir` worker application types
105105
106106
The `synapse.app.appservice` worker application type allowed you to configure a
107107
single worker to use to notify application services of new events, as long
108108
as this functionality was disabled on the main process with `notify_appservices: False`.
109+
Further, the `synapse.app.user_dir` worker application type allowed you to configure
110+
a single worker to be responsible for updating the user directory, as long as this
111+
was disabled on the main process with `update_user_directory: False`.
109112
110113
To unify Synapse's worker types, the `synapse.app.appservice` worker application
111114
type and the `notify_appservices` configuration option have been deprecated.
115+
The `synapse.app.user_dir` worker application type and `update_user_directory`
116+
configuration option have also been deprecated.
112117

113-
To get the same functionality, it's now recommended that the `synapse.app.generic_worker`
114-
worker application type is used and that the `notify_appservices_from_worker` option
115-
is set to the name of a worker.
118+
To get the same functionality as was provided by the deprecated options, it's now recommended that the `synapse.app.generic_worker`
119+
worker application type is used and that the `notify_appservices_from_worker` and/or
120+
`update_user_directory_from_worker` options are set to the name of a worker.
116121
117-
For the time being, `notify_appservices_from_worker` can be used alongside
118-
`synapse.app.appservice` and `notify_appservices` to make it easier to transition
119-
between the two configurations, however please note that:
122+
For the time being, the old options can be used alongside the new options to make
123+
it easier to transition between the two configurations, however please note that:
120124
121125
- the options must not contradict each other (otherwise Synapse won't start); and
122-
- the `notify_appservices` option will be removed in a future release of Synapse.
126+
- the `notify_appservices` and `update_user_directory` options will be removed in a future release of Synapse.
123127

124-
Please see [the relevant section of the worker documentation][v1_59_notify_ases_from] for more information.
128+
Please see the [*Notifying Application Services*][v1_59_notify_ases_from] and
129+
[*Updating the User Directory*][v1_59_update_user_dir] sections of the worker
130+
documentation for more information.
125131

126132
[v1_59_notify_ases_from]: workers.md#notifying-application-services
133+
[v1_59_update_user_dir]: workers.md#updating-the-user-directory
127134

128135

129136
# Upgrading to v1.58.0

docs/workers.md

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,7 @@ the shared configuration would include:
426426
run_background_tasks_on: background_worker
427427
```
428428

429-
You might also wish to investigate the `update_user_directory` and
429+
You might also wish to investigate the `update_user_directory_from_worker` and
430430
`media_instance_running_background_jobs` settings.
431431

432432
An example for a dedicated background worker instance:
@@ -435,9 +435,26 @@ An example for a dedicated background worker instance:
435435
{{#include systemd-with-workers/workers/background_worker.yaml}}
436436
```
437437

438+
#### Updating the User Directory
439+
440+
You can designate one generic worker to update the user directory.
441+
442+
Specify its name in the shared configuration as follows:
443+
444+
```yaml
445+
update_user_directory_from_worker: worker_name
446+
```
447+
448+
This work cannot be load-balanced; please ensure the main process is restarted
449+
after setting this option in the shared configuration!
450+
451+
This style of configuration supersedes the legacy `synapse.app.user_dir`
452+
worker application type.
453+
454+
438455
#### Notifying Application Services
439456

440-
You can designate one worker to send output traffic to Application Services.
457+
You can designate one generic worker to send output traffic to Application Services.
441458

442459
Specify its name in the shared configuration as follows:
443460

@@ -470,7 +487,7 @@ pusher_instances:
470487

471488
### `synapse.app.appservice`
472489

473-
**Deprecated as of Synapse v1.58.** [Use `synapse.app.generic_worker` with the
490+
**Deprecated as of Synapse v1.59.** [Use `synapse.app.generic_worker` with the
474491
`notify_appservices_from_worker` option instead.](#notifying-application-services)
475492

476493
Handles sending output traffic to Application Services. Doesn't handle any
@@ -540,6 +557,9 @@ Note that if a reverse proxy is used , then `/_matrix/media/` must be routed for
540557

541558
### `synapse.app.user_dir`
542559

560+
**Deprecated as of Synapse v1.59.** [Use `synapse.app.generic_worker` with the
561+
`update_user_directory_from_worker` option instead.](#updating-the-user-directory)
562+
543563
Handles searches in the user directory. It can handle REST endpoints matching
544564
the following regular expressions:
545565

synapse/app/admin_cmd.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ def start(config_options: List[str]) -> None:
210210
config.logging.no_redirect_stdio = True
211211

212212
# Explicitly disable background processes
213-
config.server.update_user_directory = False
213+
config.worker.should_update_user_directory = False
214214
config.worker.run_background_tasks = False
215215
config.worker.start_pushers = False
216216
config.worker.pusher_shard_config.instances = []

synapse/app/generic_worker.py

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -441,22 +441,6 @@ def start(config_options: List[str]) -> None:
441441
"synapse.app.user_dir",
442442
)
443443

444-
if config.worker.worker_app == "synapse.app.user_dir":
445-
if config.server.update_user_directory:
446-
sys.stderr.write(
447-
"\nThe update_user_directory must be disabled in the main synapse process"
448-
"\nbefore they can be run in a separate worker."
449-
"\nPlease add ``update_user_directory: false`` to the main config"
450-
"\n"
451-
)
452-
sys.exit(1)
453-
454-
# Force the pushers to start since they will be disabled in the main config
455-
config.server.update_user_directory = True
456-
else:
457-
# For other worker types we force this to off.
458-
config.server.update_user_directory = False
459-
460444
synapse.events.USE_FROZEN_DICTS = config.server.use_frozen_dicts
461445
synapse.util.caches.TRACK_MEMORY_USAGE = config.caches.track_memory_usage
462446

synapse/config/server.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -319,10 +319,6 @@ def read_config(self, config: JsonDict, **kwargs: Any) -> None:
319319
self.presence_router_config,
320320
) = load_module(presence_router_config, ("presence", "presence_router"))
321321

322-
# Whether to update the user directory or not. This should be set to
323-
# false only if we are updating the user directory in a worker
324-
self.update_user_directory = config.get("update_user_directory", True)
325-
326322
# whether to enable the media repository endpoints. This should be set
327323
# to false if the media repository is running as a separate endpoint;
328324
# doing so ensures that we will not run cache cleanup jobs on the

synapse/config/workers.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,13 @@ def read_config(self, config: JsonDict, **kwargs: Any) -> None:
311311
new_option_name="notify_appservices_from_worker",
312312
)
313313

314+
self.should_update_user_directory = self._should_this_worker_perform_duty(
315+
config,
316+
legacy_master_option_name="update_user_directory",
317+
legacy_worker_app_name="synapse.app.user_dir",
318+
new_option_name="update_user_directory_from_worker",
319+
)
320+
314321
def _should_this_worker_perform_duty(
315322
self,
316323
config: Dict[str, Any],

synapse/handlers/user_directory.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ def __init__(self, hs: "HomeServer"):
6060
self.clock = hs.get_clock()
6161
self.notifier = hs.get_notifier()
6262
self.is_mine_id = hs.is_mine_id
63-
self.update_user_directory = hs.config.server.update_user_directory
63+
self.update_user_directory = hs.config.worker.should_update_user_directory
6464
self.search_all_users = hs.config.userdirectory.user_directory_search_all_users
6565
self.spam_checker = hs.get_spam_checker()
6666
# The current position in the current_state_delta stream

tests/config/test_workers.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,3 +286,30 @@ def test_new_configs_appservice_worker(self) -> None:
286286
"notify_appservices_from_worker",
287287
)
288288
)
289+
290+
def test_worker_duty_configs(self) -> None:
291+
"""
292+
Additional tests for the worker duties
293+
"""
294+
295+
worker1_config = self._make_worker_config(
296+
worker_app="synapse.app.generic_worker",
297+
worker_name="worker1",
298+
extras={
299+
"notify_appservices_from_worker": "worker2",
300+
"update_user_directory_from_worker": "worker1",
301+
},
302+
)
303+
self.assertFalse(worker1_config.should_notify_appservices)
304+
self.assertTrue(worker1_config.should_update_user_directory)
305+
306+
worker2_config = self._make_worker_config(
307+
worker_app="synapse.app.generic_worker",
308+
worker_name="worker2",
309+
extras={
310+
"notify_appservices_from_worker": "worker2",
311+
"update_user_directory_from_worker": "worker1",
312+
},
313+
)
314+
self.assertTrue(worker2_config.should_notify_appservices)
315+
self.assertFalse(worker2_config.should_update_user_directory)

0 commit comments

Comments
 (0)