Skip to content
This repository was archived by the owner on Apr 26, 2024. It is now read-only.

Commit 0680d76

Browse files
authored
Reduce replication traffic due to reflected cache stream POSITION (#16557)
1 parent c02406a commit 0680d76

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

changelog.d/16557.bugfix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
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`.

synapse/replication/tcp/resource.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
from synapse.replication.tcp.commands import PositionCommand
2828
from synapse.replication.tcp.protocol import ServerReplicationStreamProtocol
2929
from synapse.replication.tcp.streams import EventsStream
30-
from synapse.replication.tcp.streams._base import StreamRow, Token
30+
from synapse.replication.tcp.streams._base import CachesStream, StreamRow, Token
3131
from synapse.util.metrics import Measure
3232

3333
if TYPE_CHECKING:
@@ -204,6 +204,23 @@ async def _run_notifier_loop(self) -> None:
204204
# The token has advanced but there is no data to
205205
# send, so we send a `POSITION` to inform other
206206
# workers of the updated position.
207+
#
208+
# There are two reasons for this: 1) this instance
209+
# requested a stream ID but didn't use it, or 2)
210+
# this instance advanced its own stream position due
211+
# to receiving notifications about other instances
212+
# advancing their stream position.
213+
214+
# We skip sending `POSITION` for the `caches` stream
215+
# for the second case as a) it generates a lot of
216+
# traffic as every worker would echo each write, and
217+
# b) nothing cares if a given worker's caches stream
218+
# position lags.
219+
if stream.NAME == CachesStream.NAME:
220+
# If there haven't been any writes since the
221+
# `last_token` then we're in the second case.
222+
if stream.minimal_local_current_token() <= last_token:
223+
continue
207224

208225
# Note: `last_token` may not *actually* be the
209226
# last token we sent out in a RDATA or POSITION.

0 commit comments

Comments
 (0)