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

Commit

Permalink
Write to the un-partial-stated events stream when the event is un-par…
Browse files Browse the repository at this point in the history
…tial-stated
  • Loading branch information
reivilibre committed Nov 24, 2022
1 parent 6768a6a commit 9bce4d8
Showing 1 changed file with 25 additions and 9 deletions.
34 changes: 25 additions & 9 deletions synapse/storage/databases/main/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ def __init__(
hs: "HomeServer",
):
super().__init__(database, db_conn, hs)
self._instance_name: str = hs.get_instance_name()

async def get_room_version(self, room_id: str) -> RoomVersion:
"""Get the room_version of a given room
Expand Down Expand Up @@ -404,18 +405,21 @@ async def update_state_for_partial_state_event(
context: EventContext,
) -> None:
"""Update the state group for a partial state event"""
await self.db_pool.runInteraction(
"update_state_for_partial_state_event",
self._update_state_for_partial_state_event_txn,
event,
context,
)
async with self._un_partial_stated_events_stream_id_gen.get_next() as un_partial_state_event_stream_id:
await self.db_pool.runInteraction(
"update_state_for_partial_state_event",
self._update_state_for_partial_state_event_txn,
event,
context,
un_partial_state_event_stream_id,
)

def _update_state_for_partial_state_event_txn(
self,
txn: LoggingTransaction,
event: EventBase,
context: EventContext,
un_partial_state_event_stream_id: int,
) -> None:
# we shouldn't have any outliers here
assert not event.internal_metadata.is_outlier()
Expand All @@ -436,7 +440,10 @@ def _update_state_for_partial_state_event_txn(

# the event may now be rejected where it was not before, or vice versa,
# in which case we need to update the rejected flags.
if bool(context.rejected) != (event.rejected_reason is not None):
rejection_status_changed = bool(context.rejected) != (
event.rejected_reason is not None
)
if rejection_status_changed:
self.mark_event_rejected_txn(txn, event.event_id, context.rejected)

self.db_pool.simple_delete_one_txn(
Expand All @@ -445,15 +452,24 @@ def _update_state_for_partial_state_event_txn(
keyvalues={"event_id": event.event_id},
)

# TODO(faster_joins): need to do something about workers here
# https://github.com/matrix-org/synapse/issues/12994
txn.call_after(self.is_partial_state_event.invalidate, (event.event_id,))
txn.call_after(
self._get_state_group_for_event.prefill,
(event.event_id,),
state_group,
)

self.db_pool.simple_insert_txn(
txn,
"un_partial_stated_event_stream",
{
"stream_id": un_partial_state_event_stream_id,
"instance_name": self._instance_name,
"event_id": event.event_id,
"rejection_status_changed": rejection_status_changed,
},
)


class MainStateBackgroundUpdateStore(RoomMemberWorkerStore):

Expand Down

0 comments on commit 9bce4d8

Please sign in to comment.