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;
51 const std::vector<HostAndPort>& servers,
52 double so_timeout = 0);
69 virtual void logout(
const std::string& dbname,
BSONObj& info);
74 virtual std::auto_ptr<DBClientCursor> query(
const std::string& ns,
78 const BSONObj* fieldsToReturn = 0,
83 virtual BSONObj findOne(
const std::string& ns,
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();
147 bool isStillConnected();
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 {
170 virtual bool call(
Message& toSend,
172 bool assertOk =
true,
173 std::string* actualServer = 0);
175 return checkMaster()->callRead(toSend, response);
188 static bool MONGO_CLIENT_FUNC
189 isSecondaryQuery(
const std::string& ns,
const BSONObj& queryObj,
int queryOptions);
198 virtual void reset();
204 static void setAuthPooledSecondaryConn(
bool setting);
206 virtual int getMaxWireVersion() {
207 return checkMaster()->getMaxWireVersion();
210 virtual int getMinWireVersion() {
211 return checkMaster()->getMinWireVersion();
217 virtual void _auth(
const BSONObj& params);
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;
Definition: dbclient_rs.h:363
for storing (non-threadsafe) information between lazy calls
Definition: dbclient_rs.h:316
Definition: message.h:305
Utility functions for parsing numbers from strings.
Definition: compare_numbers.h:20
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
A basic connection to the database.
Definition: dbclientinterface.h:1716
Use this class to connect to a replica set of servers.
Definition: dbclient_rs.h:42
Core MongoDB C++ driver interfaces are defined here.
virtual void remove(const std::string &ns, Query q, bool justOne=0, const WriteConcern *wc=NULL)
remove matching objects from the database
Class to encapsulate client side "Write Concern" concept.
Definition: write_concern.h:35
Name of a process on the network.
Definition: hostandport.h:37
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
virtual void update(const std::string &ns, Query query, BSONObj obj, bool upsert=false, bool multi=false, const WriteConcern *wc=NULL)
updates objects matching query
Definition: bsonobj.h:581
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)
send a query to the database.
Represents a Mongo query expression.
Definition: dbclientinterface.h:403
abstract class that implements the core db operations
Definition: dbclientinterface.h:1422
ReadPreferenceSetting(ReadPreference pref, const TagSet &tag)
pref the read preference mode.
Definition: dbclient_rs.h:371
C++ representation of a "BSON" object – that is, an extended JSON-style object in a binary represent...
Definition: bsonobj.h:78