Mongodb replica config slaveDelay but data still sync immediately

All we need is an easy explanation of the problem, so here it is.

I’ve set slaveDelay to 600s but when the Primary data change, the Secondary data change immediately. Here’s the curent configuration of repl with 2 server.

"members" : [
{
    "_id" : 0,
    "host" : “primary.host1:27017",
    "arbiterOnly" : false,
    "buildIndexes" : true,
    "hidden" : false,
    "priority" : 1,
    "tags" : {

    },
    "slaveDelay" : NumberLong(0),
    "votes" : 1
},
{
    "_id" : 1,
    "host" : “secondary.host2:27017",
    "arbiterOnly" : false,
    "buildIndexes" : true,
    "hidden" : true,
    "priority" : 0,
    "tags" : {

    },
    "slaveDelay" : NumberLong(600),
    "votes" : 1
}]

I don’t know where did I go wrong, or how is the slaveDelay work, since the secondary data should update after 600s.

How to solve :

I know you bored from this bug, So we are here to help you! Take a deep breath and look at the explanation of your problem. We have many solutions to this problem, But we recommend you to use the first method because it is tested & true method that will 100% work for you.

Method 1

If secondary do “initial sync”, it will reach primary first, but then it will “sleep” (this case 600 seconds) to fall back and after that, it will keep syncing 600s behind.

You can see that (sleep) in mongod.log if you watch what is happening at end of initial sync. After that sleep, if you look “last” document in opLog, it’s time stamp is that 600s behind. Of course you can see that with rs.printSlaveReplicationInfo() too.

Note: Use and implement method 1 because this method fully tested our system.
Thank you 🙂

All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply