Need to send read-only requests to secondary only.

133 views
Skip to first unread message

globalundo

unread,
Sep 29, 2012, 6:09:29 PM9/29/12
to mongod...@googlegroups.com
Greetings. I have 3 mongo instances running on separate servers: mongo1, mongo2 and mongo3, they're involved in sharding. Each of them act as primary in one of three ReplSets respectively and has a secondary for failover purposes, with no read allowed.
Currently, I would like to allow separate read-only queries to those secondary servers. Clients should be able to run any kind of read-only, poorly written queries with no effect on production cluster.
Unfortunately, I did not find the solution. Any tips? Simple image, explaining the situation, included. Thanks.
rect4074.png

Stephen Steneker

unread,
Sep 29, 2012, 11:46:20 PM9/29/12
to mongod...@googlegroups.com
Greetings. I have 3 mongo instances running on separate servers: mongo1, mongo2 and mongo3, they're involved in sharding. Each of them act as primary in one of three ReplSets respectively and has a secondary for failover purposes, with no read allowed.
Currently, I would like to allow separate read-only queries to those secondary servers. Clients should be able to run any kind of read-only, poorly written queries with no effect on production cluster.
Unfortunately, I did not find the solution. Any tips? Simple image, explaining the situation, included. Thanks.

Hi,

MongoDB 2.2 added support for additional read preference modes, including "Secondary" (secondary only):

There is also a "Secondary Preferred" read preference which will read from the primary if no secondaries are available.  This is equivalent to the "slaveOK" read preference in older drivers.

An additional option for targeting queries is Tag Sets, which are also described on the same documentation link above.

Cheers,
Stephen

globalundo

unread,
Sep 30, 2012, 5:54:05 AM9/30/12
to mongod...@googlegroups.com
Hi there, Stephen

That will do the trick — I was not aware of this change in 2.2, thanks-)
But, just to make sure: there is no way to allow read-only queries to secondary on server side, right? Application(driver)-level only.

Stephen Steneker

unread,
Oct 1, 2012, 3:35:43 AM10/1/12
to mongod...@googlegroups.com
That will do the trick — I was not aware of this change in 2.2, thanks-)

To be clear, the 2.2 change was additional read preferences (primaryPreferred, Secondary, and Nearest).  As mentioned, the SlaveOK (or "Secondary Preferred") read preference is available in previous versions.

 
But, just to make sure: there is no way to allow read-only queries to secondary on server side, right? Application(driver)-level only.

Yes, the read preferences are set via application/driver options.  The default read preference is "primary".

Depending on your driver, you should be able to set the read preference on a per-connection, per-collection, and per-operation basis.

Cheers,
Stephen 

globalundo

unread,
Oct 1, 2012, 9:27:28 AM10/1/12
to mongod...@googlegroups.com
Yeah, and I'm interested in "secondary" mode only. Once again, thanks for answer!
Reply all
Reply to author
Forward
0 new messages