build-your-own-redis icon indicating copy to clipboard operation
build-your-own-redis copied to clipboard

WAIT with multiple commands: missing replies for GETACK

Open marxin opened this issue 1 year ago • 1 comments

First of all, thank you for the very nice Replication extension for the Redis example.

I'm close to finishing the last WAIT command exercise, however, I face the following problem:

remote: [replication-18] client: $ redis-cli SET foo 123
remote: [your_program] 2024-05-18T11:28:58.737729Z  INFO connection{addr=127.0.0.1:35618}:replication: redis_starter_rust::server: sending replication: Set { key: "foo", value: "123", expiration: None }
remote: [your_program] 2024-05-18T11:28:58.737771Z  INFO connection{addr=127.0.0.1:35630}:replication: redis_starter_rust::server: sending replication: Set { key: "foo", value: "123", expiration: None }
remote: [your_program] 2024-05-18T11:28:58.737783Z  INFO connection{addr=127.0.0.1:35608}:replication: redis_starter_rust::server: sending replication: Set { key: "foo", value: "123", expiration: None }
remote: [your_program] 2024-05-18T11:28:58.737723Z  INFO connection{addr=127.0.0.1:35640}:replicationg_manager: redis_starter_rust::server: replicated: Set { key: "foo", value: "123", expiration: None }, counter: 31
remote: [your_program] 2024-05-18T11:28:58.738995Z  INFO connection{addr=127.0.0.1:35594}:replication: redis_starter_rust::server: sending replication: Set { key: "foo", value: "123", expiration: None }
remote: [replication-18] Received "OK"
remote: [replication-18] client: $ redis-cli WAIT 1 500
remote: [replication-18] Testing Replica : 1
remote: [replication-18] replica-1: Expecting "SET foo 123" to be propagated
remote: [replication-18] Received ["SET", "foo", "123"]
remote: [replication-18] replica-1: Expecting "REPLCONF GETACK *" from Master
remote: [your_program] 2024-05-18T11:28:58.750833Z  INFO connection{addr=127.0.0.1:35640}: redis_starter_rust::server: current replication counter: 31
remote: [your_program] 2024-05-18T11:28:58.750870Z  INFO connection{addr=127.0.0.1:35608}:replication: redis_starter_rust::server: sending replication: ReplConf { arg: "GETACK", value: "*" }
remote: [your_program] 2024-05-18T11:28:58.750903Z  INFO connection{addr=127.0.0.1:35594}:replication: redis_starter_rust::server: sending replication: ReplConf { arg: "GETACK", value: "*" }
remote: [your_program] 2024-05-18T11:28:58.750946Z  INFO connection{addr=127.0.0.1:35630}:replication: redis_starter_rust::server: sending replication: ReplConf { arg: "GETACK", value: "*" }
remote: [your_program] 2024-05-18T11:28:58.750962Z  INFO connection{addr=127.0.0.1:35640}:replicationg_manager: redis_starter_rust::server: replicated: ReplConf { arg: "GETACK", value: "*" }, counter: 68
remote: [your_program] 2024-05-18T11:28:58.750972Z  INFO connection{addr=127.0.0.1:35618}:replication: redis_starter_rust::server: sending replication: ReplConf { arg: "GETACK", value: "*" }
remote: [replication-18] Received ["REPLCONF", "GETACK", "*"]
remote: [replication-18] replica-1: $ redis-cli REPLCONF ACK 31
remote: [replication-18] Testing Replica : 2
remote: [replication-18] replica-2: Expecting "SET foo 123" to be propagated
remote: [replication-18] Received ["SET", "foo", "123"]
remote: [replication-18] replica-2: Expecting "REPLCONF GETACK *" from Master
remote: [your_program] 2024-05-18T11:28:58.763419Z  INFO connection{addr=127.0.0.1:35594}:replication: redis_starter_rust::server: replconf reply received: ReplConf { arg: "ACK", value: "31" }
remote: [replication-18] Received ["REPLCONF", "GETACK", "*"]
remote: [replication-18] Testing Replica : 3
remote: [replication-18] replica-3: Expecting "SET foo 123" to be propagated
remote: [replication-18] Received ["SET", "foo", "123"]
remote: [replication-18] replica-3: Expecting "REPLCONF GETACK *" from Master
remote: [replication-18] Received ["REPLCONF", "GETACK", "*"]
remote: [replication-18] Testing Replica : 4
remote: [replication-18] replica-4: Expecting "SET foo 123" to be propagated
remote: [replication-18] Received ["SET", "foo", "123"]
remote: [replication-18] replica-4: Expecting "REPLCONF GETACK *" from Master
remote: [replication-18] Received ["REPLCONF", "GETACK", "*"]
remote: [replication-18] Passed first WAIT test.
remote: [replication-18] client: $ redis-cli SET baz 789
remote: [your_program] 2024-05-18T11:28:58.770262Z  INFO connection{addr=127.0.0.1:35640}:replicationg_manager: redis_starter_rust::server: replicated: Set { key: "baz", value: "789", expiration: None }, counter: 99
remote: [your_program] 2024-05-18T11:28:58.770298Z  INFO connection{addr=127.0.0.1:35594}:replication: redis_starter_rust::server: sending replication: Set { key: "baz", value: "789", expiration: None }
remote: [replication-18] Received "OK"
remote: [replication-18] client: $ redis-cli WAIT 3 2000
remote: [replication-18] Testing Replica : 1
remote: [replication-18] replica-1: Expecting "SET baz 789" to be propagated
remote: [replication-18] Received ["SET", "baz", "789"]
remote: [replication-18] replica-1: Expecting "REPLCONF GETACK *" from Master
remote: [your_program] 2024-05-18T11:28:58.771828Z  INFO connection{addr=127.0.0.1:35640}: redis_starter_rust::server: current replication counter: 99
remote: [your_program] 2024-05-18T11:28:58.771840Z  INFO connection{addr=127.0.0.1:35640}:replicationg_manager: redis_starter_rust::server: replicated: ReplConf { arg: "GETACK", value: "*" }, counter: 136
remote: [your_program] 2024-05-18T11:28:58.771850Z  INFO connection{addr=127.0.0.1:35594}:replication: redis_starter_rust::server: sending replication: ReplConf { arg: "GETACK", value: "*" }
remote: [replication-18] Received ["REPLCONF", "GETACK", "*"]
remote: [replication-18] replica-1: $ redis-cli REPLCONF ACK 99
remote: [replication-18] Testing Replica : 2
remote: [replication-18] replica-2: Expecting "SET baz 789" to be propagated
remote: [your_program] 2024-05-18T11:28:58.819304Z  INFO connection{addr=127.0.0.1:35594}:replication: redis_starter_rust::server: replconf reply received: ReplConf { arg: "ACK", value: "99" }
remote: [replication-18] Received: "" (no content received)
remote: [replication-18]            ^ error
remote: [replication-18] Error: Expected start of a new RESP2 value (either +, -, :, $ or *)
remote: [replication-18] Test failed (try setting 'debug: true' in your codecrafters.yml to see more details)
remote: [your_program] 2024-05-18T11:29:00.824922Z  INFO connection{addr=127.0.0.1:35608}:replication: redis_starter_rust::server: replconf reply received: Null
remote: [your_program] 2024-05-18T11:29:00.824937Z ERROR connection{addr=127.0.0.1:35608}:replication: redis_starter_rust::server: replconf expect a valid reply
remote: [your_program] 2024-05-18T11:29:00.824979Z  INFO connection{addr=127.0.0.1:35630}:replication: redis_starter_rust::server: replconf reply received: Null
remote: [your_program] 2024-05-18T11:29:00.824982Z ERROR connection{addr=127.0.0.1:35630}:replication: redis_starter_rust::server: replconf expect a valid reply
remote: [your_program] 2024-05-18T11:29:00.824998Z  INFO connection{addr=127.0.0.1:35618}:replication: redis_starter_rust::server: replconf reply received: Null
remote: [your_program] 2024-05-18T11:29:00.825000Z ERROR connection{addr=127.0.0.1:35618}:replication: redis_starter_rust::server: replconf expect a valid reply

It seems some of the clients don't reply to the GETACK before the second SET baz 789 happens. That's problematic because I wait for each GETACK before I process commands in the replication queue. The failing line is:

replica-2: Expecting "SET baz 789" to be propagated where the replica expects the SET, but it hasn't send reply to GETACK yet. Is it something one should handle and what timeouts should be used if so?

marxin avatar May 18 '24 11:05 marxin