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

Commit 9e82caa

Browse files
authored
Faster remote room joins: unblock tasks waiting for full room state when the un-partial-stating of that room is received over the replication stream. [rei:frrj/streams/unpsr] (#14474)
1 parent 66d47b4 commit 9e82caa

File tree

3 files changed

+77
-0
lines changed

3 files changed

+77
-0
lines changed

changelog.d/14474.misc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Faster remote room joins: stream the un-partial-stating of rooms over replication.

synapse/replication/tcp/client.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,14 @@
3636
TagAccountDataStream,
3737
ToDeviceStream,
3838
TypingStream,
39+
UnPartialStatedRoomStream,
3940
)
4041
from synapse.replication.tcp.streams.events import (
4142
EventsStream,
4243
EventsStreamEventRow,
4344
EventsStreamRow,
4445
)
46+
from synapse.replication.tcp.streams.partial_state import UnPartialStatedRoomStreamRow
4547
from synapse.types import PersistedEventPosition, ReadReceipt, StreamKeyType, UserID
4648
from synapse.util.async_helpers import Linearizer, timeout_deferred
4749
from synapse.util.metrics import Measure
@@ -117,6 +119,7 @@ def __init__(self, hs: "HomeServer"):
117119
self._streams = hs.get_replication_streams()
118120
self._instance_name = hs.get_instance_name()
119121
self._typing_handler = hs.get_typing_handler()
122+
self._state_storage_controller = hs.get_storage_controllers().state
120123

121124
self._notify_pushers = hs.config.worker.start_pushers
122125
self._pusher_pool = hs.get_pusherpool()
@@ -236,6 +239,14 @@ async def on_rdata(
236239
self.notifier.notify_user_joined_room(
237240
row.data.event_id, row.data.room_id
238241
)
242+
elif stream_name == UnPartialStatedRoomStream.NAME:
243+
for row in rows:
244+
assert isinstance(row, UnPartialStatedRoomStreamRow)
245+
246+
# Wake up any tasks waiting for the room to be un-partial-stated.
247+
self._state_storage_controller.notify_room_un_partial_stated(
248+
row.room_id
249+
)
239250

240251
await self._presence_handler.process_replication_rows(
241252
stream_name, instance_name, token, rows
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# Copyright 2022 The Matrix.org Foundation C.I.C.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
from twisted.internet.defer import ensureDeferred
15+
16+
from synapse.rest.client import room
17+
18+
from tests.replication._base import BaseMultiWorkerStreamTestCase
19+
20+
21+
class PartialStateStreamsTestCase(BaseMultiWorkerStreamTestCase):
22+
servlets = [room.register_servlets]
23+
hijack_auth = True
24+
user_id = "@bob:test"
25+
26+
def setUp(self):
27+
super().setUp()
28+
self.store = self.hs.get_datastores().main
29+
30+
def test_un_partial_stated_room_unblocks_over_replication(self) -> None:
31+
"""
32+
Tests that, when a room is un-partial-stated on another worker,
33+
pending calls to `await_full_state` get unblocked.
34+
"""
35+
36+
# Make a room.
37+
room_id = self.helper.create_room_as("@bob:test")
38+
# Mark the room as partial-stated.
39+
self.get_success(
40+
self.store.store_partial_state_room(room_id, ["serv1", "serv2"], 0, "serv1")
41+
)
42+
43+
worker = self.make_worker_hs("synapse.app.generic_worker")
44+
45+
# On the worker, attempt to get the current hosts in the room
46+
d = ensureDeferred(
47+
worker.get_storage_controllers().state.get_current_hosts_in_room(room_id)
48+
)
49+
50+
self.reactor.advance(0.1)
51+
52+
# This should block
53+
self.assertFalse(
54+
d.called, "get_current_hosts_in_room/await_full_state did not block"
55+
)
56+
57+
# On the master, clear the partial state flag.
58+
self.get_success(self.store.clear_partial_state_room(room_id))
59+
60+
self.reactor.advance(0.1)
61+
62+
# The worker should have unblocked
63+
self.assertTrue(
64+
d.called, "get_current_hosts_in_room/await_full_state did not unblock"
65+
)

0 commit comments

Comments
 (0)