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

Skip attempt to get state at backwards-extremities #12173

Merged
merged 1 commit into from
Mar 9, 2022
Merged
Show file tree
Hide file tree
Changes from all 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/12173.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Avoid trying to calculate the state at outlier events.
60 changes: 3 additions & 57 deletions synapse/handlers/federation.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
from signedjson.sign import verify_signed_json
from unpaddedbase64 import decode_base64

from twisted.internet import defer

from synapse import event_auth
from synapse.api.constants import EventContentFields, EventTypes, Membership
from synapse.api.errors import (
Expand All @@ -45,11 +43,7 @@
from synapse.events.validator import EventValidator
from synapse.federation.federation_client import InvalidResponseError
from synapse.http.servlet import assert_params_in_dict
from synapse.logging.context import (
make_deferred_yieldable,
nested_logging_context,
preserve_fn,
)
from synapse.logging.context import nested_logging_context
from synapse.metrics.background_process_metrics import run_as_background_process
from synapse.replication.http.federation import (
ReplicationCleanRoomRestServlet,
Expand Down Expand Up @@ -355,56 +349,8 @@ async def try_backfill(domains: List[str]) -> bool:
if success:
return True

# Huh, well *those* domains didn't work out. Lets try some domains
# from the time.

tried_domains = set(likely_domains)
tried_domains.add(self.server_name)

event_ids = list(extremities.keys())

logger.debug("calling resolve_state_groups in _maybe_backfill")
resolve = preserve_fn(self.state_handler.resolve_state_groups_for_events)
states_list = await make_deferred_yieldable(
defer.gatherResults(
[resolve(room_id, [e]) for e in event_ids], consumeErrors=True
)
)

# A map from event_id to state map of event_ids.
state_ids: Dict[str, StateMap[str]] = dict(
zip(event_ids, [s.state for s in states_list])
)

state_map = await self.store.get_events(
[e_id for ids in state_ids.values() for e_id in ids.values()],
get_prev_content=False,
)

# A map from event_id to state map of events.
state_events: Dict[str, StateMap[EventBase]] = {
key: {
k: state_map[e_id]
for k, e_id in state_dict.items()
if e_id in state_map
}
for key, state_dict in state_ids.items()
}

for e_id in event_ids:
likely_extremeties_domains = get_domains_from_state(state_events[e_id])

success = await try_backfill(
[
dom
for dom, _ in likely_extremeties_domains
if dom not in tried_domains
]
)
if success:
return True

tried_domains.update(dom for dom, _ in likely_extremeties_domains)
# TODO: we could also try servers which were previously in the room, but
# are no longer.

return False

Expand Down