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

Allow PUT/GET of aliases during faster join #14292

Merged
merged 4 commits into from
Nov 1, 2022
Merged
Show file tree
Hide file tree
Changes from 2 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/14292.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Faster joins: do not block creation of or queries for room aliases during the resync.
25 changes: 18 additions & 7 deletions synapse/handlers/directory.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

import logging
import string
from typing import TYPE_CHECKING, Iterable, List, Optional
from typing import TYPE_CHECKING, Iterable, List, Optional, Set

from typing_extensions import Literal

Expand Down Expand Up @@ -85,9 +85,7 @@ async def _create_association(
# TODO(erikj): Add transactions.
# TODO(erikj): Check if there is a current association.
if not servers:
servers = await self._storage_controllers.state.get_current_hosts_in_room(
room_id
)
servers = await self._get_servers_known_to_be_in_room(room_id)

if not servers:
raise SynapseError(400, "Failed to get server list")
Expand All @@ -96,6 +94,21 @@ async def _create_association(
room_alias, room_id, servers, creator=creator
)

async def _get_servers_known_to_be_in_room(self, room_id: str) -> Set[str]:
if await self.store.is_partial_state_room(room_id):
# We don't have the full list of hosts in the room yet, but we do have
# some of them from the `/send_join` response. Use those to best-effort
# approximate the full list of servers in the room.
servers = set(await self.store.get_partial_state_servers_at_join(room_id))

# We are also in the room.
servers.add(self.server_name)
else:
servers = await self._storage_controllers.state.get_current_hosts_in_room(
room_id
)
return servers

Copy link
Contributor

Choose a reason for hiding this comment

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

We have an existing method, self._storage_controllers.state.get_current_hosts_in_room_or_partial_state_approximation that is more or less equivalent. Is there a reason we're avoiding it (apart from the awful name, which is my fault)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Only that I didn't know it existed. Will update, thanks.

async def create_association(
self,
requester: Requester,
Expand Down Expand Up @@ -290,9 +303,7 @@ async def get_association(self, room_alias: RoomAlias) -> JsonDict:
Codes.NOT_FOUND,
)

extra_servers = await self._storage_controllers.state.get_current_hosts_in_room(
room_id
)
extra_servers = await self._get_servers_known_to_be_in_room(room_id)
servers_set = set(extra_servers) | set(servers)

# If this server is in the list of servers, return it first.
Expand Down