codecrafters-io / build-your-own-redis

Definition for the redis challenge.
https://app.codecrafters.io/courses/redis/overview
MIT License
108 stars 30 forks source link

Account for processing delay in replication / command processing stage #132

Closed rohitpaulk closed 4 months ago

rohitpaulk commented 5 months ago

Im having trouble with syncronization in replication command processing

I have one thread that is listening for commands (like the sets) from the master, and another that is listening for commands sent directly to my replica

Sometimes the get from the test comes before I can process the set from the master. What is the recommended approach to syncronize that?

image

You can see I get the first SET, then I get both GETs, and only then I get the rest of the SETs

I think we need to be either sleeping for a bit before running the GET commands, or we should retry them for a certain time period. The user's implementation seems correct from a practical perspective, it's expected that there might be a small delay between a command being propagated and it being applied on the client.

linear[bot] commented 5 months ago

CC-1041 Account for processing delay in replication / command processing stage

rohitpaulk commented 5 months ago

Thanks to @urielsalis for highlighting this!

rohitpaulk commented 5 months ago

Let's implement retries instead of an arbitrary sleep (that way tests are fast for most cases). If the GET command returns null the first time, let's sleep for 500ms and retry again, upto 5 times per key.

rohitpaulk commented 4 months ago

https://github.com/codecrafters-io/redis-tester/pull/92

ryan-gang commented 4 months ago

Fixed by: https://github.com/codecrafters-io/redis-tester/pull/92.