Add new columns tracking when we partial-joined (#13892)

This commit is contained in:
David Robertson 2022-09-27 17:26:35 +01:00 committed by GitHub
parent 87fe9db467
commit f5aaa55e27
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 87 additions and 3 deletions

View file

@ -1777,28 +1777,46 @@ class RoomStore(RoomBackgroundUpdateStore, RoomWorkerStore):
self,
room_id: str,
servers: Collection[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.
We do not include a `join_event_id` here---we need to wait for the join event
to be persisted first.
Args:
room_id: the ID of the room
servers: other servers known to be in the room
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,
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],
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,
# To be updated later once the join event is persisted.
"join_event_id": None,
},
)
DatabasePool.simple_insert_many_txn(
@ -1809,6 +1827,36 @@ class RoomStore(RoomBackgroundUpdateStore, RoomWorkerStore):
)
self._invalidate_cache_and_stream(txn, self.is_partial_state_room, (room_id,))
async def write_partial_state_rooms_join_event_id(
self,
room_id: str,
join_event_id: str,
) -> None:
"""Record the join event which resulted from a partial join.
We do this separately to `store_partial_state_room` because we need to wait for
the join event to be persisted. Otherwise we violate a foreign key constraint.
"""
await self.db_pool.runInteraction(
"write_partial_state_rooms_join_event_id",
self._write_partial_state_rooms_join_event_id,
room_id,
join_event_id,
)
def _write_partial_state_rooms_join_event_id(
self,
txn: LoggingTransaction,
room_id: str,
join_event_id: str,
) -> None:
DatabasePool.simple_update_txn(
txn,
table="partial_state_rooms",
keyvalues={"room_id": room_id},
updatevalues={"join_event_id": join_event_id},
)
async def maybe_store_room_on_outlier_membership(
self, room_id: str, room_version: RoomVersion
) -> None: