20#include <boost/shared_ptr.hpp>
24#include "mongo/client/export_macros.h"
25#include "mongo/util/net/hostandport.h"
29 class ReplicaSetMonitor;
31 struct ReadPreferenceSetting;
32 typedef boost::shared_ptr<ReplicaSetMonitor> ReplicaSetMonitorPtr;
44 using DBClientBase::query;
45 using DBClientBase::update;
46 using DBClientBase::remove;
49 DBClientReplicaSet(
const std::string& name ,
const std::vector<HostAndPort>& servers,
double so_timeout=0 );
71 virtual std::auto_ptr<DBClientCursor>
query(
const std::string &ns,
Query query,
int nToReturn = 0,
int nToSkip = 0,
72 const BSONObj *fieldsToReturn = 0,
int queryOptions = 0 ,
int batchSize = 0 );
79 virtual void insert(
const std::string &ns,
const std::vector< BSONObj >& v ,
int flags=0,
const WriteConcern* wc=NULL );
81 virtual void remove(
const std::string &ns ,
Query obj ,
int flags,
const WriteConcern* wc=NULL );
85 virtual void killCursor(
long long cursorID );
108 virtual void say(
Message &toSend,
bool isRetry =
false , std::string* actualServer = 0);
109 virtual bool recv(
Message &toRecv );
110 virtual void checkResponse(
const char* data,
int nReturned,
bool* retry = NULL, std::string* targetHost = NULL );
118 void isntSecondary();
122 virtual bool isFailed()
const {
return ! _master || _master->isFailed(); }
127 double getSoTimeout()
const {
return _so_timeout; }
129 std::string toString()
const {
return getServerAddress(); }
131 std::string getServerAddress()
const;
133 virtual ConnectionString::ConnectionType type()
const {
return ConnectionString::SET; }
134 virtual bool lazySupported()
const {
return true; }
138 virtual bool call(
Message &toSend,
Message &response,
bool assertOk=
true , std::string * actualServer = 0 );
139 virtual bool callRead(
Message& toSend ,
Message& response ) {
return checkMaster()->callRead( toSend , response ); }
175 virtual void sayPiggyBack(
Message &toSend ) { checkMaster()->say( toSend ); }
185 std::auto_ptr<DBClientCursor> checkSlaveQueryResult( std::auto_ptr<DBClientCursor> result );
201 DBClientConnection* selectNodeUsingTags(boost::shared_ptr<ReadPreferenceSetting> readPref);
212 void invalidateLastSlaveOkCache();
230 void resetSlaveOkConn();
236 static const size_t MAX_RETRY;
239 static bool _authPooledSecondaryConn;
242 ReplicaSetMonitorPtr _getMonitor()
const;
244 std::string _setName;
247 boost::scoped_ptr<DBClientConnection> _master;
255 std::auto_ptr<DBClientConnection> _lastSlaveOkConn;
256 boost::shared_ptr<ReadPreferenceSetting> _lastReadPref;
264 std::map<std::string, BSONObj> _auths;
274 _lastClient( NULL ), _lastOp( -1 ), _secondaryQueryOk(
false ), _retries( 0 ) {}
277 bool _secondaryQueryOk;
310 bool operator==(
const TagSet& other)
const {
return _tags == other._tags; }
325 pref(pref), tags(tag) {
329 return pref == other.pref && tags == other.tags;
332 BSONObj toBSON()
const;
334 const ReadPreference pref;
C++ representation of a "BSON" object – that is, an extended JSON-style object in a binary representa...
Definition bsonobj.h:78
abstract class that implements the core db operations
Definition dbclientinterface.h:1330
A basic connection to the database.
Definition dbclientinterface.h:1551
for storing (non-threadsafe) information between lazy calls
Definition dbclient_rs.h:271
Use this class to connect to a replica set of servers.
Definition dbclient_rs.h:42
bool connect()
Returns false if no member of the set were reachable.
static bool MONGO_CLIENT_FUNC isSecondaryQuery(const std::string &ns, const BSONObj &queryObj, int queryOptions)
Returns whether a query or command can be sent to secondaries based on the query object and options.
DBClientConnection & slaveConn()
WARNING: this method is very dangerous - this object can decide to free the returned master connectio...
static void setAuthPooledSecondaryConn(bool setting)
@bool setting if true, DBClientReplicaSet connections will make sure that secondary connections are a...
DBClientReplicaSet(const std::string &name, const std::vector< HostAndPort > &servers, double so_timeout=0)
Call connect() after constructing.
virtual void logout(const std::string &dbname, BSONObj &info)
Logs out the connection for the given database.
DBClientConnection & masterConn()
WARNING: this method is very dangerous - this object can decide to free the returned master connectio...
virtual void insert(const std::string &ns, BSONObj obj, int flags=0, const WriteConcern *wc=NULL)
insert an object into the database
bool isStillConnected()
if not checked recently, checks whether the underlying socket/sockets are still valid
virtual void _auth(const BSONObj ¶ms)
Authorize.
virtual bool call(Message &toSend, Message &response, bool assertOk=true, std::string *actualServer=0)
actualServer is set to the actual server where they call went if there was a choice (SlaveOk)
virtual void insert(const std::string &ns, const std::vector< BSONObj > &v, int flags=0, const WriteConcern *wc=NULL)
insert a vector of objects into the database
virtual std::auto_ptr< DBClientCursor > query(const std::string &ns, Query query, int nToReturn=0, int nToSkip=0, const BSONObj *fieldsToReturn=0, int queryOptions=0, int batchSize=0)
throws userassertion "no master found"
virtual BSONObj findOne(const std::string &ns, const Query &query, const BSONObj *fieldsToReturn=0, int queryOptions=0)
throws userassertion "no master found"
virtual void reset()
Performs a "soft reset" by clearing all states relating to secondary nodes and returning secondary co...
stdx::function< void(const BSONObj &, const std::string &)> PostRunCommandHookFunc
Similar to above, but for running a function on a command response after a command has been run.
Definition dbclientinterface.h:1231
stdx::function< void(BSONObjBuilder *)> RunCommandHookFunc
A function type for runCommand hooking; the function takes a pointer to a BSONObjBuilder and returns ...
Definition dbclientinterface.h:1221
Represents a Mongo query expression.
Definition dbclientinterface.h:387
Class to encapsulate client side "Write Concern" concept.
Definition write_concern.h:35
Core MongoDB C++ driver interfaces are defined here.
the main MongoDB namespace
Definition bulk_operation_builder.h:24
Name of a process on the network.
Definition hostandport.h:36
Definition dbclient_rs.h:316
ReadPreferenceSetting(ReadPreference pref, const TagSet &tag)
@parm pref the read preference mode.
Definition dbclient_rs.h:324