diff options
author | Eric Eastwood <erice@element.io> | 2021-10-18 16:40:01 -0500 |
---|---|---|
committer | Eric Eastwood <erice@element.io> | 2021-10-18 16:40:04 -0500 |
commit | 438e2226cca4ace0730faaca6b538384d6975dcc (patch) | |
tree | 0af37a4f1db753f9e61a8a3fb2fc6f2b0b21e2fe | |
parent | Scratch debugging why events appear out of order on remote homeservers (diff) | |
download | synapse-438e2226cca4ace0730faaca6b538384d6975dcc.tar.xz |
Use OrderedDict to gurantee order returned is the same as we were building the list
We are using a Dict over a list to gurantee we don't duplicate the event if it's already in there. I assume this is why we were using a Set before.
-rw-r--r-- | synapse/handlers/federation_event.py | 12 | ||||
-rw-r--r-- | synapse/storage/databases/main/event_federation.py | 8 |
2 files changed, 16 insertions, 4 deletions
diff --git a/synapse/handlers/federation_event.py b/synapse/handlers/federation_event.py index 0e455678aa..5e068cee09 100644 --- a/synapse/handlers/federation_event.py +++ b/synapse/handlers/federation_event.py @@ -416,6 +416,18 @@ class FederationEventHandler: events = await self._federation_client.backfill( dest, room_id, limit=limit, extremities=extremities ) + logger.info( + "from remote server: got backfill response events=%s", + [ + { + "event_id": ev.event_id, + "type": ev["type"], + "depth": ev["depth"], + "content": ev["content"].get("body", None), + } + for ev in events + ], + ) if not events: return diff --git a/synapse/storage/databases/main/event_federation.py b/synapse/storage/databases/main/event_federation.py index c857158648..b9c48eea56 100644 --- a/synapse/storage/databases/main/event_federation.py +++ b/synapse/storage/databases/main/event_federation.py @@ -14,7 +14,7 @@ import itertools import logging from queue import Empty, PriorityQueue -from typing import Collection, Dict, Iterable, List, Optional, Set, Tuple +from typing import Collection, Dict, Iterable, List, Optional, Set, OrderedDict, Tuple from prometheus_client import Counter, Gauge @@ -1007,7 +1007,7 @@ class EventFederationWorkerStore(EventsWorkerStore, SignatureWorkerStore, SQLBas def _get_backfill_events(self, txn, room_id, event_list, limit): logger.debug("_get_backfill_events: %s, %r, %s", room_id, event_list, limit) - event_results = set() + event_results = OrderedDict() # We want to make sure that we do a breadth-first, "depth" ordered # search. @@ -1120,7 +1120,7 @@ class EventFederationWorkerStore(EventsWorkerStore, SignatureWorkerStore, SQLBas event_id, ) - event_results.add(event_id) + event_results[event_id] = event_id # Try and find any potential historical batches of message history. # @@ -1181,7 +1181,7 @@ class EventFederationWorkerStore(EventsWorkerStore, SignatureWorkerStore, SQLBas if row[2] not in event_results: queue.put((-row[0], -row[1], row[2])) - return event_results + return event_results.values() async def get_missing_events(self, room_id, earliest_events, latest_events, limit): ids = await self.db_pool.runInteraction( |