#include <dbclient_rs.h>

Classes | |
| struct | AuthInfo |
Public Member Functions | |
| virtual bool | auth (const string &dbname, const string &username, const string &pwd, string &errmsg, bool digestPassword=true) |
| virtual bool | call (Message &toSend, Message &response, bool assertOk=true, string *actualServer=0) |
| virtual bool | callRead (Message &toSend, Message &response) |
| virtual void | checkResponse (const char *data, int nReturned) |
| bool | connect () |
| DBClientReplicaSet (const string &name, const vector< HostAndPort > &servers) | |
| virtual BSONObj | findOne (const string &ns, const Query &query, const BSONObj *fieldsToReturn=0, int queryOptions=0) |
| string | getServerAddress () const |
| virtual void | insert (const string &ns, const vector< BSONObj > &v) |
| virtual void | insert (const string &ns, BSONObj obj) |
| virtual bool | isFailed () const |
| void | isntMaster () |
| virtual void | killCursor (long long cursorID) |
| DBClientConnection & | masterConn () |
| virtual auto_ptr< DBClientCursor > | query (const string &ns, Query query, int nToReturn=0, int nToSkip=0, const BSONObj *fieldsToReturn=0, int queryOptions=0, int batchSize=0) |
| virtual void | remove (const string &ns, Query obj, bool justOne=0) |
| virtual void | say (Message &toSend) |
| DBClientConnection & | slaveConn () |
| string | toString () |
| virtual ConnectionString::ConnectionType | type () const |
| virtual void | update (const string &ns, Query query, BSONObj obj, bool upsert=0, bool multi=0) |
| virtual | ~DBClientReplicaSet () |
Protected Member Functions | |
| virtual void | sayPiggyBack (Message &toSend) |
Private Member Functions | |
| void | _auth (DBClientConnection *conn) |
| DBClientConnection * | checkMaster () |
| DBClientConnection * | checkSlave () |
Private Attributes | |
| list< AuthInfo > | _auths |
| scoped_ptr< DBClientConnection > | _master |
| HostAndPort | _masterHost |
| ReplicaSetMonitorPtr | _monitor |
| scoped_ptr< DBClientConnection > | _slave |
| HostAndPort | _slaveHost |
Use this class to connect to a replica set of servers. The class will manage checking for which server in a replica set is master, and do failover automatically.
This can also be used to connect to replica pairs since pairs are a subset of sets
On a failover situation, expect at least one operation to return an error (throw an exception) before the failover is complete. Operations are not retried.
Definition at line 166 of file dbclient_rs.h.
| mongo::DBClientReplicaSet::DBClientReplicaSet | ( | const string & | name, | |
| const vector< HostAndPort > & | servers | |||
| ) |
Call connect() after constructing. autoReconnect is always on for DBClientReplicaSet connections.
| virtual mongo::DBClientReplicaSet::~DBClientReplicaSet | ( | ) | [virtual] |
| void mongo::DBClientReplicaSet::_auth | ( | DBClientConnection * | conn | ) | [private] |
| virtual bool mongo::DBClientReplicaSet::auth | ( | const string & | dbname, | |
| const string & | username, | |||
| const string & | pwd, | |||
| string & | errmsg, | |||
| bool | digestPassword = true | |||
| ) | [virtual] |
Authorize. Authorizes all nodes as needed
Reimplemented from mongo::DBClientWithCommands.
| virtual bool mongo::DBClientReplicaSet::call | ( | Message & | toSend, | |
| Message & | response, | |||
| bool | assertOk = true, |
|||
| string * | actualServer = 0 | |||
| ) | [virtual] |
actualServer is set to the actual server where they call went if there was a choice (SlaveOk)
Implements mongo::DBConnector.
| virtual bool mongo::DBClientReplicaSet::callRead | ( | Message & | toSend, | |
| Message & | response | |||
| ) | [inline, virtual] |
Implements mongo::DBClientBase.
Definition at line 234 of file dbclient_rs.h.
| DBClientConnection* mongo::DBClientReplicaSet::checkMaster | ( | ) | [private] |
| virtual void mongo::DBClientReplicaSet::checkResponse | ( | const char * | data, | |
| int | nReturned | |||
| ) | [inline, virtual] |
Reimplemented from mongo::DBConnector.
Definition at line 212 of file dbclient_rs.h.
| DBClientConnection* mongo::DBClientReplicaSet::checkSlave | ( | ) | [private] |
| bool mongo::DBClientReplicaSet::connect | ( | ) |
Returns false if nomember of the set were reachable, or neither is master, although, when false returned, you can still try to use this connection object, it will try reconnects.
| virtual BSONObj mongo::DBClientReplicaSet::findOne | ( | const string & | ns, | |
| const Query & | query, | |||
| const BSONObj * | fieldsToReturn = 0, |
|||
| int | queryOptions = 0 | |||
| ) | [virtual] |
throws userassertion "no master found"
Reimplemented from mongo::DBClientInterface.
| string mongo::DBClientReplicaSet::getServerAddress | ( | ) | const [inline, virtual] |
Implements mongo::DBClientInterface.
Definition at line 226 of file dbclient_rs.h.
| virtual void mongo::DBClientReplicaSet::insert | ( | const string & | ns, | |
| const vector< BSONObj > & | v | |||
| ) | [virtual] |
insert multiple objects. Note that single object insert is asynchronous, so this version is only nominally faster and not worth a special effort to try to use.
Reimplemented from mongo::DBClientBase.
| virtual void mongo::DBClientReplicaSet::insert | ( | const string & | ns, | |
| BSONObj | obj | |||
| ) | [virtual] |
insert an object into the database
Reimplemented from mongo::DBClientBase.
| virtual bool mongo::DBClientReplicaSet::isFailed | ( | ) | const [inline, virtual] |
Implements mongo::DBClientBase.
Definition at line 220 of file dbclient_rs.h.
| void mongo::DBClientReplicaSet::isntMaster | ( | ) |
| virtual void mongo::DBClientReplicaSet::killCursor | ( | long long | cursorID | ) | [virtual] |
Implements mongo::DBClientBase.
| DBClientConnection& mongo::DBClientReplicaSet::masterConn | ( | ) |
| virtual auto_ptr<DBClientCursor> mongo::DBClientReplicaSet::query | ( | const string & | ns, | |
| Query | query, | |||
| int | nToReturn = 0, |
|||
| int | nToSkip = 0, |
|||
| const BSONObj * | fieldsToReturn = 0, |
|||
| int | queryOptions = 0, |
|||
| int | batchSize = 0 | |||
| ) | [virtual] |
throws userassertion "no master found"
Reimplemented from mongo::DBClientBase.
| virtual void mongo::DBClientReplicaSet::remove | ( | const string & | ns, | |
| Query | q, | |||
| bool | justOne = 0 | |||
| ) | [virtual] |
remove matching objects from the database
| justOne | if this true, then once a single match is found will stop |
Reimplemented from mongo::DBClientBase.
| virtual void mongo::DBClientReplicaSet::say | ( | Message & | toSend | ) | [inline, virtual] |
Implements mongo::DBClientBase.
Definition at line 233 of file dbclient_rs.h.
| virtual void mongo::DBClientReplicaSet::sayPiggyBack | ( | Message & | toSend | ) | [inline, protected, virtual] |
Implements mongo::DBConnector.
Definition at line 238 of file dbclient_rs.h.
| DBClientConnection& mongo::DBClientReplicaSet::slaveConn | ( | ) |
| string mongo::DBClientReplicaSet::toString | ( | ) | [inline, virtual] |
Implements mongo::DBClientWithCommands.
Definition at line 224 of file dbclient_rs.h.
| virtual ConnectionString::ConnectionType mongo::DBClientReplicaSet::type | ( | ) | const [inline, virtual] |
Implements mongo::DBClientBase.
Definition at line 228 of file dbclient_rs.h.
| virtual void mongo::DBClientReplicaSet::update | ( | const string & | ns, | |
| Query | query, | |||
| BSONObj | obj, | |||
| bool | upsert = 0, |
|||
| bool | multi = 0 | |||
| ) | [virtual] |
updates objects matching query
Reimplemented from mongo::DBClientBase.
list<AuthInfo> mongo::DBClientReplicaSet::_auths [private] |
Definition at line 272 of file dbclient_rs.h.
scoped_ptr<DBClientConnection> mongo::DBClientReplicaSet::_master [private] |
Definition at line 250 of file dbclient_rs.h.
Definition at line 249 of file dbclient_rs.h.
Definition at line 247 of file dbclient_rs.h.
scoped_ptr<DBClientConnection> mongo::DBClientReplicaSet::_slave [private] |
Definition at line 253 of file dbclient_rs.h.
Definition at line 252 of file dbclient_rs.h.