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
Copy file name to clipboardExpand all lines: stage_descriptions/replication-15-yd3.md
+27-32Lines changed: 27 additions & 32 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,35 +2,29 @@ In this stage, you'll extend your `REPLCONF GETACK` implementation to respond wi
2
2
3
3
### Offset tracking
4
4
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.
# 146 = 51 + 37 (for the second REPLCONF command) + 29 (for the first set command) + 29 (for the second set command)
58
52
```
59
53
54
+
Your replica must calculate and return the exact offset at each step.
55
+
60
56
### Notes
61
57
62
58
- 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.
65
60
- 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
0 commit comments