20#include <boost/shared_ptr.hpp>
24#include "mongo/client/export_macros.h"
25#include "mongo/util/net/hostandport.h"
29class ReplicaSetMonitor;
31struct ReadPreferenceSetting;
32typedef boost::shared_ptr<ReplicaSetMonitor> ReplicaSetMonitorPtr;
44 using DBClientBase::query;
45 using DBClientBase::update;
46 using DBClientBase::remove;
51 const std::vector<HostAndPort>& servers,
52 double so_timeout = 0);
74 virtual std::auto_ptr<DBClientCursor>
query(
const std::string& ns,
78 const BSONObj* fieldsToReturn = 0,
85 const BSONObj* fieldsToReturn = 0,
86 int queryOptions = 0);
88 virtual void insert(
const std::string& ns,
93 virtual void insert(
const std::string& ns,
94 const std::vector<BSONObj>& v,
98 virtual void remove(
const std::string& ns,
Query obj,
int flags,
const WriteConcern* wc = NULL);
103 virtual void killCursor(
long long cursorID);
126 virtual void say(
Message& toSend,
bool isRetry =
false, std::string* actualServer = 0);
127 virtual bool recv(
Message& toRecv);
128 virtual void checkResponse(
const char* data,
131 std::string* targetHost = NULL);
140 void isntSecondary();
144 virtual bool isFailed()
const {
145 return !_master || _master->isFailed();
151 double getSoTimeout()
const {
155 std::string toString()
const {
156 return getServerAddress();
159 std::string getServerAddress()
const;
161 virtual ConnectionString::ConnectionType type()
const {
162 return ConnectionString::SET;
164 virtual bool lazySupported()
const {
172 bool assertOk =
true,
173 std::string* actualServer = 0);
175 return checkMaster()->callRead(toSend, response);
188 static bool MONGO_CLIENT_FUNC
206 virtual int getMaxWireVersion() {
207 return checkMaster()->getMaxWireVersion();
210 virtual int getMinWireVersion() {
211 return checkMaster()->getMinWireVersion();
219 virtual void sayPiggyBack(
Message& toSend) {
220 checkMaster()->say(toSend);
231 std::auto_ptr<DBClientCursor> checkSlaveQueryResult(std::auto_ptr<DBClientCursor> result);
247 DBClientConnection* selectNodeUsingTags(boost::shared_ptr<ReadPreferenceSetting> readPref);
258 void invalidateLastSlaveOkCache();
276 void resetSlaveOkConn();
282 static const size_t MAX_RETRY;
285 static bool _authPooledSecondaryConn;
288 ReplicaSetMonitorPtr _getMonitor()
const;
290 std::string _setName;
293 boost::scoped_ptr<DBClientConnection> _master;
301 std::auto_ptr<DBClientConnection> _lastSlaveOkConn;
302 boost::shared_ptr<ReadPreferenceSetting> _lastReadPref;
310 std::map<std::string, BSONObj> _auths;
318 LazyState() : _lastClient(NULL), _lastOp(-1), _secondaryQueryOk(
false), _retries(0) {}
321 bool _secondaryQueryOk;
355 bool operator==(
const TagSet& other)
const {
356 return _tags == other._tags;
374 return pref == other.pref && tags == other.tags;
377 BSONObj toBSON()
const;
379 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:1422
A basic connection to the database.
Definition dbclientinterface.h:1716
for storing (non-threadsafe) information between lazy calls
Definition dbclient_rs.h:316
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:1342
stdx::function< void(BSONObjBuilder *)> RunCommandHookFunc
A function type for runCommand hooking; the function takes a pointer to a BSONObjBuilder and returns ...
Definition dbclientinterface.h:1332
Represents a Mongo query expression.
Definition dbclientinterface.h:403
Class to encapsulate client side "Write Concern" concept.
Definition write_concern.h:35
Core MongoDB C++ driver interfaces are defined here.
Utility functions for parsing numbers from strings.
Definition compare_numbers.h:20
Name of a process on the network.
Definition hostandport.h:37
Definition dbclient_rs.h:363
ReadPreferenceSetting(ReadPreference pref, const TagSet &tag)
@parm pref the read preference mode.
Definition dbclient_rs.h:371