Skip to content

Commit 6229790

Browse files
authored
Merge pull request #418 from codecrafters-io/TropicolX-patch-63
Revise "Single-replica propagation #zn8" (stage 53)
2 parents ed95234 + 41cacf6 commit 6229790

File tree

1 file changed

+15
-29
lines changed

1 file changed

+15
-29
lines changed
Lines changed: 15 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,22 @@
11
In this stage, you'll add support for propagating write commands to a single replica as a master.
22

3-
### Command propagation
3+
### Command Propagation
44

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.
76

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.
118

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
1610

1711
Command propagation happens over the replication connection. This is the same connection that was used for the handshake.
1812

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.
2114

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.
2516

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.
2818

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.
3020

3121
### Tests
3222

@@ -36,28 +26,24 @@ The tester will execute your program like this:
3626
./your_program.sh --port <PORT>
3727
```
3828

39-
It'll then connect to your TCP server as a replica and execute the following commands:
40-
41-
1. `PING` (expecting `+PONG\r\n` back)
42-
2. `REPLCONF listening-port <PORT>` (expecting `+OK\r\n` back)
43-
3. `REPLCONF capa eof capa psync2` (expecting `+OK\r\n` back)
44-
4. `PSYNC ? -1` (expecting `+FULLRESYNC <REPL_ID> 0\r\n` back)
29+
It will then connect to your TCP server as a replica and complete the full handshake sequence covered in previous stages.
4530

4631
The tester will then wait for your server to send an RDB file.
4732

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).
4934

5035
```bash
5136
$ redis-cli SET foo 1
5237
$ redis-cli SET bar 2
5338
$ redis-cli SET baz 3
5439
```
5540

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).
5845

5946
### Notes
6047

6148
- 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

Comments
 (0)