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

Add concept of StatelessEventContext #2999

Closed
wants to merge 3 commits into from

Conversation

erikjohnston
Copy link
Member

The master process (usually) doesn't need the state at an event when it
has been created by a worker process, so let's not automatically load
the state in that case.

This is in preparation for using contexts that may or may not have the
current_state_ids set. This will allow us to avoid unnecessarily pulling
out state for an event on the master process when using workers.
The master process (usually) doesn't need the state at an event when it
has been created by a worker process, so let's not automatically load
the state in that case.
Copy link
Member

@richvdh richvdh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks plausible I guess. I'm surprised that there aren't going to be more places that get upset about these fields suddenly disappearing.

@@ -763,9 +764,18 @@ def is_inviter_member_event(e):
e.sender == event.sender
)

# We get the current state at the event. If we have a full
# EventContext, use it, otherwise we hit the DB.
if isinstance(context, EventContext):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isintance is a bit nasty. Can we do something like get_state_ids() which is defined to return None if they are unknown?

if ctx.state_group in state_groups_map:
continue

if isinstance(ctx, EventContext) and ctx.current_state_ids:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this largely used on the master? Will this do anything on a system with a split-out event creator worker? a comment here might be useful.

# state group from its context.
# Otherwise we need to pull the state group from the database.
missing_event_ids = [] # List of events we need to fetch groups for
state_groups_to_resolve = set() # State groups of new_latest_event_ids
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks like it's only a subset of the state groups of new_latest_event_ids?

missing_event_ids.append(event_id)

if not was_updated:
return

if missing_event_ids:
# Now pull out the state for any missing events from DB
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we now only get the state group ids here

@@ -504,61 +504,68 @@ def _get_new_state_after_events(self, room_id, events_context, new_latest_event_
defer.returnValue({})

# map from state_group to ((type, key) -> event_id) state map
state_groups = {}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm slightly failing to follow how the new code relates to the old in this file, but it generally looks sane, and a cleanup which may well be worth shipping independently of StatelessEventContext?

@erikjohnston
Copy link
Member Author

(Superseded by #3550)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants