本文整理汇总了C++中DBClientConnection::call方法的典型用法代码示例。如果您正苦于以下问题:C++ DBClientConnection::call方法的具体用法?C++ DBClientConnection::call怎么用?C++ DBClientConnection::call使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DBClientConnection
的用法示例。
在下文中一共展示了DBClientConnection::call方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: call
bool DBClientReplicaSet::call( Message &toSend, Message &response, bool assertOk , string * actualServer ) {
if ( toSend.operation() == dbQuery ) {
// TODO: might be possible to do this faster by changing api
DbMessage dm( toSend );
QueryMessage qm( dm );
if ( qm.queryOptions & QueryOption_SlaveOk ) {
for ( int i=0; i<3; i++ ) {
try {
DBClientConnection* s = checkSlave();
if ( actualServer )
*actualServer = s->getServerAddress();
return s->call( toSend , response , assertOk );
}
catch ( DBException &e ) {
LOG(1) << "can't call replica set slave " << i << " : " << _slaveHost << causedBy( e ) << endl;
if ( actualServer )
*actualServer = "";
}
}
}
}
DBClientConnection* m = checkMaster();
if ( actualServer )
*actualServer = m->getServerAddress();
return m->call( toSend , response , assertOk );
}
示例2: call
bool DBClientReplicaSet::call(Message &toSend,
Message &response,
bool assertOk,
string * actualServer) {
const char * ns = 0;
if (toSend.operation() == dbQuery) {
// TODO: might be possible to do this faster by changing api
DbMessage dm(toSend);
QueryMessage qm(dm);
ns = qm.ns;
shared_ptr<ReadPreferenceSetting> readPref( _extractReadPref( qm.query,
qm.queryOptions ) );
if ( _isSecondaryQuery( ns, qm.query, *readPref ) ) {
LOG( 3 ) << "dbclient_rs call using secondary or tagged node selection in "
<< _getMonitor()->getName() << ", read pref is "
<< readPref->toBSON() << " (primary : "
<< ( _master.get() != NULL ?
_master->getServerAddress() : "[not cached]" )
<< ", lastTagged : "
<< ( _lastSlaveOkConn.get() != NULL ?
_lastSlaveOkConn->getServerAddress() : "[not cached]" )
<< ")" << endl;
for (size_t retry = 0; retry < MAX_RETRY; retry++) {
try {
DBClientConnection* conn = selectNodeUsingTags(readPref);
if (conn == NULL) {
return false;
}
if (actualServer != NULL) {
*actualServer = conn->getServerAddress();
}
return conn->call(toSend, response, assertOk);
}
catch ( const DBException& dbExcep ) {
LOG(1) << "can't call replica set node " << _lastSlaveOkHost << ": "
<< causedBy( dbExcep ) << endl;
if ( actualServer ) *actualServer = "";
invalidateLastSlaveOkCache();
}
}
// Was not able to successfully send after max retries
return false;
}
}
LOG( 3 ) << "dbclient_rs call to primary node in " << _getMonitor()->getName() << endl;
DBClientConnection* m = checkMaster();
if ( actualServer )
*actualServer = m->getServerAddress();
if ( ! m->call( toSend , response , assertOk ) )
return false;
if ( ns ) {
QueryResult * res = (QueryResult*)response.singleData();
if ( res->nReturned == 1 ) {
BSONObj x(res->data() );
if ( str::contains( ns , "$cmd" ) ) {
if ( isNotMasterErrorString( x["errmsg"] ) )
isntMaster();
}
else {
if ( isNotMasterErrorString( getErrField( x ) ) )
isntMaster();
}
}
}
return true;
}