From de0002b1e50c2718e521a3244befe598b66539f5 Mon Sep 17 00:00:00 2001 From: David Robertson Date: Fri, 23 Sep 2022 18:45:54 +0100 Subject: [PATCH] Store when we partial-joined --- synapse/handlers/federation.py | 7 ++++++- synapse/storage/databases/main/room.py | 23 +++++++++++++++++++++-- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/synapse/handlers/federation.py b/synapse/handlers/federation.py index 583d5ecd7749..2d0f8b7ef7ed 100644 --- a/synapse/handlers/federation.py +++ b/synapse/handlers/federation.py @@ -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, + self.store.get_device_stream_token(), + ) try: max_stream_id = ( diff --git a/synapse/storage/databases/main/room.py b/synapse/storage/databases/main/room.py index 5dd116d76653..b25947420459 100644 --- a/synapse/storage/databases/main/room.py +++ b/synapse/storage/databases/main/room.py @@ -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(