Skip to content

Commit 86816cc

Browse files
authored
Merge pull request #427 from codecrafters-io/TropicolX-patch-71-1
Revise "WAIT with no commands #tu8" (stage 59)
2 parents c7a8c20 + af71a99 commit 86816cc

File tree

1 file changed

+24
-10
lines changed

1 file changed

+24
-10
lines changed
Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,25 @@
1-
**🚧 We're still working on instructions for this stage**. You can find notes on how the tester works below.
1+
In this stage, you’ll extend your `WAIT` implementation to handle the case where replicas are connected, but no commands have been sent.
22

3-
<!--
3+
### `WAIT` with connected replicas
44

5-
In this stage you will implement WAIT, when some replicas are connected to Master, but there have been NO commands propagated from master to replica. So offset is essentially 0. In this case, the Master can just return the count of `connected_slaves` asap. (The replicas will finish the sync handshake with Master, so they are actually connnected.)
6-
(The master will return the count of `connected_slaves` no matter how many replicas we pass in the WAIT command parameter. As the offset is 0, it knows all replicas are in sync.)
5+
In a previous stage, we handled the case where no replicas were connected, and the master could safely return `0`.
76

8-
-->
7+
Now, we’ll consider the case where some replicas are connected. Each replica will have completed the handshake and received the empty RDB file. But since no write commands have been sent yet, the replication offset is still `0`.
8+
9+
In this situation, the master will return the number of connected replicas, since it knows they are all in sync at offset `0`:
10+
11+
```bash
12+
$ redis-cli WAIT 3 500
13+
(integer) 7
14+
$ redis-cli WAIT 7 500
15+
(integer) 7
16+
$ redis-cli WAIT 9 500
17+
(integer) 7
18+
```
19+
20+
In the example above, `7` replicas are connected. No matter how many replicas the client asks for, the master will reply with the number of connected replicas (`7`).
21+
22+
For this stage, you can ignore both arguments (`<numreplicas> <timeout>`) and simply return the number of connected replicas.
923

1024
### Tests
1125

@@ -15,19 +29,19 @@ The tester will execute your program as a master like this:
1529
./your_program.sh
1630
```
1731

18-
It'll then start **multiple** replicas that connect to your server. Each will complete the handshake and expect to receive an empty RDB file.
32+
It will then start **multiple** replicas that connect to your server. Each will complete the handshake and expect to receive an empty RDB file.
1933

20-
It'll then connect to your master as a Redis client (not one of the replicas) and send commands like this:
34+
It will then connect to your master as a client and send commands like this:
2135

2236
```bash
2337
$ redis-cli WAIT 3 500 # (expecting 7 back)
2438
$ redis-cli WAIT 7 500 # (expecting 7 back)
2539
$ redis-cli WAIT 9 500 # (expecting 7 back)
2640
```
2741

28-
The response to each of these commands should be encoded as a RESP integer (i.e. `:7\r\n`).
42+
The response to each of these commands should be encoded as a RESP integer (i.e., `:7\r\n`).
2943

3044
### Notes
3145

32-
- Even if WAIT is called with a number lesser than the number of connected replicas, the master should return the count of connected replicas.
33-
- The number of replicas created in this stage will be random, so you can't hardcode `7` as the response like in the example above.
46+
- Even if `WAIT` is called with a number less than the number of connected replicas, the master should return the count of connected replicas.
47+
- The number of replicas created in this stage will be random, so you can't hardcode `7` as the response, like in the example above.

0 commit comments

Comments
 (0)