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

Commit 9228ae6

Browse files
author
Mathieu Velten
authored
Add some clarification to the doc/comments regarding TCP replication (#15354)
1 parent 9d641d8 commit 9228ae6

File tree

4 files changed

+9
-36
lines changed

4 files changed

+9
-36
lines changed

changelog.d/15354.misc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add some clarification to the doc/comments regarding TCP replication.

docs/tcp_replication.md

+5-4
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ position of all streams. The server then periodically sends `RDATA` commands
2525
which have the format `RDATA <stream_name> <instance_name> <token> <row>`, where
2626
the format of `<row>` is defined by the individual streams. The
2727
`<instance_name>` is the name of the Synapse process that generated the data
28-
(usually "master").
28+
(usually "master"). We expect an RDATA for every row in the DB.
2929

3030
Error reporting happens by either the client or server sending an ERROR
3131
command, and usually the connection will be closed.
@@ -107,7 +107,7 @@ reconnect, following the steps above.
107107
If the server sends messages faster than the client can consume them the
108108
server will first buffer a (fairly large) number of commands and then
109109
disconnect the client. This ensures that we don't queue up an unbounded
110-
number of commands in memory and gives us a potential oppurtunity to
110+
number of commands in memory and gives us a potential opportunity to
111111
squawk loudly. When/if the client recovers it can reconnect to the
112112
server and ask for missed messages.
113113

@@ -122,7 +122,7 @@ since these include tokens which can be used to restart the stream on
122122
connection errors.
123123

124124
The client should keep track of the token in the last RDATA command
125-
received for each stream so that on reconneciton it can start streaming
125+
received for each stream so that on reconnection it can start streaming
126126
from the correct place. Note: not all RDATA have valid tokens due to
127127
batching. See `RdataCommand` for more details.
128128

@@ -188,7 +188,8 @@ client (C):
188188
Two positions are included, the "new" position and the last position sent respectively.
189189
This allows servers to tell instances that the positions have advanced but no
190190
data has been written, without clients needlessly checking to see if they
191-
have missed any updates.
191+
have missed any updates. Instances will only fetch stuff if there is a gap between
192+
their current position and the given last position.
192193

193194
#### ERROR (S, C)
194195

synapse/replication/tcp/protocol.py

+1-30
Original file line numberDiff line numberDiff line change
@@ -14,36 +14,7 @@
1414
"""This module contains the implementation of both the client and server
1515
protocols.
1616
17-
The basic structure of the protocol is line based, where the initial word of
18-
each line specifies the command. The rest of the line is parsed based on the
19-
command. For example, the `RDATA` command is defined as::
20-
21-
RDATA <stream_name> <token> <row_json>
22-
23-
(Note that `<row_json>` may contains spaces, but cannot contain newlines.)
24-
25-
Blank lines are ignored.
26-
27-
# Example
28-
29-
An example iteraction is shown below. Each line is prefixed with '>' or '<' to
30-
indicate which side is sending, these are *not* included on the wire::
31-
32-
* connection established *
33-
> SERVER localhost:8823
34-
> PING 1490197665618
35-
< NAME synapse.app.appservice
36-
< PING 1490197665618
37-
< REPLICATE
38-
> POSITION events 1
39-
> POSITION backfill 1
40-
> POSITION caches 1
41-
> RDATA caches 2 ["get_user_by_id",["@01register-user:localhost:8823"],1490197670513]
42-
> RDATA events 14 ["ev", ["$149019767112vOHxz:localhost:8823",
43-
"!AFDCvgApUmpdfVjIXm:localhost:8823","m.room.guest_access","",null]]
44-
< PING 1490197675618
45-
> ERROR server stopping
46-
* connection closed by server *
17+
An explanation of this protocol is available in docs/tcp_replication.md
4718
"""
4819
import fcntl
4920
import logging

synapse/replication/tcp/streams/_base.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,8 @@ async def get_updates(self) -> StreamUpdateResult:
152152
Returns:
153153
A triplet `(updates, new_last_token, limited)`, where `updates` is
154154
a list of `(token, row)` entries, `new_last_token` is the new
155-
position in stream, and `limited` is whether there are more updates
156-
to fetch.
155+
position in stream (ie the highest token returned in the updates),
156+
and `limited` is whether there are more updates to fetch.
157157
"""
158158
current_token = self.current_token(self.local_instance_name)
159159
updates, current_token, limited = await self.get_updates_since(

0 commit comments

Comments
 (0)