本文整理汇总了C++中DBClientConnection::say方法的典型用法代码示例。如果您正苦于以下问题:C++ DBClientConnection::say方法的具体用法?C++ DBClientConnection::say怎么用?C++ DBClientConnection::say使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DBClientConnection
的用法示例。
在下文中一共展示了DBClientConnection::say方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: say
void DBClientReplicaSet::say( Message& toSend, bool isRetry ) {
if( ! isRetry )
_lazyState = LazyState();
int lastOp = -1;
bool slaveOk = false;
if ( ( lastOp = toSend.operation() ) == dbQuery ) {
// TODO: might be possible to do this faster by changing api
DbMessage dm( toSend );
QueryMessage qm( dm );
if ( ( slaveOk = ( qm.queryOptions & QueryOption_SlaveOk ) ) ) {
for ( int i = _lazyState._retries; i < 3; i++ ) {
try {
DBClientConnection* slave = checkSlave();
slave->say( toSend );
_lazyState._lastOp = lastOp;
_lazyState._slaveOk = slaveOk;
_lazyState._retries = i;
_lazyState._lastClient = slave;
return;
}
catch ( DBException &e ) {
LOG(1) << "can't callLazy replica set slave " << i << " : " << _slaveHost << causedBy( e ) << endl;
}
}
}
}
DBClientConnection* master = checkMaster();
master->say( toSend );
_lazyState._lastOp = lastOp;
_lazyState._slaveOk = slaveOk;
_lazyState._retries = 3;
_lazyState._lastClient = master;
return;
}
示例2: say
void DBClientReplicaSet::say(Message& toSend, bool isRetry, string* actualServer) {
if (!isRetry)
_lazyState = LazyState();
const int lastOp = toSend.operation();
if (lastOp == dbQuery) {
// TODO: might be possible to do this faster by changing api
DbMessage dm(toSend);
QueryMessage qm(dm);
shared_ptr<ReadPreferenceSetting> readPref( _extractReadPref( qm.query,
qm.queryOptions ) );
if ( _isSecondaryQuery( qm.ns, qm.query, *readPref ) ) {
LOG( 3 ) << "dbclient_rs say 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;
string lastNodeErrMsg;
for (size_t retry = 0; retry < MAX_RETRY; retry++) {
_lazyState._retries = retry;
try {
DBClientConnection* conn = selectNodeUsingTags(readPref);
if (conn == NULL) {
break;
}
if (actualServer != NULL) {
*actualServer = conn->getServerAddress();
}
conn->say(toSend);
_lazyState._lastOp = lastOp;
_lazyState._secondaryQueryOk = true;
_lazyState._lastClient = conn;
}
catch ( const DBException& DBExcep ) {
StringBuilder errMsgBuilder;
errMsgBuilder << "can't callLazy replica set node "
<< _lastSlaveOkHost.toString() << ": " << causedBy( DBExcep );
lastNodeErrMsg = errMsgBuilder.str();
LOG(1) << lastNodeErrMsg << endl;
invalidateLastSlaveOkCache();
continue;
}
return;
}
StringBuilder assertMsg;
assertMsg << "Failed to call say, no good nodes in " << _getMonitor()->getName();
if ( !lastNodeErrMsg.empty() ) {
assertMsg << ", last error: " << lastNodeErrMsg;
}
uasserted(16380, assertMsg.str());
}
}
LOG( 3 ) << "dbclient_rs say to primary node in " << _getMonitor()->getName()
<< endl;
DBClientConnection* master = checkMaster();
if (actualServer)
*actualServer = master->getServerAddress();
_lazyState._lastOp = lastOp;
_lazyState._secondaryQueryOk = false;
// Don't retry requests to primary since there is only one host to try
_lazyState._retries = MAX_RETRY;
_lazyState._lastClient = master;
master->say(toSend);
return;
}