summary refs log tree commit diff
diff options
context:
space:
mode:
authorErik Johnston <erikj@matrix.org>2023-10-30 14:47:57 +0000
committerGitHub <noreply@github.com>2023-10-30 14:47:57 +0000
commit408c13801a244a89d23f9c8e8ccce1b3d049abb6 (patch)
tree18dce9160b0fe2c516db6dd3afb155ca4a5f0513
parentClaim fallback keys in bulk (#16570) (diff)
downloadsynapse-408c13801a244a89d23f9c8e8ccce1b3d049abb6.tar.xz
Add fast path for replication events stream fetch (#16580)
We can bail early if the from token is greater than or equal to the
current token.
-rw-r--r--changelog.d/16580.bugfix1
-rw-r--r--synapse/replication/tcp/streams/events.py6
2 files changed, 7 insertions, 0 deletions
diff --git a/changelog.d/16580.bugfix b/changelog.d/16580.bugfix
new file mode 100644
index 0000000000..4f4a0380cd
--- /dev/null
+++ b/changelog.d/16580.bugfix
@@ -0,0 +1 @@
+Fix a long-standing, exceedingly rare edge case where the first event persisted by a new event persister worker might not be sent down `/sync`.
diff --git a/synapse/replication/tcp/streams/events.py b/synapse/replication/tcp/streams/events.py
index 38823113d8..57138fea80 100644
--- a/synapse/replication/tcp/streams/events.py
+++ b/synapse/replication/tcp/streams/events.py
@@ -157,6 +157,12 @@ class EventsStream(_StreamFromIdGen):
         current_token: Token,
         target_row_count: int,
     ) -> StreamUpdateResult:
+        # The events stream cannot be "reset", so its safe to return early if
+        # the from token is larger than the current token (the DB query will
+        # trivially return 0 rows anyway).
+        if from_token >= current_token:
+            return [], current_token, False
+
         # the events stream merges together three separate sources:
         #  * new events
         #  * current_state changes