Skip to content

Commit c89fea3

Browse files
authored
Limit amount of replication we send (#17358)
Fixes up #17333, where we failed to actually send less data (the `DISTINCT` didn't work due to `stream_id` being different). We fix this by making it so that every device list outbound poke for a given user ID has the same stream ID. We can't change the query to only return e.g. max stream ID as the receivers look up the destinations to send to by doing `SELECT WHERE stream_id = ?`
1 parent 554a926 commit c89fea3

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

changelog.d/17358.misc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Handle device lists notifications for large accounts more efficiently in worker mode.

synapse/storage/databases/main/devices.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2131,19 +2131,18 @@ def _add_device_outbound_poke_to_stream_txn(
21312131
user_id: str,
21322132
device_id: str,
21332133
hosts: Collection[str],
2134-
stream_ids: List[int],
2134+
stream_id: int,
21352135
context: Optional[Dict[str, str]],
21362136
) -> None:
21372137
if self._device_list_federation_stream_cache:
21382138
for host in hosts:
21392139
txn.call_after(
21402140
self._device_list_federation_stream_cache.entity_has_changed,
21412141
host,
2142-
stream_ids[-1],
2142+
stream_id,
21432143
)
21442144

21452145
now = self._clock.time_msec()
2146-
stream_id_iterator = iter(stream_ids)
21472146

21482147
encoded_context = json_encoder.encode(context)
21492148
mark_sent = not self.hs.is_mine_id(user_id)
@@ -2152,7 +2151,7 @@ def _add_device_outbound_poke_to_stream_txn(
21522151
(
21532152
destination,
21542153
self._instance_name,
2155-
next(stream_id_iterator),
2154+
stream_id,
21562155
user_id,
21572156
device_id,
21582157
mark_sent,
@@ -2337,22 +2336,22 @@ async def add_device_list_outbound_pokes(
23372336
return
23382337

23392338
def add_device_list_outbound_pokes_txn(
2340-
txn: LoggingTransaction, stream_ids: List[int]
2339+
txn: LoggingTransaction, stream_id: int
23412340
) -> None:
23422341
self._add_device_outbound_poke_to_stream_txn(
23432342
txn,
23442343
user_id=user_id,
23452344
device_id=device_id,
23462345
hosts=hosts,
2347-
stream_ids=stream_ids,
2346+
stream_id=stream_id,
23482347
context=context,
23492348
)
23502349

2351-
async with self._device_list_id_gen.get_next_mult(len(hosts)) as stream_ids:
2350+
async with self._device_list_id_gen.get_next() as stream_id:
23522351
return await self.db_pool.runInteraction(
23532352
"add_device_list_outbound_pokes",
23542353
add_device_list_outbound_pokes_txn,
2355-
stream_ids,
2354+
stream_id,
23562355
)
23572356

23582357
async def add_remote_device_list_to_pending(

0 commit comments

Comments
 (0)