Skip to content

Commit

Permalink
Handle large chain calc better (#17291)
Browse files Browse the repository at this point in the history
We calculate the auth chain links outside of the main persist event
transaction to ensure that we do not block other event sending during
the calculation.
  • Loading branch information
erikjohnston committed Jun 19, 2024
1 parent afaf2d9 commit bdf82ef
Show file tree
Hide file tree
Showing 5 changed files with 230 additions and 82 deletions.
1 change: 1 addition & 0 deletions changelog.d/17291.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Do not block event sending/receiving while calulating large event auth chains.
12 changes: 12 additions & 0 deletions synapse/storage/controllers/persist_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -617,13 +617,25 @@ async def _persist_event_batch(
room_id, chunk
)

with Measure(self._clock, "calculate_chain_cover_index_for_events"):
# We now calculate chain ID/sequence numbers for any state events we're
# persisting. We ignore out of band memberships as we're not in the room
# and won't have their auth chain (we'll fix it up later if we join the
# room).
#
# See: docs/auth_chain_difference_algorithm.md
new_event_links = await self.persist_events_store.calculate_chain_cover_index_for_events(
room_id, [e for e, _ in chunk]
)

await self.persist_events_store._persist_events_and_state_updates(
room_id,
chunk,
state_delta_for_room=state_delta_for_room,
new_forward_extremities=new_forward_extremities,
use_negative_stream_ordering=backfilled,
inhibit_local_membership_updates=backfilled,
new_event_links=new_event_links,
)

return replaced_events
Expand Down
Loading

0 comments on commit bdf82ef

Please sign in to comment.