#include <syncclusterconnection.h>
Public Member Functions | |
virtual bool | call (Message &toSend, Message &response, bool assertOk, string *actualServer) |
virtual bool | callRead (Message &toSend, Message &response) |
virtual BSONObj | findOne (const string &ns, const Query &query, const BSONObj *fieldsToReturn, int queryOptions) |
bool | fsync (string &errmsg) |
virtual BSONObj | getLastErrorDetailed () |
virtual auto_ptr< DBClientCursor > | getMore (const string &ns, long long cursorId, int nToReturn, int options) |
virtual 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 |
virtual void | killCursor (long long cursorID) |
bool | prepare (string &errmsg) |
virtual auto_ptr< DBClientCursor > | query (const string &ns, Query query, int nToReturn, int nToSkip, const BSONObj *fieldsToReturn, int queryOptions, int batchSize) |
virtual void | remove (const string &ns, Query query, bool justOne) |
virtual void | say (Message &toSend) |
virtual void | sayPiggyBack (Message &toSend) |
SyncClusterConnection (string a, string b, string c) | |
SyncClusterConnection (string commaSeparated) | |
SyncClusterConnection (const list< HostAndPort > &) | |
virtual string | toString () |
virtual ConnectionString::ConnectionType | type () const |
virtual void | update (const string &ns, Query query, BSONObj obj, bool upsert, bool multi) |
~SyncClusterConnection () | |
Private Member Functions | |
void | _checkLast () |
bool | _commandOnActive (const string &dbname, const BSONObj &cmd, BSONObj &info, int options=0) |
void | _connect (string host) |
int | _lockType (const string &name) |
auto_ptr< DBClientCursor > | _queryOnActive (const string &ns, Query query, int nToReturn, int nToSkip, const BSONObj *fieldsToReturn, int queryOptions, int batchSize) |
string | _toString () const |
SyncClusterConnection (SyncClusterConnection &prev) | |
Private Attributes | |
string | _address |
vector< string > | _connAddresses |
vector< DBClientConnection * > | _conns |
vector< BSONObj > | _lastErrors |
map< string, int > | _lockTypes |
mongo::mutex | _mutex |
This is a connection to a cluster of servers that operate as one for super high durability.
Write operations are two-phase. First, all nodes are asked to fsync. If successful everywhere, the write is sent everywhere and then followed by an fsync. There is no rollback if a problem occurs during the second phase. Naturally, with all these fsyncs, these operations will be quite slow -- use sparingly.
Read operations are sent to a single random node.
The class checks if a command is read or write style, and sends to a single node if a read lock command and to all in two phases with a write style command.
Definition at line 41 of file syncclusterconnection.h.
mongo::SyncClusterConnection::SyncClusterConnection | ( | const list< HostAndPort > & | ) |
commaSeparated | should be 3 hosts comma separated |
mongo::SyncClusterConnection::SyncClusterConnection | ( | string | commaSeparated | ) |
mongo::SyncClusterConnection::SyncClusterConnection | ( | string | a, | |
string | b, | |||
string | c | |||
) |
mongo::SyncClusterConnection::~SyncClusterConnection | ( | ) |
mongo::SyncClusterConnection::SyncClusterConnection | ( | SyncClusterConnection & | prev | ) | [private] |
void mongo::SyncClusterConnection::_checkLast | ( | ) | [private] |
bool mongo::SyncClusterConnection::_commandOnActive | ( | const string & | dbname, | |
const BSONObj & | cmd, | |||
BSONObj & | info, | |||
int | options = 0 | |||
) | [private] |
void mongo::SyncClusterConnection::_connect | ( | string | host | ) | [private] |
int mongo::SyncClusterConnection::_lockType | ( | const string & | name | ) | [private] |
auto_ptr<DBClientCursor> mongo::SyncClusterConnection::_queryOnActive | ( | const string & | ns, | |
Query | query, | |||
int | nToReturn, | |||
int | nToSkip, | |||
const BSONObj * | fieldsToReturn, | |||
int | queryOptions, | |||
int | batchSize | |||
) | [private] |
string mongo::SyncClusterConnection::_toString | ( | ) | const [private] |
virtual bool mongo::SyncClusterConnection::call | ( | Message & | toSend, | |
Message & | response, | |||
bool | assertOk, | |||
string * | actualServer | |||
) | [virtual] |
actualServer is set to the actual server where they call went if there was a choice (SlaveOk)
Implements mongo::DBConnector.
virtual bool mongo::SyncClusterConnection::callRead | ( | Message & | toSend, | |
Message & | response | |||
) | [virtual] |
Implements mongo::DBClientBase.
virtual BSONObj mongo::SyncClusterConnection::findOne | ( | const string & | ns, | |
const Query & | query, | |||
const BSONObj * | fieldsToReturn, | |||
int | queryOptions | |||
) | [virtual] |
AssertionException |
Reimplemented from mongo::DBClientInterface.
bool mongo::SyncClusterConnection::fsync | ( | string & | errmsg | ) |
runs fsync on all servers
virtual BSONObj mongo::SyncClusterConnection::getLastErrorDetailed | ( | ) | [virtual] |
Get error result from the last operation on this connection.
Reimplemented from mongo::DBClientWithCommands.
virtual auto_ptr<DBClientCursor> mongo::SyncClusterConnection::getMore | ( | const string & | ns, | |
long long | cursorId, | |||
int | nToReturn, | |||
int | options | |||
) | [virtual] |
don't use this - called automatically by DBClientCursor for you
cursorId | id of cursor to retrieve |
AssertionException |
Reimplemented from mongo::DBClientBase.
virtual string mongo::SyncClusterConnection::getServerAddress | ( | ) | const [inline, virtual] |
Implements mongo::DBClientInterface.
Definition at line 84 of file syncclusterconnection.h.
virtual void mongo::SyncClusterConnection::insert | ( | const string & | ns, | |
const vector< BSONObj > & | v | |||
) | [virtual] |
insert a vector of objects into the database
Reimplemented from mongo::DBClientBase.
virtual void mongo::SyncClusterConnection::insert | ( | const string & | ns, | |
BSONObj | obj | |||
) | [virtual] |
insert an object into the database
Reimplemented from mongo::DBClientBase.
virtual bool mongo::SyncClusterConnection::isFailed | ( | ) | const [inline, virtual] |
Implements mongo::DBClientBase.
Definition at line 85 of file syncclusterconnection.h.
virtual void mongo::SyncClusterConnection::killCursor | ( | long long | cursorID | ) | [virtual] |
Implements mongo::DBClientBase.
bool mongo::SyncClusterConnection::prepare | ( | string & | errmsg | ) |
virtual auto_ptr<DBClientCursor> mongo::SyncClusterConnection::query | ( | const string & | ns, | |
Query | query, | |||
int | nToReturn, | |||
int | nToSkip, | |||
const BSONObj * | fieldsToReturn, | |||
int | queryOptions, | |||
int | batchSize | |||
) | [virtual] |
send a query to the database.
ns | namespace to query, format is <dbname>.<collectname>[.<collectname>]* | |
query | query to perform on the collection. this is a BSONObj (binary JSON) You may format as { query: { ... }, orderby: { ... } } to specify a sort order. | |
nToReturn | n to return (i.e., limit). 0 = unlimited | |
nToSkip | start with the nth item | |
fieldsToReturn | optional template of which fields to select. if unspecified, returns all fields | |
queryOptions | see options enum at top of this file |
AssertionException |
Reimplemented from mongo::DBClientBase.
virtual void mongo::SyncClusterConnection::remove | ( | const string & | ns, | |
Query | q, | |||
bool | justOne | |||
) | [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::SyncClusterConnection::say | ( | Message & | toSend | ) | [virtual] |
Implements mongo::DBClientBase.
virtual void mongo::SyncClusterConnection::sayPiggyBack | ( | Message & | toSend | ) | [virtual] |
Implements mongo::DBConnector.
virtual string mongo::SyncClusterConnection::toString | ( | ) | [inline, virtual] |
Implements mongo::DBClientWithCommands.
Definition at line 86 of file syncclusterconnection.h.
virtual ConnectionString::ConnectionType mongo::SyncClusterConnection::type | ( | ) | const [inline, virtual] |
Implements mongo::DBClientBase.
Definition at line 92 of file syncclusterconnection.h.
virtual void mongo::SyncClusterConnection::update | ( | const string & | ns, | |
Query | query, | |||
BSONObj | obj, | |||
bool | upsert, | |||
bool | multi | |||
) | [virtual] |
updates objects matching query
Reimplemented from mongo::DBClientBase.
string mongo::SyncClusterConnection::_address [private] |
Definition at line 104 of file syncclusterconnection.h.
vector<string> mongo::SyncClusterConnection::_connAddresses [private] |
Definition at line 105 of file syncclusterconnection.h.
vector<DBClientConnection*> mongo::SyncClusterConnection::_conns [private] |
Definition at line 106 of file syncclusterconnection.h.
vector<BSONObj> mongo::SyncClusterConnection::_lastErrors [private] |
Definition at line 110 of file syncclusterconnection.h.
map<string,int> mongo::SyncClusterConnection::_lockTypes [private] |
Definition at line 107 of file syncclusterconnection.h.
Definition at line 108 of file syncclusterconnection.h.