Ensure we don't use unpersisted state group as prev group
This commit is contained in:
parent
c62c480dc6
commit
ea11ee09f3
|
@ -273,7 +273,8 @@ class StateHandler(object):
|
||||||
}
|
}
|
||||||
elif entry.prev_group:
|
elif entry.prev_group:
|
||||||
context.prev_group = 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:
|
else:
|
||||||
if entry.state_group is None:
|
if entry.state_group is None:
|
||||||
entry.state_group = self.store.get_next_state_group()
|
entry.state_group = self.store.get_next_state_group()
|
||||||
|
@ -364,12 +365,10 @@ class StateHandler(object):
|
||||||
if new_state_event_ids == frozenset(e_id for e_id in events):
|
if new_state_event_ids == frozenset(e_id for e_id in events):
|
||||||
state_group = sg
|
state_group = sg
|
||||||
break
|
break
|
||||||
if state_group is None:
|
|
||||||
# Worker instances don't have access to this method, but we want
|
# TODO: We want to create a state group for this set of events, to
|
||||||
# to set the state_group on the main instance to increase cache
|
# increase cache hits, but we need to make sure that it doesn't
|
||||||
# hits.
|
# end up as a prev_group without being added to the database
|
||||||
if hasattr(self.store, "get_next_state_group"):
|
|
||||||
state_group = self.store.get_next_state_group()
|
|
||||||
|
|
||||||
prev_group = None
|
prev_group = None
|
||||||
delta_ids = None
|
delta_ids = None
|
||||||
|
|
|
@ -223,6 +223,19 @@ class StateStore(SQLBaseStore):
|
||||||
# We persist as a delta if we can, while also ensuring the chain
|
# We persist as a delta if we can, while also ensuring the chain
|
||||||
# of deltas isn't tooo long, as otherwise read performance degrades.
|
# of deltas isn't tooo long, as otherwise read performance degrades.
|
||||||
if context.prev_group:
|
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(
|
potential_hops = self._count_state_group_hops_txn(
|
||||||
txn, context.prev_group
|
txn, context.prev_group
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in New Issue