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

Refactor state module to support multiple room versions #3673

Merged
merged 9 commits into from
Aug 22, 2018
2 changes: 1 addition & 1 deletion synapse/handlers/federation.py
Original file line number Diff line number Diff line change
Expand Up @@ -1814,7 +1814,7 @@ def do_auth(self, origin, event, context, auth_events):

room_version = yield self.store.get_room_version(event.room_id)

new_state = yield self.state_handler.resolve_events(
new_state = self.state_handler.resolve_events(
room_version,
[list(local_view.values()), list(remote_view.values())],
event
Expand Down
17 changes: 3 additions & 14 deletions synapse/state/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,14 +262,9 @@ def compute_event_context(self, event, old_state=None):
defer.returnValue(context)

logger.debug("calling resolve_state_groups from compute_event_context")
if event.type == EventTypes.Create:
Copy link
Member

Choose a reason for hiding this comment

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

I guess you could explicitly assert that event.type != EventTypes.Create here to give a slightly more comprehensible failure if/when it happens.

Copy link
Member Author

Choose a reason for hiding this comment

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

Creation events will happily reach that point

Copy link
Member

Choose a reason for hiding this comment

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

oh. why would we ever be doing state res on create events?

Copy link
Member Author

Choose a reason for hiding this comment

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

We don't, but we do call compute_event_context, and that gets nooped in resolve_state_groups_for_events since it has not prev events

room_version = event.content.get("room_version", RoomVersions.V1)
else:
room_version = None

entry = yield self.resolve_state_groups_for_events(
event.room_id, [e for e, _ in event.prev_events],
explicit_room_version=room_version,
)

prev_state_ids = entry.state
Expand Down Expand Up @@ -337,8 +332,7 @@ def compute_event_context(self, event, old_state=None):
defer.returnValue(context)

@defer.inlineCallbacks
def resolve_state_groups_for_events(self, room_id, event_ids,
explicit_room_version=None):
def resolve_state_groups_for_events(self, room_id, event_ids):
""" Given a list of event_ids this method fetches the state at each
event, resolves conflicts between them and returns them.

Expand Down Expand Up @@ -378,9 +372,7 @@ def resolve_state_groups_for_events(self, room_id, event_ids,
delta_ids=delta_ids,
))

room_version = explicit_room_version
if not room_version:
room_version = yield self.store.get_room_version(room_id)
room_version = yield self.store.get_room_version(room_id)

result = yield self._state_resolution_handler.resolve_state_groups(
room_id, room_version, state_groups_ids, None,
Expand All @@ -393,7 +385,6 @@ def _state_map_factory(self, ev_ids):
ev_ids, get_prev_content=False, check_redacted=False,
)

@defer.inlineCallbacks
def resolve_events(self, room_version, state_sets, event):
logger.info(
"Resolving state for %s with %d groups", event.room_id, len(state_sets)
Expand All @@ -409,8 +400,6 @@ def resolve_events(self, room_version, state_sets, event):
for ev in st
}

room_version = yield self.store.get_room_version(event.room_id)

with Measure(self.clock, "state._resolve_events"):
new_state = resolve_events_with_state_map(
room_version, state_set_ids, state_map,
Expand All @@ -420,7 +409,7 @@ def resolve_events(self, room_version, state_sets, event):
key: state_map[ev_id] for key, ev_id in iteritems(new_state)
}

defer.returnValue(new_state)
return new_state


class StateResolutionHandler(object):
Expand Down