You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In this stage, you'll add support for propagating write commands to a single replica as a master.
2
2
3
-
### Command propagation
3
+
### Command Propagation
4
4
5
-
After the replication handshake is complete and the master has sent the RDB file to the replica, the
6
-
master starts propagating commands to the replica.
5
+
After the replication handshake is complete and the master has sent the RDB file to the replica, the master starts propagating "write" commands to the replica.
7
6
8
-
When a master receives a "write" command from a client, it propagates the command to the replica. The
9
-
replica processes the command and updates its state. More on how this propagation works in the
10
-
"Replication connection" section below.
7
+
Write commands are commands that modify the master's dataset, such as `SET` and `DEL`. Commands like `PING`, `ECHO`, etc., are not considered "write" commands, so they aren't propagated.
11
8
12
-
Commands like `PING`, `ECHO` etc. are not considered "write" commands, so they aren't propagated. Commands like
13
-
`SET`, `DEL` etc. are considered "write" commands, so they are propagated.
14
-
15
-
### Replication connection
9
+
### The Propagation Process
16
10
17
11
Command propagation happens over the replication connection. This is the same connection that was used for the handshake.
18
12
19
-
Propagated commands are sent as RESP arrays. For example, if the master receives `SET foo bar` as a command from a client,
20
-
it'll send `*3\r\n$3\r\nSET\r\n$3\r\nfoo\r\n$3\r\nbar\r\n` to all connected replicas over their respective replication connections.
13
+
The propagated commands are sent as RESP arrays. For example, if the master receives `SET foo bar` as a command from a client, it'll send `*3\r\n$3\r\nSET\r\n$3\r\nfoo\r\n$3\r\nbar\r\n` to all connected replicas over their respective replication connections.
21
14
22
-
Replicas process commands received over the replication connection just like they would process commands received from a client,
23
-
but with one difference: Replicas don't send responses back to the master. They just process the command silently and update their
24
-
state.
15
+
Replicas process commands received over the connection just like they would process commands received from a client, but with one difference: they don't send responses back to the master. They just process the command silently and update their state.
25
16
26
-
Similarly, the master doesn't wait for a response from the replica when propagating commands. It just keeps sending commands as they
27
-
come in.
17
+
Similarly, the master doesn't wait for a response from the replica when propagating commands. It just sends the commands as they come in.
28
18
29
-
There is one exception to this "no response" rule, the `REPLCONF GETACK` command. We'll learn about this in later stages.
19
+
There is one exception to this "no response" rule: the `REPLCONF GETACK` command. We'll learn about this command in later stages.
30
20
31
21
### Tests
32
22
@@ -36,28 +26,24 @@ The tester will execute your program like this:
36
26
./your_program.sh --port <PORT>
37
27
```
38
28
39
-
It'll then connect to your TCP server as a replica and execute the following commands:
It will then connect to your TCP server as a replica and complete the full handshake sequence covered in previous stages.
45
30
46
31
The tester will then wait for your server to send an RDB file.
47
32
48
-
Once the RDB file is received, the tester will send series of write commands to your program (as a separate Redis client, not the replica).
33
+
Once the RDB file is received, the tester will send a series of write commands to your program (as a separate Redis client).
49
34
50
35
```bash
51
36
$ redis-cli SET foo 1
52
37
$ redis-cli SET bar 2
53
38
$ redis-cli SET baz 3
54
39
```
55
40
56
-
It'll then assert that these commands were propagated to the replica, in order. The tester will
57
-
expect to receive these commands (encoded as RESP arrays) on the replication connection (the one used for the handshake).
41
+
It will then assert that these commands were propagated to the replica in the correct order. The tester will expect to receive these commands:
42
+
43
+
- Encoded as RESP arrays.
44
+
- Sent on the same connection used for the handshake (replication connection).
58
45
59
46
### Notes
60
47
61
48
- Although replicas provide a `listening-port` during the handshake, it’s used only for [monitoring/logging purposes](https://github.com/redis/redis/blob/90178712f6eccf1e5b61daa677c5c103114bda3a/src/replication.c#L107-L130), not for propagation. Redis propagates commands over the same TCP connection that the replica initiated during the handshake.
62
-
- A true implementation would buffer the commands so that they can be sent to the replica after it loads the RDB file. For the
63
-
purposes of this challenge, you can assume that the replica is ready to receive commands immediately after receiving the RDB file.
49
+
- A true implementation would buffer the commands so that they can be sent to the replica after it loads the RDB file. For the purposes of this challenge, you can assume that the replica is ready to receive commands immediately after receiving the RDB file.
0 commit comments