Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set up a mongodb delayed slave that is not hidden?

For testing purposes, I am trying to simulate a replication lag in a mongodb cluster, by setting up a slave with slaveDelay=n. As it turns out, this magically causes the slave to be hidden, so my test cannot access it.

The mongodb documentation states "Typically we would not want a delayed member to be used for slaveOkay reads. Thus, setting slaveDelay also hides the member from your application as if you also set hidden:true."

Is there a way to configure for my "untypical" use case? Or is there a better way to simulate reading from different slaves with varying time lag?

I tried forcing the test code to connect to the delayed slave using a TaggedReadPreference, but this results in a

com.mongodb.MongoException: Could not find any valid secondaries with the supplied tags ('{ "delayed" : "true"}'

Apparently the Java driver does cannot see the secondary. When I remove the "slaveDelay" setting, it connects fine.

Here's my cluster configuration:

rs.reconfig({
"_id" : "rs0",
"version" : 4,
"members" : [
    {   "_id" : 0,
        "host" : "localhost:27017",
        "priority" : 0,
        slaveDelay: 10,
        tags: { delayed: "true" }
    },
    {   "_id" : 1,
        "host" : "localhost:27018"
    },
    {   "_id" : 2,
        "host" : "localhost:27019",
        "arbiterOnly" : true
    }
]
})
like image 630
axeolotl Avatar asked Nov 04 '22 00:11

axeolotl


1 Answers

This is not possible as far as I'm aware. Your only route is to simulate/force actual network delay between your primary and your delayed secondary through a proxy for example. There are a number of such tools available and they will give you a more accurate test.

like image 100
Remon van Vliet Avatar answered Dec 01 '22 20:12

Remon van Vliet