This repository has been archived by the owner on Apr 26, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Allow running sendToDevice on workers #9044
Merged
Merged
Changes from 17 commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
8f7e6b7
Refactor add_messages_to_device_inbox
erikjohnston c132b39
Support routing edu's to multiple instances
erikjohnston 691c373
Newsfile
erikjohnston 124f415
Support resync clients off master
erikjohnston e81d693
Newsfile
erikjohnston 40d9869
Only define _last_device_delete_cache once
erikjohnston 6da60bf
Newsfile
erikjohnston 7386f09
Merge branch 'erikj/resync_off_master' into erikj/split_to_device_sen…
erikjohnston 08a4f88
Merge branch 'erikj/allow_routing_edus' into erikj/split_to_device_se…
erikjohnston 1236ac3
Use MultiWriterIDGenerator for device inbox
erikjohnston 248832e
Allow configuring which workers handle to_device messages
erikjohnston 811cb59
Move DB write functions to worker store
erikjohnston eb6121a
Assert writing to device inbox only happens on appropriate workers
erikjohnston 7d43cb7
Wire up SendToDeviceRestServlet to work on workers
erikjohnston 5420f01
Newsfile
erikjohnston 36f0d2b
Merge remote-tracking branch 'origin/develop' into erikj/split_to_dev…
erikjohnston 9a91c2d
Ensure you can only config one instance to handle to device messages,…
erikjohnston 82286cc
Merge remote-tracking branch 'origin/develop' into erikj/split_to_dev…
erikjohnston d371d96
Update changelog
erikjohnston fc38115
Fix port script to handle new sequences
erikjohnston 2667875
Remove redundant '_device_inbox_id_gen'
erikjohnston 171f360
Expand comment on federation_sender
erikjohnston 867a21f
Remove spurious changelog
erikjohnston 07f2d9a
Fixup comment
erikjohnston 14624e7
Fix newsfile
erikjohnston File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Support routing edu's to multiple instances. | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Allow handling `/sendToDevice` API endpoints on workers. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Allow handling `/sendToDevice` API endpoints on workers. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -24,6 +24,7 @@ | |||||
set_tag, | ||||||
start_active_span, | ||||||
) | ||||||
from synapse.replication.http.devices import ReplicationUserDevicesResyncRestServlet | ||||||
from synapse.types import JsonDict, UserID, get_domain_from_id | ||||||
from synapse.util import json_encoder | ||||||
from synapse.util.stringutils import random_string | ||||||
|
@@ -44,13 +45,32 @@ def __init__(self, hs: "HomeServer"): | |||||
self.store = hs.get_datastore() | ||||||
self.notifier = hs.get_notifier() | ||||||
self.is_mine = hs.is_mine | ||||||
self.federation = hs.get_federation_sender() | ||||||
|
||||||
hs.get_federation_registry().register_edu_handler( | ||||||
"m.direct_to_device", self.on_direct_to_device_edu | ||||||
) | ||||||
# We only need to poke the federation sender explicitly if its 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.
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. ... how does it work if it's on a different instance? 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've expanded the comment to:
|
||||||
# same instance. | ||||||
self.federation_sender = None | ||||||
if hs.should_send_federation(): | ||||||
self.federation_sender = hs.get_federation_sender() | ||||||
|
||||||
# If we can handle the to device EDUs we do so, otherwise we route them | ||||||
# to the appropriate worker. | ||||||
if hs.get_instance_name() in hs.config.worker.writers.to_device: | ||||||
hs.get_federation_registry().register_edu_handler( | ||||||
"m.direct_to_device", self.on_direct_to_device_edu | ||||||
) | ||||||
else: | ||||||
hs.get_federation_registry().register_instances_for_edu( | ||||||
"m.direct_to_device", hs.config.worker.writers.to_device, | ||||||
) | ||||||
|
||||||
self._device_list_updater = hs.get_device_handler().device_list_updater | ||||||
if hs.config.worker.worker_app is None: | ||||||
self._user_device_resync = ( | ||||||
hs.get_device_handler().device_list_updater.user_device_resync | ||||||
) | ||||||
else: | ||||||
self._user_device_resync = ReplicationUserDevicesResyncRestServlet.make_client( | ||||||
hs | ||||||
) | ||||||
|
||||||
async def on_direct_to_device_edu(self, origin: str, content: JsonDict) -> None: | ||||||
local_messages = {} | ||||||
|
@@ -138,9 +158,7 @@ async def _check_for_unknown_devices( | |||||
await self.store.mark_remote_user_device_cache_as_stale(sender_user_id) | ||||||
|
||||||
# Immediately attempt a resync in the background | ||||||
run_in_background( | ||||||
self._device_list_updater.user_device_resync, sender_user_id | ||||||
) | ||||||
run_in_background(self._user_device_resync, sender_user_id) | ||||||
|
||||||
async def send_device_message( | ||||||
self, | ||||||
|
@@ -195,7 +213,8 @@ async def send_device_message( | |||||
) | ||||||
|
||||||
log_kv({"remote_messages": remote_messages}) | ||||||
for destination in remote_messages.keys(): | ||||||
# Enqueue a new federation transaction to send the new | ||||||
# device messages to each remote destination. | ||||||
self.federation.send_device_messages(destination) | ||||||
if self.federation_sender: | ||||||
for destination in remote_messages.keys(): | ||||||
# Enqueue a new federation transaction to send the new | ||||||
# device messages to each remote destination. | ||||||
self.federation_sender.send_device_messages(destination) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
this is probably lost?