Skip to content

Commit babdadf

Browse files
authored
Merge pull request #425 from codecrafters-io/TropicolX-patch-70
Revise "WAIT with no replicas #my8" (stage 58)
2 parents 003dfb1 + 4be551e commit babdadf

File tree

1 file changed

+29
-13
lines changed

1 file changed

+29
-13
lines changed
Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,32 @@
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 begin implementing support for the `WAIT` command on the master.
22

3-
<!--
4-
In the next 3 stages, you will implement the WAIT command on your master.
5-
The WAIT command is used to find out how many replicas a write command was propagated to, with the replica ACKing it back. This way we can know how durable the write was. As we haven't implemented periodic ACKs from the replica, in this stage, for WAIT, the master has to send a GETACK to the replica, if the replica replies back with the proper offset, before the WAIT expires, the master can count that replica's write to be a success.
3+
### The `WAIT` command
64

7-
In this stage you will implement WAIT, when exactly 0 replicas are connected to Master. The Master can just return 0 asap. This way we will gently dive into the implementation.
8-
-->
5+
The `WAIT` command is used to check how many replicas have acknowledged a write command. This allows a client to measure the durability of a write command before considering it successful.
6+
7+
The command format is:
8+
9+
```bash
10+
WAIT <numreplicas> <timeout>
11+
```
12+
13+
Here's what each argument means:
14+
15+
- `<numreplicas>`: The minimum number of replicas that must acknowledge the write command.
16+
- `<timeout>`: The maximum time (in milliseconds) the client is willing to wait.
17+
18+
For example:
19+
20+
```bash
21+
$ redis-cli WAIT 3 5000
22+
(integer) 2
23+
```
24+
25+
Here, the client is asking the master to wait for `3` replicas (with a maximum timeout of 5000 ms). After the timeout passes, the master has only `2` replicas connected, so it immediately replies with `2` as a [RESP integer](https://redis.io/docs/latest/develop/reference/protocol-spec/#integers).
26+
27+
For now, we’ll handle the simplest case: when the client needs `0` replicas and the master also has no replicas connected. In this case, `WAIT` should immediately return `0`.
28+
29+
We'll get to tracking the number of replicas and responding accordingly in later stages.
930

1031
### Tests
1132

@@ -15,15 +36,10 @@ The tester will execute your program like this:
1536
./your_program.sh
1637
```
1738

18-
A redis client will then connect to your master and send `WAIT 0 60000`:
39+
It will then connect to your master and send:
1940

2041
```bash
2142
$ redis-cli WAIT 0 60000
2243
```
2344

24-
It'll expect to receive `0` back immediately, since no replicas are connected.
25-
26-
### Notes
27-
28-
- You can hardcode `0` as the response for the WAIT command in this stage. We'll get to tracking the number of replicas and responding
29-
accordingly in the next stages.
45+
The tester will expect to receive `0` immediately (as a RESP integer), since no replicas are connected.

0 commit comments

Comments
 (0)