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

Commit 328b991

Browse files
author
David Robertson
committed
Read new column
1 parent 8f17eaa commit 328b991

File tree

4 files changed

+34
-11
lines changed

4 files changed

+34
-11
lines changed

synapse/handlers/device.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -937,7 +937,7 @@ async def incoming_device_list_update(
937937
# Check if we are partially joining any rooms. If so we need to store
938938
# all device list updates so that we can handle them correctly once we
939939
# know who is in the room.
940-
partial_rooms = await self.store.get_partial_state_rooms_and_servers()
940+
partial_rooms = await self.store.get_partial_state_room_resync_info()
941941
if partial_rooms:
942942
await self.store.add_remote_device_list_to_pending(
943943
user_id,

synapse/handlers/federation.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1603,13 +1603,13 @@ async def _resume_sync_partial_state_room(self) -> None:
16031603
"""Resumes resyncing of all partial-state rooms after a restart."""
16041604
assert not self.config.worker.worker_app
16051605

1606-
partial_state_rooms = await self.store.get_partial_state_rooms_and_servers()
1607-
for room_id, servers_in_room in partial_state_rooms.items():
1606+
partial_state_rooms = await self.store.get_partial_state_room_resync_info()
1607+
for room_id, resync_info in partial_state_rooms.items():
16081608
run_as_background_process(
16091609
desc="sync_partial_state_room",
16101610
func=self._sync_partial_state_room,
16111611
initial_destination=None,
1612-
other_destinations=servers_in_room,
1612+
other_destinations=resync_info.servers_in_room,
16131613
room_id=room_id,
16141614
)
16151615

synapse/storage/database.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1658,7 +1658,7 @@ async def simple_select_one_onecol(
16581658
table: string giving the table name
16591659
keyvalues: dict of column names and values to select the row with
16601660
retcol: string giving the name of the column to return
1661-
allow_none: If true, return None instead of failing if the SELECT
1661+
allow_none: If true, return None instead of raising StoreError if the SELECT
16621662
statement returns no rows
16631663
desc: description of the transaction, for logging and metrics
16641664
"""

synapse/storage/databases/main/room.py

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,12 @@ class RoomSortOrder(Enum):
9797
STATE_EVENTS = "state_events"
9898

9999

100+
@attr.s(slots=True, frozen=True, auto_attribs=True)
101+
class PartialStateResyncInfo:
102+
joined_via: Optional[str]
103+
servers_in_room: List[str] = attr.ib(factory=list)
104+
105+
100106
class RoomWorkerStore(CacheInvalidationWorkerStore):
101107
def __init__(
102108
self,
@@ -1160,17 +1166,29 @@ async def get_partial_state_servers_at_join(self, room_id: str) -> Sequence[str]
11601166
desc="get_partial_state_servers_at_join",
11611167
)
11621168

1163-
async def get_partial_state_rooms_and_servers(
1169+
async def get_partial_state_room_resync_info(
11641170
self,
1165-
) -> Mapping[str, Collection[str]]:
1166-
"""Get all rooms containing events with partial state, and the servers known
1167-
to be in the room.
1171+
) -> Mapping[str, PartialStateResyncInfo]:
1172+
"""Get all rooms containing events with partial state, and the information
1173+
needed to restart a "resync" of those rooms.
11681174
11691175
Returns:
11701176
A dictionary of rooms with partial state, with room IDs as keys and
11711177
lists of servers in rooms as values.
11721178
"""
1173-
room_servers: Dict[str, List[str]] = {}
1179+
room_servers: Dict[str, PartialStateResyncInfo] = {}
1180+
1181+
rows = await self.db_pool.simple_select_list(
1182+
table="partial_state_rooms",
1183+
keyvalues={},
1184+
retcols=("room_id", "joined_via"),
1185+
desc="get_server_which_served_partial_join",
1186+
)
1187+
1188+
for row in rows:
1189+
room_id = row["room_id"]
1190+
joined_via = row["joined_via"]
1191+
room_servers[room_id] = PartialStateResyncInfo(joined_via=joined_via)
11741192

11751193
rows = await self.db_pool.simple_select_list(
11761194
"partial_state_rooms_servers",
@@ -1182,7 +1200,12 @@ async def get_partial_state_rooms_and_servers(
11821200
for row in rows:
11831201
room_id = row["room_id"]
11841202
server_name = row["server_name"]
1185-
room_servers.setdefault(room_id, []).append(server_name)
1203+
# There is a foreign key constraint which enforces that every room_id in
1204+
# partial_state_rooms_servers appears in partial_state_rooms, so this lookup
1205+
# should always succeed.
1206+
# TODO(faster joins): To make this robust we should run both SELECTs in the
1207+
# same transaction.
1208+
room_servers[room_id].servers_in_room.append(server_name)
11861209

11871210
return room_servers
11881211

0 commit comments

Comments
 (0)