Expand my Community achievements bar.

SOLVED

Set ReadPreference for mongodb in WAR file

Avatar

Level 6

I need to set the readpreference of mongodb as primaryPreferred in web.xml. How to do it?

1 Accepted Solution

Avatar

Correct answer by
Level 10

So in the same document, it has mentioned to set that as part of configuration. So you can mention as part of your Mongo URI configration in AEM as below

 

via Configuration

In this mode the config is specified as part of the Mongo URI (See configuration). So if a user wants that reads from secondaries should prefer secondary with tag dc:ny,rack:1otherwise they go to other secondary then he can specify that via following mongouri

mongodb://example1.com,example2.com,example3.com/?readPreference=secondary&readPreferenceTags=dc:ny,rack:1&readPreferenceTags=dc:ny&readPreferenceTags= 

View solution in original post

4 Replies

Avatar

Employee

With standalone AEM instances there is no web.xml

Which reference did you read about setting readpreference? This seems like a MongoDB setting rather than an AEM setting.

Avatar

Level 6

This is for the war file. I referred http://jackrabbit.apache.org/oak/docs/nodestore/documentmk.html for details. But I am not able to set the read preference. It has to be set from AEM server.

Avatar

Correct answer by
Level 10

So in the same document, it has mentioned to set that as part of configuration. So you can mention as part of your Mongo URI configration in AEM as below

 

via Configuration

In this mode the config is specified as part of the Mongo URI (See configuration). So if a user wants that reads from secondaries should prefer secondary with tag dc:ny,rack:1otherwise they go to other secondary then he can specify that via following mongouri

mongodb://example1.com,example2.com,example3.com/?readPreference=secondary&readPreferenceTags=dc:ny,rack:1&readPreferenceTags=dc:ny&readPreferenceTags= 

Avatar

Level 6

This is not working. I am setting the readPreference as primaryPreferred. When I shutdown the primary db, AEM always tries to connect to primary.  I am getting the below error. As you see below the readPreference is not modifed even though I pass this parameter in web.xml 

 

18.08.2015 21:09:32.707 *WARN* [DocumentNodeStore lease update thread] org.apache.jackrabbit.oak.plugins.document.DocumentNodeStore Background operation failed: org.apache.jackrabbit.oak.plugins.document.DocumentStoreException: Timed out after 10000 ms while waiting for a server that matches {serverSelectors=[ReadPreferenceServerSelector{readPreference=primary}, LatencyMinimizingServerSelector{acceptableLatencyDifference=15 ms}]}. Client view of cluster state is {type=ReplicaSet, servers=[{address=local:17017, type=ReplicaSetArbiter, averageLatency=1.9 ms, state=Connected}, {address=local:27017, type=ReplicaSetSecondary, averageLatency=2.1 ms, state=Connected}, {address=1local:27017, type=Unknown, state=Connecting, exception={com.mongodb.MongoException$Network: Exception opening the socket}, caused by {java.net.ConnectException: Connection refused}}]