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
}
]
})
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With