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

Ensure we don't use unpersisted state group as prev group #2263

Merged
merged 1 commit into from
Jun 8, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions synapse/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,8 @@ def compute_event_context(self, event, old_state=None):
}
elif entry.prev_group:
context.prev_group = entry.prev_group
context.delta_ids = entry.delta_ids
context.delta_ids = dict(entry.delta_ids)
context.delta_ids[key] = event.event_id
else:
if entry.state_group is None:
entry.state_group = self.store.get_next_state_group()
Expand Down Expand Up @@ -364,12 +365,10 @@ def resolve_state_groups(self, room_id, event_ids):
if new_state_event_ids == frozenset(e_id for e_id in events):
state_group = sg
break
if state_group is None:
# Worker instances don't have access to this method, but we want
# to set the state_group on the main instance to increase cache
# hits.
if hasattr(self.store, "get_next_state_group"):
state_group = self.store.get_next_state_group()

# TODO: We want to create a state group for this set of events, to
# increase cache hits, but we need to make sure that it doesn't
# end up as a prev_group without being added to the database

prev_group = None
delta_ids = None
Expand Down
13 changes: 13 additions & 0 deletions synapse/storage/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,19 @@ def _store_mult_state_groups_txn(self, txn, events_and_contexts):
# We persist as a delta if we can, while also ensuring the chain
# of deltas isn't tooo long, as otherwise read performance degrades.
if context.prev_group:
is_in_db = self._simple_select_one_onecol_txn(
txn,
table="state_groups",
keyvalues={"id": context.prev_group},
retcol="id",
allow_none=True,
)
if not is_in_db:
raise Exception(
"Trying to persist state with unpersisted prev_group: %r"
% (context.prev_group,)
)

potential_hops = self._count_state_group_hops_txn(
txn, context.prev_group
)
Expand Down