summaryrefslogtreecommitdiff
path: root/client/dbclient_rs.cpp
diff options
context:
space:
mode:
authorEliot Horowitz <eliot@10gen.com>2010-12-19 00:11:23 -0500
committerEliot Horowitz <eliot@10gen.com>2010-12-19 00:11:23 -0500
commitc4ea46b1e709e69bf08257f6e10473ef55df5781 (patch)
treed1f4a193f9d821e840194e95bd98fd88f09513af /client/dbclient_rs.cpp
parente6dc75b1250fcfb3141a0a4142f9d7ddbe2e20f0 (diff)
downloadmongo-c4ea46b1e709e69bf08257f6e10473ef55df5781.tar.gz
route queries to secondaris if SLAVE_OK is set SEVER-1634
Diffstat (limited to 'client/dbclient_rs.cpp')
-rw-r--r--client/dbclient_rs.cpp40
1 files changed, 34 insertions, 6 deletions
diff --git a/client/dbclient_rs.cpp b/client/dbclient_rs.cpp
index 6897c182839..6bbafad42ae 100644
--- a/client/dbclient_rs.cpp
+++ b/client/dbclient_rs.cpp
@@ -349,14 +349,42 @@ namespace mongo {
return checkMaster()->update(ns, query, obj, upsert,multi);
}
- auto_ptr<DBClientCursor> DBClientReplicaSet::query(const string &a, Query b, int c, int d,
- const BSONObj *e, int f, int g){
- // TODO: if slave ok is set go to a slave
- return checkMaster()->query(a,b,c,d,e,f,g);
+ auto_ptr<DBClientCursor> DBClientReplicaSet::query(const string &ns, Query query, int nToReturn, int nToSkip,
+ const BSONObj *fieldsToReturn, int queryOptions, int batchSize){
+
+ if ( queryOptions & QueryOption_SlaveOk ){
+ // we're ok sending to a slave
+ // we'll try 2 slaves before just using master
+ // checkSlave will try a different slave automatically after a failure
+ for ( int i=0; i<2; i++ ){
+ try {
+ return checkSlave()->query(ns,query,nToReturn,nToSkip,fieldsToReturn,queryOptions,batchSize);
+ }
+ catch ( DBException & e ){
+ LOG(1) << "can't query replica set slave: " << _slaveHost << endl;
+ }
+ }
+ }
+
+ return checkMaster()->query(ns,query,nToReturn,nToSkip,fieldsToReturn,queryOptions,batchSize);
}
- BSONObj DBClientReplicaSet::findOne(const string &a, const Query& b, const BSONObj *c, int d) {
- return checkMaster()->findOne(a,b,c,d);
+ BSONObj DBClientReplicaSet::findOne(const string &ns, const Query& query, const BSONObj *fieldsToReturn, int queryOptions) {
+ if ( queryOptions & QueryOption_SlaveOk ){
+ // we're ok sending to a slave
+ // we'll try 2 slaves before just using master
+ // checkSlave will try a different slave automatically after a failure
+ for ( int i=0; i<2; i++ ){
+ try {
+ return checkSlave()->findOne(ns,query,fieldsToReturn,queryOptions);
+ }
+ catch ( DBException & e ){
+ LOG(1) << "can't query replica set slave: " << _slaveHost << endl;
+ }
+ }
+ }
+
+ return checkMaster()->findOne(ns,query,fieldsToReturn,queryOptions);
}
void DBClientReplicaSet::killCursor( long long cursorID ){