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;
49 DBClientReplicaSet(
const std::string& name ,
const std::vector<HostAndPort>& servers,
double so_timeout=0 );
66 virtual void logout(
const std::string& dbname,
BSONObj& info);
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 );
75 virtual BSONObj findOne(
const std::string &ns,
const Query& query,
const BSONObj *fieldsToReturn = 0,
int queryOptions = 0);
77 virtual void insert(
const std::string &ns ,
BSONObj obj ,
int flags=0,
const WriteConcern* wc=NULL );
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(); }
123 bool isStillConnected();
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 ); }
151 static bool MONGO_CLIENT_FUNC isSecondaryQuery(
const std::string& ns,
162 virtual void reset();
168 static void setAuthPooledSecondaryConn(
bool setting);
173 virtual void _auth(
const BSONObj& params);
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;
Definition: dbclient_rs.h:316
for storing (non-threadsafe) information between lazy calls
Definition: dbclient_rs.h:271
Definition: message.h:298
the main MongoDB namespace
Definition: bulk_operation_builder.h:24
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
A basic connection to the database.
Definition: dbclientinterface.h:1551
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:36
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
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:559
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:387
abstract class that implements the core db operations
Definition: dbclientinterface.h:1330
ReadPreferenceSetting(ReadPreference pref, const TagSet &tag)
pref the read preference mode.
Definition: dbclient_rs.h:324
C++ representation of a "BSON" object – that is, an extended JSON-style object in a binary represent...
Definition: bsonobj.h:78