Skip to content

Commit ed95234

Browse files
authored
Merge pull request #417 from codecrafters-io/TropicolX-patch-62
Revise "Empty RDB transfer #cf8" (stage 52)
2 parents 724b903 + 592faf1 commit ed95234

File tree

1 file changed

+19
-20
lines changed

1 file changed

+19
-20
lines changed
Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,27 @@
1-
In this stage, you'll add support for sending an empty RDB file as a master. This is part of the "full resynchronization" process.
1+
In this stage, you'll add support for sending an empty RDB file as a master.
22

3-
### Full resynchronization
3+
### Full Resynchronization
44

5-
When a replica connects to a master for the first time, it sends a `PSYNC ? -1` command. This is the replica's way of
6-
telling the master that it doesn't have any data yet, and needs to be fully resynchronized.
5+
When a replica connects to a master for the first time, it sends a `PSYNC ? -1` command. This is the replica's way of telling the master that it doesn't have any data yet and needs to be fully resynchronized.
76

8-
The master acknowledges this by sending a `FULLRESYNC` response to the replica.
7+
The master responds in two steps:
98

10-
After sending the `FULLRESYNC` response, the master will then send a RDB file of its current state to the replica. The replica is expected to load the file into memory, replacing its current state.
9+
- It acknowledges with a `FULLRESYNC` response (Handled in a previous stage)
10+
- It sends a snapshot of its current state as an [RDB file](https://rdb.fnordig.de/file_format.html).
1111

12-
For the purposes of this challenge, you don't have to actually construct an RDB file. We'll assume that the master's database is always empty,
13-
and just hardcode an empty RDB file to send to the replica.
12+
The replica is expected to load the file into memory and replace its current state with the master's data.
1413

15-
You can find the hex representation of an empty RDB file [here](https://github.com/codecrafters-io/redis-tester/blob/main/internal/assets/empty_rdb_hex.md).
14+
For this challenge, you don’t need to build an RDB file yourself. Instead, you can hardcode an empty RDB file, since we’ll assume the master’s database is always empty.
1615

17-
The tester will accept any valid RDB file that is empty, you don't need to send the exact file above.
16+
You can find the hex and base64 representation of an empty RDB file [here](https://github.com/codecrafters-io/redis-tester/blob/main/internal/assets/empty_rdb_hex.md). You need to decode these into binary contents before sending them to the replica.
1817

1918
The file is sent using the following format:
2019

2120
```
2221
$<length_of_file>\r\n<binary_contents_of_file>
2322
```
2423

25-
(This is similar to how [Bulk Strings](https://redis.io/topics/protocol#resp-bulk-strings) are encoded, but without the trailing `\r\n`)
24+
This is similar to how [bulk strings](https://redis.io/topics/protocol#resp-bulk-strings) are encoded, but without the trailing `\r\n`.
2625

2726
### Tests
2827

@@ -32,22 +31,22 @@ The tester will execute your program like this:
3231
./your_program.sh --port <PORT>
3332
```
3433

35-
It'll then connect to your TCP server as a replica and execute the following commands:
34+
It will then connect to your TCP server as a replica and execute the following commands:
3635

37-
1. `PING` (expecting `+PONG\r\n` back)
38-
2. `REPLCONF listening-port <PORT>` (expecting `+OK\r\n` back)
39-
3. `REPLCONF capa eof capa psync2` (expecting `+OK\r\n` back)
40-
4. `PSYNC ? -1` (expecting `+FULLRESYNC <REPL_ID> 0\r\n` back)
36+
1. `PING` - expecting `+PONG\r\n`
37+
2. `REPLCONF listening-port <PORT>` - expecting `+OK\r\n`
38+
3. `REPLCONF capa eof capa psync2` - expecting `+OK\r\n`
39+
4. `PSYNC ? -1` - expecting `+FULLRESYNC <REPL_ID> 0\r\n`
4140

42-
After receiving a response to the last command, the tester will expect to receive an empty RDB file from your server.
41+
After the last response, the tester will expect to receive an empty RDB file from your server.
42+
43+
The tester will accept any valid RDB file that is empty.
4344

4445
### Notes
4546

46-
- The [RDB file link](https://github.com/codecrafters-io/redis-tester/blob/main/internal/assets/empty_rdb_hex.md) contains hex & base64 representations
47-
of the file. You need to decode these into binary contents before sending it to the replica.
4847
- The RDB file should be sent like this: `$<length>\r\n<contents>`
4948
- `<length>` is the length of the file in bytes
5049
- `<contents>` is the binary contents of the file
51-
- Note that this is NOT a RESP bulk string, it doesn't contain a `\r\n` at the end
50+
- Note that this is NOT a RESP bulk string and doesn't contain a `\r\n` at the end.
5251
- If you want to learn more about the RDB file format, read [this blog post](https://rdb.fnordig.de/file_format.html). This challenge
5352
has a separate extension dedicated to reading RDB files.

0 commit comments

Comments
 (0)