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

Add new columns tracking when we partial-joined #13892

Merged
merged 8 commits into from
Sep 27, 2022
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/13892.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Faster remote room joins: record _when_ we first partial-join to a room.
7 changes: 6 additions & 1 deletion synapse/handlers/federation.py
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,12 @@ async def do_invite_join(
# Mark the room as having partial state.
# The background process is responsible for unmarking this flag,
# even if the join fails.
await self.store.store_partial_state_room(room_id, ret.servers_in_room)
await self.store.store_partial_state_room(
room_id,
ret.servers_in_room,
ret.event.event_id,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we insert null here, and then update it with the join event ID in the persist event DB transaction? That way we might be able to keep the foreign key constraint?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It'd mean that we have to tell the persist event logic "you're persisting a partial join response" somehow. I can look at doing this but I'm not sure if it's worth the extra complexity in the persistence path. WDYT?

self.store.get_device_stream_token(),
)

try:
max_stream_id = (
Expand Down
23 changes: 21 additions & 2 deletions synapse/storage/databases/main/room.py
Original file line number Diff line number Diff line change
Expand Up @@ -1777,28 +1777,47 @@ async def store_partial_state_room(
self,
room_id: str,
servers: Collection[str],
join_event_id: str,
device_lists_stream_id: int,
) -> None:
"""Mark the given room as containing events with partial state
"""Mark the given room as containing events with partial state.
We also store additional data that describes _when_ we first partial-joined this
room, which helps us to keep other homeservers in sync when we finally fully
join this room.
Args:
room_id: the ID of the room
servers: other servers known to be in the room
join_event_id: the event ID of the join membership event returned in the
(partial) /send_join response.
device_lists_stream_id: the device_lists stream ID at the time when we first
joined the room.
"""
await self.db_pool.runInteraction(
"store_partial_state_room",
self._store_partial_state_room_txn,
room_id,
servers,
join_event_id,
device_lists_stream_id,
)

def _store_partial_state_room_txn(
self, txn: LoggingTransaction, room_id: str, servers: Collection[str]
self,
txn: LoggingTransaction,
room_id: str,
servers: Collection[str],
join_event_id: str,
device_lists_stream_id: int,
) -> None:
DatabasePool.simple_insert_txn(
txn,
table="partial_state_rooms",
values={
"room_id": room_id,
"device_lists_stream_id": device_lists_stream_id,
"join_event_id": join_event_id,
},
)
DatabasePool.simple_insert_many_txn(
Expand Down
23 changes: 23 additions & 0 deletions synapse/storage/schema/main/delta/73/04partial_join_details.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/* Copyright 2022 The Matrix.org Foundation C.I.C
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

-- To ensure we correctly notify other homeservers about device list changes from our
-- users after a partial join transitions to a full join, we need to know when we began
-- the partial join. For now it's sufficient to know the device_list stream_id at the
-- time of the partial join, and the join event created for us during a partial join.
--
-- Both columns are nullable without defaults, for backwards compatibility.
ALTER TABLE partial_state_rooms ADD COLUMN device_lists_stream_id BIGINT;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
ALTER TABLE partial_state_rooms ADD COLUMN device_lists_stream_id BIGINT;
ALTER TABLE partial_state_rooms ADD COLUMN device_lists_stream_id BIGINT NOT NULL;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the appropriate value to use for a default?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OH, because there might be existing entries. Hmm. I think 0 should be fine. It means we'll resend out all device list updates, but nothing should actually be using partial joins yet

ALTER TABLE partial_state_rooms ADD COLUMN join_event_id TEXT;