summary refs log tree commit diff
path: root/synapse
diff options
context:
space:
mode:
authorErik Johnston <erik@matrix.org>2017-06-08 11:59:57 +0100
committerErik Johnston <erik@matrix.org>2017-06-08 11:59:57 +0100
commitea11ee09f31ce239120aceaf11b38df3cd94cf69 (patch)
treeaef7c462c7c5c49859e6b88607b6a40b9692f615 /synapse
parentMerge pull request #2259 from matrix-org/erikj/fix_state_woes (diff)
downloadsynapse-ea11ee09f31ce239120aceaf11b38df3cd94cf69.tar.xz
Ensure we don't use unpersisted state group as prev group
Diffstat (limited to '')
-rw-r--r--synapse/state.py13
-rw-r--r--synapse/storage/state.py13
2 files changed, 19 insertions, 7 deletions
diff --git a/synapse/state.py b/synapse/state.py
index a98145598f..576eb6b788 100644
--- a/synapse/state.py
+++ b/synapse/state.py
@@ -273,7 +273,8 @@ class StateHandler(object):
                 }
             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()
@@ -364,12 +365,10 @@ class StateHandler(object):
                 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
diff --git a/synapse/storage/state.py b/synapse/storage/state.py
index c3eecbe824..151223219d 100644
--- a/synapse/storage/state.py
+++ b/synapse/storage/state.py
@@ -223,6 +223,19 @@ class StateStore(SQLBaseStore):
             # 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
                 )