Skip to content

Commit 88c9e23

Browse files
authored
Revise "ACKs with commands #yd3" (stage 57)
Removed unnecessary details section and streamlined explanations about offset tracking and command processing.
1 parent 101dd4f commit 88c9e23

File tree

1 file changed

+27
-32
lines changed

1 file changed

+27
-32
lines changed

stage_descriptions/replication-15-yd3.md

Lines changed: 27 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -2,35 +2,29 @@ In this stage, you'll extend your `REPLCONF GETACK` implementation to respond wi
22

33
### Offset tracking
44

5-
<details>
6-
<summary>Click to expand/collapse</summary>
7-
As we saw in previous stages, when a replica receives a command from the master, it processes it and updates its state. In addition to processing commands, the replica also keeps a running count of the number of bytes of commands it has processed.
8-
9-
This count is called the "offset". When a master sends a `REPLCONF GETACK` command to a replica, the replica is expected to respond with `REPLCONF ACK <offset>`. The returned `<offset>` should only include the number of bytes of commands processed **before** receiving the `REPLCONF GETACK` command.
10-
11-
As an example:
12-
13-
- Let's say a replica connects to a master and completes the handshake.
14-
- The master then sends a `REPLCONF GETACK *` command.
15-
- The replica should respond with `REPLCONF ACK 0`.
16-
- The returned offset is 0 since no commands have been processed yet (before receiving the `REPLCONF GETACK` command)
17-
- The master then sends `REPLCONF GETACK *` again.
18-
- The replica should respond with `REPLCONF ACK 37`.
19-
- The returned offset is 37 since the first `REPLCONF GETACK` command was processed, and it was 37 bytes long.
20-
- The RESP encoding for the `REPLCONF GETACK` command looks like this: `*3\r\n$8\r\nreplconf\r\n$6\r\ngetack\r\n$1\r\n*\r\n` (that's 37 bytes long)
21-
- The master then sends a `PING` command to the replica (masters do this periodically to notify replicas that the master is still alive).
22-
- The replica must silently process the `PING` command and update its offset. It should not send a response back to the master.
23-
- The master then sends `REPLCONF GETACK *` again (this is the third REPLCONF GETACK command received by the replica)
24-
- The replica should respond with `REPLCONF ACK 88`.
25-
- The returned offset is 88 (37 + 37 + 14)
26-
- 37 for the first `REPLCONF GETACK` command
27-
- 37 for the second `REPLCONF GETACK` command
28-
- 14 for the `PING` command
29-
- Note that the third `REPLCONF GETACK` command is not included in the offset, since the value should
30-
only include the number of bytes of commands processed **before** receiving the current `REPLCONF GETACK` command.
31-
- ... and so on
32-
33-
</details>
5+
As we saw in previous stages, when a replica receives a command from the master, it processes the command and updates its state accordingly. In addition to processing commands, the replica also keeps a running count of the number of bytes of commands it has processed.
6+
7+
This count is called the "offset". When a master sends a `REPLCONF GETACK` command to a replica, the replica is expected to respond with `REPLCONF ACK <offset>`. The returned `<offset>` should only include the number of bytes of commands processed **before** receiving the `REPLCONF GETACK` command.
8+
9+
As an example:
10+
11+
- Let's say a replica connects to a master and completes the handshake.
12+
- The master then sends a `REPLCONF GETACK *` command.
13+
- The replica should respond with `REPLCONF ACK 0`.
14+
- The returned offset is 0 since no commands have been processed yet (before receiving the `REPLCONF GETACK` command)
15+
- The master then sends `REPLCONF GETACK *` again.
16+
- The replica should respond with `REPLCONF ACK 37`.
17+
- The returned offset is 37 since the first `REPLCONF GETACK` command was processed, and it was 37 bytes long.
18+
- The RESP encoding for the `REPLCONF GETACK` command looks like this: `*3\r\n$8\r\nreplconf\r\n$6\r\ngetack\r\n$1\r\n*\r\n` (that's 37 bytes long)
19+
- The master then sends a `PING` command to the replica (masters do this periodically to notify replicas that the master is still alive).
20+
- The replica must silently process the `PING` command and update its offset. It should not send a response back to the master.
21+
- The master then sends `REPLCONF GETACK *` again (this is the third REPLCONF GETACK command received by the replica)
22+
- The replica should respond with `REPLCONF ACK 88`.
23+
- The returned offset is 88 (37 + 37 + 14)
24+
- 37 for the first `REPLCONF GETACK` command
25+
- 37 for the second `REPLCONF GETACK` command
26+
- 14 for the `PING` command
27+
- Note that the third `REPLCONF GETACK` command is not included in the offset, since the value should only include the number of bytes of commands processed **before** receiving the current `REPLCONF GETACK` command.
3428

3529
### Tests
3630

@@ -57,11 +51,12 @@ REPLCONF getack * # expecting REPLCONF ACK 146
5751
# 146 = 51 + 37 (for the second REPLCONF command) + 29 (for the first set command) + 29 (for the second set command)
5852
```
5953

54+
Your replica must calculate and return the exact offset at each step.
55+
6056
### Notes
6157

6258
- The offset should only include the number of bytes of commands processed **before** receiving the current `REPLCONF GETACK` command.
63-
- Although masters don't propagate `PING` commands when received from clients (since they aren't "write" commands),
64-
they may send `PING` commands to replicas to notify replicas that the master is still alive.
59+
- Although masters don't propagate `PING` commands when received from clients (since they aren't "write" commands), they may send `PING` commands to replicas to notify replicas that the master is still alive.
6560
- Replicas should update their offset to account for **all** commands propagated from the master, including `PING` and `REPLCONF` itself.
66-
- The response should be encoded as a [RESP Array](https://redis.io/docs/latest/develop/reference/protocol-spec/#arrays), like
61+
- The response should be encoded as a [RESP array](https://redis.io/docs/latest/develop/reference/protocol-spec/#arrays), like
6762
this: `*3\r\n$8\r\nREPLCONF\r\n$3\r\nACK\r\n$3\r\n154\r\n`.

0 commit comments

Comments
 (0)