I’m stuck on stage 13.
I’ve tried so I’ve set up two go routines to handle connections from clients and masters (for replicas). Issue is whenever I run the test, only some of the SET commands will propagate to the replicas. usually its second or third. but never all three. Not sure whats going on.
here’s a snippet of my code:
server.go: package mainimport ( "encoding/base64" "flag" "fmt" "io" "net" " - Pastebin.com
Here are my logs:
codecrafters test
Initiating test run...
⏳ Turbo test runners busy. You are in queue.
Upgrade to skip the wait: https://codecrafters.io/turbo
Running tests. Logs should appear shortly...
Debug = true
[replication-13] Running tests for Replication > Stage #13: Command Processing
[replication-13] Master is running on port 6379
[replication-13] $ ./spawn_redis_server.sh --port 6380 --replicaof localhost 6379
[replication-13] master: Received bytes: "*1\r\n$4\r\nPING\r\n"
[replication-13] master: Received RESP value: ["PING"]
[replication-13] Received ["PING"]
[replication-13] master: Sent "PONG"
[replication-13] master: Sent bytes: "+PONG\r\n"
[replication-13] master: Received bytes: "*3\r\n$8\r\nREPLCONF\r\n$14\r\nlistening-port\r\n$4\r\n6380\r\n"
[replication-13] master: Received RESP value: ["REPLCONF", "listening-port", "6380"]
[replication-13] Received ["REPLCONF", "listening-port", "6380"]
[replication-13] master: Sent "OK"
[replication-13] master: Sent bytes: "+OK\r\n"
[replication-13] master: Received bytes: "*3\r\n$8\r\nREPLCONF\r\n$4\r\ncapa\r\n$6\r\npsync2\r\n"
[replication-13] master: Received RESP value: ["REPLCONF", "capa", "psync2"]
[replication-13] Received ["REPLCONF", "capa", "psync2"]
[replication-13] master: Sent "OK"
[replication-13] master: Sent bytes: "+OK\r\n"
[replication-13] master: Received bytes: "*3\r\n$5\r\nPSYNC\r\n$1\r\n?\r\n$2\r\n-1\r\n"
[replication-13] master: Received RESP value: ["PSYNC", "?", "-1"]
[replication-13] Received ["PSYNC", "?", "-1"]
[your_program] Listening on port: 6380
[replication-13] master: Sent "FULLRESYNC 75cd7bc10c49047e0d163660f3b90625b1af31dc 0"
[replication-13] master: Sent bytes: "+FULLRESYNC 75cd7bc10c49047e0d163660f3b90625b1af31dc 0\r\n"
[replication-13] Sending RDB file...
[replication-13] master: Sent bytes: "$88\r\nREDIS0011\xfa\tredis-ver\x057.2.0\xfa\nredis-bits\xc0@\xfa\x05ctime\xc2m\b\xbce\xfa\bused-mem°\xc4\x10\x00\xfa\baof-base\xc0\x00\xff\xf0n;\xfe\xc0\xffZ\xa2"
[replication-13] Sent RDB file.
[your_program] Unknown type: +Client connected: [::1]:6379
[your_program] Invalid request, expected array
[replication-13] master: $ redis-cli SET foo 123
[replication-13] master: Sent bytes: "*3\r\n$3\r\nSET\r\n$3\r\nfoo\r\n$3\r\n123\r\n"
[replication-13] master: $ redis-cli SET bar 456
[replication-13] master: Sent bytes: "*3\r\n$3\r\nSET\r\n$3\r\nbar\r\n$3\r\n456\r\n"
[replication-13] master: $ redis-cli SET baz 789
[replication-13] master: Sent bytes: "*3\r\n$3\r\nSET\r\n$3\r\nbaz\r\n$3\r\n789\r\n"
[replication-13] Getting key foo
[replication-13] client: $ redis-cli GET foo
[replication-13] client: Sent bytes: "*2\r\n$3\r\nGET\r\n$3\r\nfoo\r\n"
[your_program] Client connected: [::1]:6379
[your_program] slave received: SET [{bulk 0 foo [] 0 false} {bulk 0 123 [] 0 false}] result: {string OK 0 [] 0 false}
[your_program] slave DB VALUE: map[foo:{string 123 0 [] 0 false}]
[your_program] Client connected: [::1]:6379
[your_program] slave received: SET [{bulk 0 bar [] 0 false} {bulk 0 456 [] 0 false}] result: {string OK 0 [] 0 false}
[your_program] slave DB VALUE: map[bar:{string 456 0 [] 0 false} foo:{string 123 0 [] 0 false}]
[your_program] Client connected: [::1]:33970
[your_program] slave received: GET [{bulk 0 foo [] 0 false}] result: {string 123 0 [] 0 false}
[your_program] slave DB VALUE: map[bar:{string 456 0 [] 0 false} foo:{string 123 0 [] 0 false}]
[replication-13] client: Received bytes: "+123\r\n"
[replication-13] client: Received RESP value: "123"
[replication-13] Received "123"
[replication-13] Getting key bar
[replication-13] client: $ redis-cli GET bar
[replication-13] client: Sent bytes: "*2\r\n$3\r\nGET\r\n$3\r\nbar\r\n"
[your_program] Client connected: [::1]:33970
[your_program] slave received: GET [{bulk 0 bar [] 0 false}] result: {string 456 0 [] 0 false}
[your_program] slave DB VALUE: map[bar:{string 456 0 [] 0 false} foo:{string 123 0 [] 0 false}]
[replication-13] client: Received bytes: "+456\r\n"
[replication-13] client: Received RESP value: "456"
[replication-13] Received "456"
[replication-13] Getting key baz
[replication-13] client: $ redis-cli GET baz
[replication-13] client: Sent bytes: "*2\r\n$3\r\nGET\r\n$3\r\nbaz\r\n"
[your_program] Client connected: [::1]:33970
[your_program] slave received: GET [{bulk 0 baz [] 0 false}] result: {null 0 [] 0 false}
[your_program] slave DB VALUE: map[bar:{string 456 0 [] 0 false} foo:{string 123 0 [] 0 false}]
[replication-13] client: Received bytes: "$-1\r\n"
[replication-13] client: Received RESP value: NIL
[replication-13] Retrying... (1/5 attempts)
[replication-13] client: $ redis-cli GET baz
[replication-13] client: Sent bytes: "*2\r\n$3\r\nGET\r\n$3\r\nbaz\r\n"
[replication-13] client: Received bytes: "$-1\r\n"
[replication-13] client: Received RESP value: NIL
[your_program] Client connected: [::1]:33970
[your_program] slave received: GET [{bulk 0 baz [] 0 false}] result: {null 0 [] 0 false}
[your_program] slave DB VALUE: map[bar:{string 456 0 [] 0 false} foo:{string 123 0 [] 0 false}]
[replication-13] Retrying... (2/5 attempts)
[replication-13] client: $ redis-cli GET baz
[replication-13] client: Sent bytes: "*2\r\n$3\r\nGET\r\n$3\r\nbaz\r\n"
[replication-13] client: Received bytes: "$-1\r\n"
[replication-13] client: Received RESP value: NIL
[your_program] Client connected: [::1]:33970
[your_program] slave received: GET [{bulk 0 baz [] 0 false}] result: {null 0 [] 0 false}
[your_program] slave DB VALUE: map[bar:{string 456 0 [] 0 false} foo:{string 123 0 [] 0 false}]
[replication-13] Retrying... (3/5 attempts)
[replication-13] client: $ redis-cli GET baz
[replication-13] client: Sent bytes: "*2\r\n$3\r\nGET\r\n$3\r\nbaz\r\n"
[replication-13] client: Received bytes: "$-1\r\n"
[replication-13] client: Received RESP value: NIL
[your_program] Client connected: [::1]:33970
[your_program] slave received: GET [{bulk 0 baz [] 0 false}] result: {null 0 [] 0 false}
[your_program] slave DB VALUE: map[bar:{string 456 0 [] 0 false} foo:{string 123 0 [] 0 false}]
[replication-13] Retrying... (4/5 attempts)
[replication-13] client: $ redis-cli GET baz
[replication-13] client: Sent bytes: "*2\r\n$3\r\nGET\r\n$3\r\nbaz\r\n"
[replication-13] client: Received bytes: "$-1\r\n"
[replication-13] client: Received RESP value: NIL
[your_program] Client connected: [::1]:33970
[your_program] slave received: GET [{bulk 0 baz [] 0 false}] result: {null 0 [] 0 false}
[your_program] slave DB VALUE: map[bar:{string 456 0 [] 0 false} foo:{string 123 0 [] 0 false}]
[replication-13] Retrying... (5/5 attempts)
[replication-13] client: $ redis-cli GET baz
[replication-13] client: Sent bytes: "*2\r\n$3\r\nGET\r\n$3\r\nbaz\r\n"
[replication-13] client: Received bytes: "$-1\r\n"
[replication-13] client: Received RESP value: NIL
[your_program] Client connected: [::1]:33970
[your_program] slave received: GET [{bulk 0 baz [] 0 false}] result: {null 0 [] 0 false}
[your_program] slave DB VALUE: map[bar:{string 456 0 [] 0 false} foo:{string 123 0 [] 0 false}]
[your_program] Client disconnected: [::1]:33970
[your_program] ERR IS read tcp [::1]:53302->[::1]:6379: read: connection reset by peer
[replication-13] Expected simple string or bulk string, got NIL
[replication-13] Test failed
[replication-13] Terminating program
[replication-13] Program terminated successfully