Issue with MongoDb Delay Replica

Hi, I am trying to setup a Replica set with 1 Secondary to have some delay from Primary.
Even though rs.config() shows correct desired configurations, there is no delay when I make changes in Primary. The Delayed one is instantly reflecting changes. Not sure why configurations look fine but there is no delay.

It will be really helpful if someone can give some suggestions to fix this or experienced something similar.
Or if you know some guide other below doc that can help.

I followed below steps to make it delay by following these docs: https://www.mongodb.com/docs/manual/tutorial/configure-a-delayed-replica-set-member/#example

cfg = rs.conf() 
cfg.members[1].priority = 0 
cfg.members[1].hidden = true 
cfg.members[1].secondaryDelaySecs = 180 
rs.reconfig(cfg)

Also attaching screenshot of rs.conf() for reference.

Hi @Naman_Saxena1,
The configuration is correct!
Do you read the data from the hidden node?
You should do it in 3 minutes.

Regards

Hi @Fabio_Ramohitaj ,
so after inserting a new document in Primary, I instantly opened Secondary Delayed node in MongoDb Compass and it was showing latest document. I basically wanted to test if delay is working properly.
My understanding was MongoDb Compass will NOT show newly inserted document before 3 mins or am I missing some information?

Hi @Naman_Saxena1,
Are you sure you logged in to the correct instance? Because I see that you created the replica set on the same machine, with 3 different ports, so you will have to connect to the instance with port 27012.
Try to see it by going up directly to the server via the mongoshell.
I created a replica set for test and it works for me.

Regards

@Fabio_Ramohitaj yeah I am sure I am accessing correct instance.
Hmm, I will setup new replica set from scratch, maybe I made some mistake that is why delay is not happening. :thinking:

1 Like

@Naman_Saxena1, That seems pretty strange.
What version of MongoDB are you using?
Try recreating and let me know!

Regards

@Fabio_Ramohitaj I am using version 6.0

Even tried creating a new replica set and still there is no delay. I am sharing steps I am following, maybe you will be able notice if I am making some mistake.

cd C:\Program Files\MongoDB\Server\6.0\bin
mongod -f node1.cfg	-> Runs on 127.0.0.1:27011
mongod -f node2.cfg	-> Runs on 127.0.0.1:27012
mongod -f node3.cfg	-> Runs on 127.0.0.1:27013

mongosh --port 27011
use admin
rs.initiate()
db.createUser({user:"m103-admin",pwd: "m103-pass",roles:[{role:"root",db:"admin"}]})
exit
mongosh --host "m103-example/127.0.0.1:27011" -u "m103-admin" -p "m103-pass" --authenticationDatabase "admin"

10) Create config variable: rsconfig = { _id: "m103-example", members: [ { _id: 0, host: "localhost:27011" }, { _id: 1, host: "localhost:27012" }, { _id: 2, host: "localhost:27013" }] }
11) Initiate replica: rs.reconfig(rsconfig)

// To make 2nd Node Delayed
cfg = rs.conf()
cfg.members[1].hidden = true
cfg.members[1].priority = 0
cfg.members[1].secondaryDelaySecs = 600
rs.reconfig(cfg)

exit

Restart node1.cfg, node2.cfg and node3.cfg

// Connect to 27011
mongosh --host "m103-example/127.0.0.1:27011" -u "m103-admin" -p "m103-pass" --authenticationDatabase "admin"
use practicedb					
db.users.insertOne({name:'User1'})	
exit


mongosh --host "m103-example/127.0.0.1:27012" -u "m103-admin" -p "m103-pass" --authenticationDatabase "admin"
show databases				-> Showing practicedb before 5 mins (No Delay)
db.users.find({})				-> Showing newly inserted document before 5 mins (No Delay)

Or let me know if you have some guide that I can follow.

Thanks a lot for helping!

Hi @Naman_Saxena1,
Really strange.
If I can, I will do more tests on my machine when I get home tonight.

Regards

When you connect with

you are not reading from the secondary because you are connecting to the replica set. The first thing the shell does is to read the rs config and reconnect and read from the primary. To connect and read to the secondary you have to remove the replica set name from the connection. this means you need to connect with

127.0.0.1:27012

rather than

m103-example/127.0.0.1:27012
2 Likes

@steevej You are right!
Connected using 127.0.0.1:27012 and then ran db.getMongo().setReadPref(“secondary”) for testing.
It is working. Thanks a lot! :smile:

1 Like

Hi @steevej,
Honestly, I didn’t know it connected to the cluster, I suspected it, but I wanted to test before I said nonsense.

Best Rergards

1 Like

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