summary refs log tree commit diff
path: root/synapse/storage/state.py
diff options
context:
space:
mode:
authorMark Haines <mark.haines@matrix.org>2016-03-30 15:58:20 +0100
committerMark Haines <mark.haines@matrix.org>2016-03-30 16:01:58 +0100
commit31a9eceda5cf00b0482baf1c8bf1e138c823f621 (patch)
treeb41ec3d2ee01f6cc896418b523a2a9510ecd30bd /synapse/storage/state.py
parentMerge pull request #674 from matrix-org/markjh/replicate_state (diff)
downloadsynapse-31a9eceda5cf00b0482baf1c8bf1e138c823f621.tar.xz
Add a replication stream for state groups
Diffstat (limited to 'synapse/storage/state.py')
-rw-r--r--synapse/storage/state.py30
1 files changed, 30 insertions, 0 deletions
diff --git a/synapse/storage/state.py b/synapse/storage/state.py
index 30d1060ecd..7fc9a4f264 100644
--- a/synapse/storage/state.py
+++ b/synapse/storage/state.py
@@ -429,3 +429,33 @@ class StateStore(SQLBaseStore):
             }
 
         defer.returnValue(results)
+
+    def get_all_new_state_groups(self, last_id, current_id, limit):
+        def get_all_new_state_groups_txn(txn):
+            sql = (
+                "SELECT id, room_id, event_id FROM state_groups"
+                " WHERE ? < id AND id <= ? ORDER BY id LIMIT ?"
+            )
+            txn.execute(sql, (last_id, current_id, limit))
+            groups = txn.fetchall()
+
+            if not groups:
+                return ([], [])
+
+            lower_bound = groups[0][0]
+            upper_bound = groups[-1][0]
+            sql = (
+                "SELECT state_group, type, state_key, event_id"
+                " FROM state_groups_state"
+                " WHERE ? <= state_group AND state_group <= ?"
+            )
+
+            txn.execute(sql, (lower_bound, upper_bound))
+            state_group_state = txn.fetchall()
+            return (groups, state_group_state)
+        return self.runInteraction(
+            "get_all_new_state_groups", get_all_new_state_groups_txn
+        )
+
+    def get_state_stream_token(self):
+        return self._state_groups_id_gen.get_max_token()