mirror of
https://git.anonymousland.org/anonymousland/synapse.git
synced 2025-05-02 11:16:07 -04:00
Add ability to wait for replication streams (#7542)
The idea here is that if an instance persists an event via the replication HTTP API it can return before we receive that event over replication, which can lead to races where code assumes that persisting an event immediately updates various caches (e.g. current state of the room). Most of Synapse doesn't hit such races, so we don't do the waiting automagically, instead we do so where necessary to avoid unnecessary delays. We may decide to change our minds here if it turns out there are a lot of subtle races going on. People probably want to look at this commit by commit.
This commit is contained in:
parent
06a02bc1ce
commit
1531b214fc
24 changed files with 304 additions and 112 deletions
|
@ -29,7 +29,7 @@ logger = logging.getLogger(__name__)
|
|||
|
||||
class ReplicationFederationSendEventsRestServlet(ReplicationEndpoint):
|
||||
"""Handles events newly received from federation, including persisting and
|
||||
notifying.
|
||||
notifying. Returns the maximum stream ID of the persisted events.
|
||||
|
||||
The API looks like:
|
||||
|
||||
|
@ -46,6 +46,13 @@ class ReplicationFederationSendEventsRestServlet(ReplicationEndpoint):
|
|||
"context": { .. serialized event context .. },
|
||||
}],
|
||||
"backfilled": false
|
||||
}
|
||||
|
||||
200 OK
|
||||
|
||||
{
|
||||
"max_stream_id": 32443,
|
||||
}
|
||||
"""
|
||||
|
||||
NAME = "fed_send_events"
|
||||
|
@ -115,11 +122,11 @@ class ReplicationFederationSendEventsRestServlet(ReplicationEndpoint):
|
|||
|
||||
logger.info("Got %d events from federation", len(event_and_contexts))
|
||||
|
||||
await self.federation_handler.persist_events_and_notify(
|
||||
max_stream_id = await self.federation_handler.persist_events_and_notify(
|
||||
event_and_contexts, backfilled
|
||||
)
|
||||
|
||||
return 200, {}
|
||||
return 200, {"max_stream_id": max_stream_id}
|
||||
|
||||
|
||||
class ReplicationFederationSendEduRestServlet(ReplicationEndpoint):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue