#YG4 Command not reaching to the replica

CodeCarfters tester output:

remote: ------------------------------------------------------------------------
remote: 
remote: 
remote:      ___            _          ___              __  _                   
remote:     / __\ ___    __| |  ___   / __\_ __  __ _  / _|| |_  ___  _ __  ___ 
remote:    / /   / _ \  / _` | / _ \ / /  | '__|/ _` || |_ | __|/ _ \| '__|/ __|
remote:   / /___| (_) || (_| ||  __// /___| |  | (_| ||  _|| |_|  __/| |   \__ 
remote:   \____/ \___/  \__,_| \___|\____/|_|   \__,_||_|   \__|\___||_|   |___/
remote: 
remote: 
remote:    Welcome to CodeCrafters! Your commit was received successfully.
remote: 
remote: ------------------------------------------------------------------------
remote: 
remote: ⚡ This is a turbo test run. https://codecrafters.io/turbo
remote: 
remote: Running tests on your code. Logs should appear shortly...
remote: 
remote: [compile] [INFO] Scanning for projects...
remote: [compile] [INFO] 
remote: [compile] [INFO] -----------------< io.codecrafters:codecrafters-redis >-----------------
remote: [compile] [INFO] Building codecrafters-redis 1.0
remote: [compile] [INFO]   from pom.xml
remote: [compile] [INFO] --------------------------------[ jar ]---------------------------------
remote: [compile] [INFO] 
remote: [compile] [INFO] --- resources:3.3.1:resources (default-resources) @ codecrafters-redis ---
remote: [compile] [INFO] skip non existing resourceDirectory /app/src/main/resources
remote: [compile] [INFO] 
remote: [compile] [INFO] --- compiler:3.13.0:compile (default-compile) @ codecrafters-redis ---
remote: [compile] [INFO] Recompiling the module because of changed source code.
remote: [compile] [INFO] Compiling 6 source files with javac [debug target 21] to target/classes
remote: [compile] [WARNING] location of system modules is not set in conjunction with -source 21
remote: [compile]   not setting the location of system modules may lead to class files that cannot run on JDK 21
remote: [compile]     --release 21 is recommended instead of -source 21 -target 21 because it sets the location of system modules automatically
remote: [compile] [INFO] 
remote: [compile] [INFO] --- resources:3.3.1:testResources (default-testResources) @ codecrafters-redis ---
remote: [compile] [INFO] skip non existing resourceDirectory /app/src/test/resources
remote: [compile] [INFO] 
remote: [compile] [INFO] --- compiler:3.13.0:testCompile (default-testCompile) @ codecrafters-redis ---
remote: [compile] [INFO] No sources to compile
remote: [compile] [INFO] 
remote: [compile] [INFO] --- surefire:3.2.5:test (default-test) @ codecrafters-redis ---
remote: [compile] [INFO] No tests to run.
remote: [compile] [INFO] 
remote: [compile] [INFO] --- jar:3.4.1:jar (default-jar) @ codecrafters-redis ---
remote: [compile] [INFO] Building jar: /app/target/codecrafters-redis-1.0.jar
remote: [compile] [INFO] 
remote: [compile] [INFO] --- assembly:3.7.1:single (make-assembly) @ codecrafters-redis ---
remote: [compile] [INFO] Building jar: /tmp/codecrafters-build-redis-java/codecrafters-redis.jar
remote: [compile] [WARNING] Configuration option 'appendAssemblyId' is set to false.
remote: [compile] Instead of attaching the assembly file: /tmp/codecrafters-build-redis-java/codecrafters-redis.jar, it will become the file for main project artifact.
remote: [compile] NOTE: If multiple descriptors or descriptor-formats are provided for this project, the value of this file will be non-deterministic!
remote: [compile] [WARNING] Replacing pre-existing project main-artifact file: /app/target/codecrafters-redis-1.0.jar
remote: [compile] with assembly file: /tmp/codecrafters-build-redis-java/codecrafters-redis.jar
remote: [compile] [INFO] ------------------------------------------------------------------------
remote: [compile] [INFO] BUILD SUCCESS
remote: [compile] [INFO] ------------------------------------------------------------------------
remote: [compile] [INFO] Total time:  3.475 s
remote: [compile] [INFO] Finished at: 2024-11-27T06:55:07Z
remote: [compile] [INFO] ------------------------------------------------------------------------
remote: [compile] Moved ./.codecrafters/run.sh → ./your_program.sh
remote: [compile] Compilation successful.
remote: 
remote: Debug = true
remote: 
remote: [tester::#YG4] Running tests for Stage #YG4 (Replication - Command Processing)
remote: [tester::#YG4] Master is running on port 6379
remote: [tester::#YG4] $ ./your_program.sh --port 6380 --replicaof "localhost 6379"
remote: [your_program] dir: 
remote: [your_program] dbfile: 
remote: [your_program] server port: 6380
remote: [your_program] role: slave
remote: [your_program]   hostname: localhost
remote: [your_program]   hostport: 6379
remote: [your_program] version: 
remote: [your_program] Logs from your program will appear here!
remote: [tester::#YG4] [handshake] master: Waiting for replica to initiate handshake with "PING" command
remote: [your_program] doing handshake
remote: [tester::#YG4] [handshake] master: Received bytes: "*1\r\n$4\r\nPING\r\n"
remote: [tester::#YG4] [handshake] master: Received RESP array: ["PING"]
remote: [tester::#YG4] [handshake] Received ["PING"]
remote: [tester::#YG4] [handshake] master: Sent "PONG"
remote: [tester::#YG4] [handshake] master: Sent bytes: "+PONG\r\n"
remote: [tester::#YG4] [handshake] master: Waiting for replica to send "REPLCONF listening-port 6380" command
remote: [your_program] +PONG
remote: [tester::#YG4] [handshake] master: Received bytes: "*3\r\n$8\r\nREPLCONF\r\n$14\r\nlistening-port\r\n$4\r\n6380\r\n"
remote: [tester::#YG4] [handshake] master: Received RESP array: ["REPLCONF", "listening-port", "6380"]
remote: [tester::#YG4] [handshake] Received ["REPLCONF", "listening-port", "6380"]
remote: [tester::#YG4] [handshake] master: Sent "OK"
remote: [tester::#YG4] [handshake] master: Sent bytes: "+OK\r\n"
remote: [tester::#YG4] [handshake] master: Waiting for replica to send "REPLCONF capa" command
remote: [your_program] +OK
remote: [tester::#YG4] [handshake] master: Received bytes: "*3\r\n$8\r\nREPLCONF\r\n$4\r\ncapa\r\n$6\r\npsync2\r\n"
remote: [tester::#YG4] [handshake] master: Received RESP array: ["REPLCONF", "capa", "psync2"]
remote: [tester::#YG4] [handshake] Received ["REPLCONF", "capa", "psync2"]
remote: [tester::#YG4] [handshake] master: Sent "OK"
remote: [tester::#YG4] [handshake] master: Sent bytes: "+OK\r\n"
remote: [tester::#YG4] [handshake] master: Waiting for replica to send "PSYNC" command
remote: [your_program] +OK
remote: [tester::#YG4] [handshake] master: Received bytes: "*3\r\n$5\r\nPSYNC\r\n$1\r\n?\r\n$2\r\n-1\r\n"
remote: [tester::#YG4] [handshake] master: Received RESP array: ["PSYNC", "?", "-1"]
remote: [tester::#YG4] [handshake] Received ["PSYNC", "?", "-1"]
remote: [tester::#YG4] [handshake] master: Sent "FULLRESYNC 75cd7bc10c49047e0d163660f3b90625b1af31dc 0"
remote: [tester::#YG4] [handshake] master: Sent bytes: "+FULLRESYNC 75cd7bc10c49047e0d163660f3b90625b1af31dc 0\r\n"
remote: [tester::#YG4] [handshake] Sending RDB file...
remote: [tester::#YG4] [handshake] 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"
remote: [tester::#YG4] [handshake] Sent RDB file.
remote: [tester::#YG4] [propagation] master: > SET foo 123
remote: [tester::#YG4] [propagation] master: Sent bytes: "*3\r\n$3\r\nSET\r\n$3\r\nfoo\r\n$3\r\n123\r\n"
remote: [tester::#YG4] [propagation] master: > SET bar 456
remote: [tester::#YG4] [propagation] master: Sent bytes: "*3\r\n$3\r\nSET\r\n$3\r\nbar\r\n$3\r\n456\r\n"
remote: [tester::#YG4] [propagation] master: > SET baz 789
remote: [tester::#YG4] [propagation] master: Sent bytes: "*3\r\n$3\r\nSET\r\n$3\r\nbaz\r\n$3\r\n789\r\n"
remote: [tester::#YG4] [test] Getting key foo
remote: [tester::#YG4] [test] client: $ redis-cli GET foo
remote: [tester::#YG4] [test] client: Sent bytes: "*2\r\n$3\r\nGET\r\n$3\r\nfoo\r\n"
remote: [your_program] +FULLRESYNC 75cd7bc10c49047e0d163660f3b90625b1af31dc 0
remote: [your_program] $88
remote: [your_program] REDIS0011�       redis-ver7.2.0�
remote: [your_program] redis-bits�@�ctime��eused-mem°� Command received :[SET, bar, 456]
remote: [your_program] Command received :[SET, baz, 789]
remote: [your_program] [SET, bar, 456]
remote: [your_program] [SET, baz, 789]
remote: [your_program] [GET, foo]
remote: [tester::#YG4] [test] client: Received bytes: "$-1\r\n"
remote: [tester::#YG4] [test] client: Received RESP null bulk string: "$-1\r\n"
remote: [tester::#YG4] [test] Retrying... (1/5 attempts)
remote: [tester::#YG4] [test] client: > GET foo
remote: [tester::#YG4] [test] client: Sent bytes: "*2\r\n$3\r\nGET\r\n$3\r\nfoo\r\n"
remote: [tester::#YG4] [test] client: Received bytes: "$-1\r\n"
remote: [tester::#YG4] [test] client: Received RESP null bulk string: "$-1\r\n"
remote: [your_program] [GET, foo]
remote: [tester::#YG4] [test] Retrying... (2/5 attempts)
remote: [tester::#YG4] [test] client: > GET foo
remote: [tester::#YG4] [test] client: Sent bytes: "*2\r\n$3\r\nGET\r\n$3\r\nfoo\r\n"
remote: [your_program] [GET, foo]
remote: [tester::#YG4] [test] client: Received bytes: "$-1\r\n"
remote: [tester::#YG4] [test] client: Received RESP null bulk string: "$-1\r\n"
remote: [tester::#YG4] [test] Retrying... (3/5 attempts)
remote: [tester::#YG4] [test] client: > GET foo
remote: [tester::#YG4] [test] client: Sent bytes: "*2\r\n$3\r\nGET\r\n$3\r\nfoo\r\n"
remote: [tester::#YG4] [test] client: Received bytes: "$-1\r\n"
remote: [tester::#YG4] [test] client: Received RESP null bulk string: "$-1\r\n"
remote: [your_program] [GET, foo]
remote: [tester::#YG4] [test] Retrying... (4/5 attempts)
remote: [tester::#YG4] [test] client: > GET foo
remote: [tester::#YG4] [test] client: Sent bytes: "*2\r\n$3\r\nGET\r\n$3\r\nfoo\r\n"
remote: [tester::#YG4] [test] client: Received bytes: "$-1\r\n"
remote: [tester::#YG4] [test] client: Received RESP null bulk string: "$-1\r\n"
remote: [your_program] [GET, foo]
remote: [tester::#YG4] [test] Retrying... (5/5 attempts)
remote: [tester::#YG4] [test] client: > GET foo
remote: [tester::#YG4] [test] client: Sent bytes: "*2\r\n$3\r\nGET\r\n$3\r\nfoo\r\n"
remote: [tester::#YG4] [test] client: Received bytes: "$-1\r\n"
remote: [tester::#YG4] [test] client: Received RESP null bulk string: "$-1\r\n"
remote: [your_program] [GET, foo]
remote: [tester::#YG4] Expected simple string or bulk string, got NIL
remote: [tester::#YG4] Test failed
remote: [tester::#YG4] Terminating program
remote: [tester::#YG4] Program terminated successfully
remote: 
remote: Try our CLI to run tests faster without Git: https://codecrafters.io/cli
remote: 
remote: View our article on debugging test failures: https://codecrafters.io/debug
remote: 
To https://git.codecrafters.io/eb5367dbbaf2942b
   bb908fe..77b731e  master -> master

in here we can see that my replica server didn’t ready the first commnd set foo 123,
but when i tried to run the server locally i get the correct output

logs of master

[INFO] Scanning for projects...
[INFO] 
[INFO] -----------------< io.codecrafters:codecrafters-redis >-----------------
[INFO] Building codecrafters-redis 1.0
[INFO]   from pom.xml
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] 
[INFO] --- resources:3.3.1:resources (default-resources) @ codecrafters-redis ---
[INFO] skip non existing resourceDirectory /home/happypotter/Programming/whitepaper/codecrafters-redis-java/src/main/resources
[INFO] 
[INFO] --- compiler:3.13.0:compile (default-compile) @ codecrafters-redis ---
[INFO] Nothing to compile - all classes are up to date.
[INFO] 
[INFO] --- resources:3.3.1:testResources (default-testResources) @ codecrafters-redis ---
[INFO] skip non existing resourceDirectory /home/happypotter/Programming/whitepaper/codecrafters-redis-java/src/test/resources
[INFO] 
[INFO] --- compiler:3.13.0:testCompile (default-testCompile) @ codecrafters-redis ---
[INFO] No sources to compile
[INFO] 
[INFO] --- surefire:3.2.5:test (default-test) @ codecrafters-redis ---
[INFO] 
[INFO] --- jar:3.4.1:jar (default-jar) @ codecrafters-redis ---
[INFO] 
[INFO] --- assembly:3.7.1:single (make-assembly) @ codecrafters-redis ---
[INFO] Building jar: /tmp/codecrafters-build-redis-java/codecrafters-redis.jar
[WARNING] Configuration option 'appendAssemblyId' is set to false.
Instead of attaching the assembly file: /tmp/codecrafters-build-redis-java/codecrafters-redis.jar, it will become the file for main project artifact.
NOTE: If multiple descriptors or descriptor-formats are provided for this project, the value of this file will be non-deterministic!
[WARNING] Replacing pre-existing project main-artifact file: /home/happypotter/Programming/whitepaper/codecrafters-redis-java/target/codecrafters-redis-1.0.jar
with assembly file: /tmp/codecrafters-build-redis-java/codecrafters-redis.jar
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  1.999 s
[INFO] Finished at: 2024-11-27T12:41:47+05:30
[INFO] ------------------------------------------------------------------------
dir: 
dbfile: 
server port: 6379
role: master
version: 
Logs from your program will appear here!
[PING]
[REPLCONF, listening-port, 6380]
Repl listening port: 6380
[REPLCONF, capa, psync2]
capabilitles: psync2
[PSYNC, ?, -1]
[set, name, 223]
Adding args to queue: [set, name, 223]
Sending command to replica: [set, name, 223]
[set, baz, 333]
Adding args to queue: [set, baz, 333]
Sending command to replica: [set, baz, 333]
[set, foo, 123]
Adding args to queue: [set, foo, 123]
Sending command to replica: [set, foo, 123]

logs of replica

[INFO] Scanning for projects...
[INFO] 
[INFO] -----------------< io.codecrafters:codecrafters-redis >-----------------
[INFO] Building codecrafters-redis 1.0
[INFO]   from pom.xml
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] 
[INFO] --- resources:3.3.1:resources (default-resources) @ codecrafters-redis ---
[INFO] skip non existing resourceDirectory /home/happypotter/Programming/whitepaper/codecrafters-redis-java/src/main/resources
[INFO] 
[INFO] --- compiler:3.13.0:compile (default-compile) @ codecrafters-redis ---
[INFO] Nothing to compile - all classes are up to date.
[INFO] 
[INFO] --- resources:3.3.1:testResources (default-testResources) @ codecrafters-redis ---
[INFO] skip non existing resourceDirectory /home/happypotter/Programming/whitepaper/codecrafters-redis-java/src/test/resources
[INFO] 
[INFO] --- compiler:3.13.0:testCompile (default-testCompile) @ codecrafters-redis ---
[INFO] No sources to compile
[INFO] 
[INFO] --- surefire:3.2.5:test (default-test) @ codecrafters-redis ---
[INFO] 
[INFO] --- jar:3.4.1:jar (default-jar) @ codecrafters-redis ---
[INFO] 
[INFO] --- assembly:3.7.1:single (make-assembly) @ codecrafters-redis ---
[INFO] Building jar: /tmp/codecrafters-build-redis-java/codecrafters-redis.jar
[WARNING] Configuration option 'appendAssemblyId' is set to false.
Instead of attaching the assembly file: /tmp/codecrafters-build-redis-java/codecrafters-redis.jar, it will become the file for main project artifact.
NOTE: If multiple descriptors or descriptor-formats are provided for this project, the value of this file will be non-deterministic!
[WARNING] Replacing pre-existing project main-artifact file: /home/happypotter/Programming/whitepaper/codecrafters-redis-java/target/codecrafters-redis-1.0.jar
with assembly file: /tmp/codecrafters-build-redis-java/codecrafters-redis.jar
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  1.685 s
[INFO] Finished at: 2024-11-27T12:41:51+05:30
[INFO] ------------------------------------------------------------------------
dir: 
dbfile: 
server port: 6380
role: slave
         hostname: localhost
         hostport: 6379
version: 
Logs from your program will appear here!
doing handshake
+PONG
+OK
+OK
Command received :[set, name, 223]
[set, name, 223]
Command received :[set, baz, 333]
[set, baz, 333]
Command received :[set, foo, 123]
[set, foo, 123]

please help me with this,

here’s my github repo, please take a look GitHub - wigiwee/codecrafters-redis-java

I’ll take a look and get back to you by the end of the week.

can you please help me with this a bit earlier

Thank you for your understanding! We’re a small team, and as you’ve likely noticed, there’s a backlog of issues being addressed on the forum.

We’re doing our best to work through them as quickly as possible, and we truly appreciate your patience.

@wigiwee , I tried running your code against the previous stages, but it’s no longer passing #LA7 Implement the SET & GET commands.

Suggestions:

  1. Use our CLI to test against previous stages by running:
codecrafters test --previous
  1. Focus on fixing the early stages first, as later stages depend on them.

i am very sorry about this, while debugging #YG4 i put a bunch of print statements and things went wrong, i fixed it, it was a minor issue, now #LA7 works but #YG4 still has same issue

Now it’s #GL7 (Replication - Send handshake (1/3)):

fixed that, please check now,

@andy1li you found anything?, i’m still stuck here

Sorry for the delayed response. One potential issue is that handshake is run in a separate thread, which can cause race conditions.

Could you try ensuring that the handshake is fully completed before accepting client connections?


still same error,

in the handshake() method i start accepting requests only after i receive rdb file

in the handshake() method i start accepting requests only after i receive rdb file

The writer and reader within your handshake function are not for client connections; they represent the connection to the master and should be handled in a separate thread—but also only after the handshake is complete.

could you please provide a code example that would pass that test, i actually don’t have subscription but i am planning to buy the 3 month subscription if i can pass this test,

Feel free to check out my code, though it’s in Python.

Closing this thread due to inactivity. If you still need assistance, feel free to reopen or start a new discussion!

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.