looks like I have some problems with #EC3 as it doesn’t pass tests consistently. Most of the times it does but sometimes doesn’t. If I run multiple clients locally they get the results in the right order, but when running tests with codecrafters CLI it sometimes fails the tests.
You can find my code here. There, you will find methods Rpush and Blpop.
I am using concurrent queues to schedule tasks for when the clients request for data, so once the data is available the first requested client always receives the data first as per requirements of the #EC3 stage. I’m also using locks for locking the essential parts of the code as it’s a global static data objects that are being accessed at the same time.
The Waiters is a concurrent dictionary that facilitates queues per list key. So when a client requests some list key, the waiters queue will be created for the specific list key. Once the data is received with the specific key, the data is pushed to the first waiter from the queue, the rest of the waiters get empty list.
By default, I think there’s some issue in my code, but I can not reject the idea that there might be an issue on codecrafters side too!
I am trying to understand what would the impact be if I controlled the execution order of the HandleConnection(client) call. I think if I would set the connection handling in some certain order (e.g. queue) I would lose the async concept. I think it’s good that connections are handled in the async manner. What’s happenning here is that once the connection received, they are being handled in async manner. So yes, you can not know which task is going to finish first or last.
However, I control the execution order when I get the BLPOPcommand from the client, this is where the waiter queues are created and handled.
@inner After looking into this further, it seems the only reliable way to guarantee order is by using an event loop (which is how the official Redis does it).
We understand that’s too restrictive, so we plan to stop enforcing the assertion order. That said, it may take a little time before the change is rolled out.