本文整理汇总了C++中ShardedConnectionInfo::inForceVersionOkMode方法的典型用法代码示例。如果您正苦于以下问题:C++ ShardedConnectionInfo::inForceVersionOkMode方法的具体用法?C++ ShardedConnectionInfo::inForceVersionOkMode怎么用?C++ ShardedConnectionInfo::inForceVersionOkMode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ShardedConnectionInfo
的用法示例。
在下文中一共展示了ShardedConnectionInfo::inForceVersionOkMode方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: shardVersionOk
/**
* @ return true if not in sharded mode
or if version for this client is ok
*/
bool shardVersionOk( const string& ns , bool isWriteOp , string& errmsg ) {
if ( ! shardingState.enabled() )
return true;
ShardedConnectionInfo* info = ShardedConnectionInfo::get( false );
if ( ! info ) {
// this means the client has nothing sharded
// so this allows direct connections to do whatever they want
// which i think is the correct behavior
return true;
}
if ( info->inForceVersionOkMode() ) {
return true;
}
// TODO
// all collections at some point, be sharded or not, will have a version (and a ShardChunkManager)
// for now, we remove the sharding state of dropped collection
// so delayed request may come in. This has to be fixed.
ConfigVersion clientVersion = info->getVersion(ns);
ConfigVersion version;
if ( ! shardingState.hasVersion( ns , version ) && clientVersion == 0 ) {
return true;
}
if ( version == 0 && clientVersion > 0 ) {
stringstream ss;
ss << "collection was dropped or this shard no longer valied version: " << version << " clientVersion: " << clientVersion;
errmsg = ss.str();
return false;
}
if ( clientVersion >= version )
return true;
if ( clientVersion == 0 ) {
stringstream ss;
ss << "client in sharded mode, but doesn't have version set for this collection: " << ns << " myVersion: " << version;
errmsg = ss.str();
return false;
}
if ( version.majorVersion() == clientVersion.majorVersion() ) {
// this means there was just a split
// since on a split w/o a migrate this server is ok
// going to accept
return true;
}
stringstream ss;
ss << "your version is too old ns: " + ns << " global: " << version << " client: " << clientVersion;
errmsg = ss.str();
return false;
}
示例2: shardVersionOk
/**
* @ return true if not in sharded mode
or if version for this client is ok
*/
bool shardVersionOk( const string& ns , bool isWriteOp , string& errmsg ){
if ( ! shardingState.enabled() )
return true;
ShardedConnectionInfo* info = ShardedConnectionInfo::get( false );
if ( ! info ){
// this means the client has nothing sharded
// so this allows direct connections to do whatever they want
// which i think is the correct behavior
return true;
}
if ( info->inForceVersionOkMode() ){
return true;
}
ConfigVersion version;
if ( ! shardingState.hasVersion( ns , version ) ){
return true;
}
ConfigVersion clientVersion = info->getVersion(ns);
if ( version == 0 && clientVersion > 0 ){
stringstream ss;
ss << "collection was dropped or this shard no longer valied version: " << version << " clientVersion: " << clientVersion;
errmsg = ss.str();
return false;
}
if ( clientVersion >= version )
return true;
if ( clientVersion == 0 ){
stringstream ss;
ss << "client in sharded mode, but doesn't have version set for this collection: " << ns << " myVersion: " << version;
errmsg = ss.str();
return false;
}
if ( isWriteOp && version.majorVersion() == clientVersion.majorVersion() ){
// this means there was just a split
// since on a split w/o a migrate this server is ok
// going to accept write
return true;
}
stringstream ss;
ss << "your version is too old ns: " + ns << " global: " << version << " client: " << clientVersion;
errmsg = ss.str();
return false;
}
示例3: shardVersionOk
/**
* @ return true if not in sharded mode
or if version for this client is ok
*/
bool shardVersionOk( const string& ns , string& errmsg, ConfigVersion& received, ConfigVersion& wanted ) {
if ( ! shardingState.enabled() )
return true;
if ( ! isMasterNs( ns.c_str() ) ) {
// right now connections to secondaries aren't versioned at all
return true;
}
ShardedConnectionInfo* info = ShardedConnectionInfo::get( false );
if ( ! info ) {
// this means the client has nothing sharded
// so this allows direct connections to do whatever they want
// which i think is the correct behavior
return true;
}
if ( info->inForceVersionOkMode() ) {
return true;
}
// TODO
// all collections at some point, be sharded or not, will have a version (and a ShardChunkManager)
// for now, we remove the sharding state of dropped collection
// so delayed request may come in. This has to be fixed.
ConfigVersion clientVersion = info->getVersion(ns);
ConfigVersion version;
if ( ! shardingState.hasVersion( ns , version ) && ! clientVersion.isSet() ) {
return true;
}
// The versions we're going to compare, saved for future use
received = clientVersion;
wanted = version;
if ( ! version.isSet() && clientVersion.isSet() ) {
stringstream ss;
ss << "collection was dropped or this shard no longer valid version";
errmsg = ss.str();
return false;
}
if ( clientVersion >= version )
return true;
if ( ! clientVersion.isSet() ) {
stringstream ss;
ss << "client in sharded mode, but doesn't have version set for this collection";
errmsg = ss.str();
return false;
}
if ( version.majorVersion() == clientVersion.majorVersion() ) {
// this means there was just a split
// since on a split w/o a migrate this server is ok
// going to accept
return true;
}
stringstream ss;
ss << "your version is too old";
errmsg = ss.str();
return false;
}
示例4: shardVersionOk
/**
* @ return true if not in sharded mode
or if version for this client is ok
*/
bool shardVersionOk( const string& ns , string& errmsg, ChunkVersion& received, ChunkVersion& wanted ) {
if ( ! shardingState.enabled() )
return true;
if ( ! isMasterNs( ns.c_str() ) ) {
// right now connections to secondaries aren't versioned at all
return true;
}
ShardedConnectionInfo* info = ShardedConnectionInfo::get( false );
if ( ! info ) {
// this means the client has nothing sharded
// so this allows direct connections to do whatever they want
// which i think is the correct behavior
return true;
}
if ( info->inForceVersionOkMode() ) {
return true;
}
// TODO : all collections at some point, be sharded or not, will have a version
// (and a CollectionMetadata)
received = info->getVersion( ns );
wanted = shardingState.getVersion( ns );
if( received.isWriteCompatibleWith( wanted ) ) return true;
//
// Figure out exactly why not compatible, send appropriate error message
// The versions themselves are returned in the error, so not needed in messages here
//
// Check epoch first, to send more meaningful message, since other parameters probably
// won't match either
if( ! wanted.hasCompatibleEpoch( received ) ){
errmsg = str::stream() << "version epoch mismatch detected for " << ns << ", "
<< "the collection may have been dropped and recreated";
return false;
}
if( ! wanted.isSet() && received.isSet() ){
errmsg = str::stream() << "this shard no longer contains chunks for " << ns << ", "
<< "the collection may have been dropped";
return false;
}
if( wanted.isSet() && ! received.isSet() ){
errmsg = str::stream() << "this shard contains versioned chunks for " << ns << ", "
<< "but no version set in request";
return false;
}
if( wanted.majorVersion() != received.majorVersion() ){
//
// Could be > or < - wanted is > if this is the source of a migration,
// wanted < if this is the target of a migration
//
errmsg = str::stream() << "version mismatch detected for " << ns << ", "
<< "stored major version " << wanted.majorVersion()
<< " does not match received " << received.majorVersion();
return false;
}
// Those are all the reasons the versions can mismatch
verify( false );
return false;
}