summary refs log tree commit diff
path: root/synapse/replication/tcp/streams.py
diff options
context:
space:
mode:
authorRichard van der Hoff <richard@matrix.org>2019-03-25 16:48:56 +0000
committerRichard van der Hoff <richard@matrix.org>2019-03-25 16:48:56 +0000
commitce0ce1add3dde3da2ff366ee873174f5b5e70763 (patch)
tree8573d760dbaa68676e95e18698639537e75d75b2 /synapse/replication/tcp/streams.py
parentMerge branch 'develop' of github.com:matrix-org/synapse into matrix-org-hotfixes (diff)
parentFix ClientReplicationStreamProtocol.__str__ (#4929) (diff)
downloadsynapse-ce0ce1add3dde3da2ff366ee873174f5b5e70763.tar.xz
Merge branch 'develop' into matrix-org-hotfixes
Diffstat (limited to 'synapse/replication/tcp/streams.py')
-rw-r--r--synapse/replication/tcp/streams.py11
1 files changed, 8 insertions, 3 deletions
diff --git a/synapse/replication/tcp/streams.py b/synapse/replication/tcp/streams.py

index 728746bd12..a6e9d6709e 100644 --- a/synapse/replication/tcp/streams.py +++ b/synapse/replication/tcp/streams.py
@@ -23,7 +23,7 @@ Each stream is defined by the following information: current_token: The function that returns the current token for the stream update_function: The function that returns a list of updates between two tokens """ - +import itertools import logging from collections import namedtuple @@ -195,8 +195,8 @@ class Stream(object): limit=MAX_EVENTS_BEHIND + 1, ) - if len(rows) >= MAX_EVENTS_BEHIND: - raise Exception("stream %s has fallen behind" % (self.NAME)) + # never turn more than MAX_EVENTS_BEHIND + 1 into updates. + rows = itertools.islice(rows, MAX_EVENTS_BEHIND + 1) else: rows = yield self.update_function( from_token, current_token, @@ -204,6 +204,11 @@ class Stream(object): updates = [(row[0], self.ROW_TYPE(*row[1:])) for row in rows] + # check we didn't get more rows than the limit. + # doing it like this allows the update_function to be a generator. + if self._LIMITED and len(updates) >= MAX_EVENTS_BEHIND: + raise Exception("stream %s has fallen behind" % (self.NAME)) + defer.returnValue((updates, current_token)) def current_token(self):