本文整理汇总了C++中DbMessage::msg方法的典型用法代码示例。如果您正苦于以下问题:C++ DbMessage::msg方法的具体用法?C++ DbMessage::msg怎么用?C++ DbMessage::msg使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DbMessage
的用法示例。
在下文中一共展示了DbMessage::msg方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: _update
void _update( Request& r , DbMessage& d, ChunkManager* manager ){
int flags = d.pullInt();
BSONObj query = d.nextJsObj();
uassert( 10201 , "invalid update" , d.moreJSObjs() );
BSONObj toupdate = d.nextJsObj();
BSONObj chunkFinder = query;
bool upsert = flags & UpdateOption_Upsert;
bool multi = flags & UpdateOption_Multi;
if ( multi )
uassert( 10202 , "can't mix multi and upsert and sharding" , ! upsert );
if ( upsert && !(manager->hasShardKey(toupdate) ||
(toupdate.firstElement().fieldName()[0] == '$' && manager->hasShardKey(query))))
{
throw UserException( 8012 , "can't upsert something without shard key" );
}
bool save = false;
if ( ! manager->hasShardKey( query ) ){
if ( multi ){
}
else if ( query.nFields() != 1 || strcmp( query.firstElement().fieldName() , "_id" ) ){
throw UserException( 8013 , "can't do update with query that doesn't have the shard key" );
}
else {
save = true;
chunkFinder = toupdate;
}
}
if ( ! save ){
if ( toupdate.firstElement().fieldName()[0] == '$' ){
// TODO: check for $set, etc.. on shard key
}
else if ( manager->hasShardKey( toupdate ) && manager->getShardKey().compare( query , toupdate ) ){
throw UserException( 8014 , "change would move shards!" );
}
}
if ( multi ){
vector<Chunk*> chunks;
manager->getChunksForQuery( chunks , chunkFinder );
set<string> seen;
for ( vector<Chunk*>::iterator i=chunks.begin(); i!=chunks.end(); i++){
Chunk * c = *i;
if ( seen.count( c->getShard() ) )
continue;
doWrite( dbUpdate , r , c->getShard() );
seen.insert( c->getShard() );
}
}
else {
Chunk& c = manager->findChunk( chunkFinder );
doWrite( dbUpdate , r , c.getShard() );
c.splitIfShould( d.msg().data->dataLen() );
}
}
示例2: _update
void _update( Request& r , DbMessage& d, ChunkManagerPtr manager ){
int flags = d.pullInt();
BSONObj query = d.nextJsObj();
uassert( 10201 , "invalid update" , d.moreJSObjs() );
BSONObj toupdate = d.nextJsObj();
BSONObj chunkFinder = query;
bool upsert = flags & UpdateOption_Upsert;
bool multi = flags & UpdateOption_Multi;
uassert( 10202 , "can't mix multi and upsert and sharding" , ! ( upsert && multi ) );
if ( upsert && !(manager->hasShardKey(toupdate) ||
(toupdate.firstElement().fieldName()[0] == '$' && manager->hasShardKey(query))))
{
throw UserException( 8012 , "can't upsert something without shard key" );
}
bool save = false;
if ( ! manager->hasShardKey( query ) ){
if ( multi ){
}
else if ( strcmp( query.firstElement().fieldName() , "_id" ) || query.nFields() != 1 ){
throw UserException( 8013 , "can't do non-multi update with query that doesn't have the shard key" );
}
else {
save = true;
chunkFinder = toupdate;
}
}
if ( ! save ){
if ( toupdate.firstElement().fieldName()[0] == '$' ){
BSONObjIterator ops(toupdate);
while(ops.more()){
BSONElement op(ops.next());
if (op.type() != Object)
continue;
BSONObjIterator fields(op.embeddedObject());
while(fields.more()){
const string field = fields.next().fieldName();
uassert(13123, "Can't modify shard key's value", ! manager->getShardKey().partOfShardKey(field));
}
}
} else if ( manager->hasShardKey( toupdate ) ){
uassert( 8014, "change would move shards!", manager->getShardKey().compare( query , toupdate ) == 0 );
} else {
uasserted(12376, "shard key must be in update object");
}
}
if ( multi ){
set<Shard> shards;
manager->getShardsForQuery( shards , chunkFinder );
int * x = (int*)(r.d().afterNS());
x[0] |= UpdateOption_Broadcast;
for ( set<Shard>::iterator i=shards.begin(); i!=shards.end(); i++){
doWrite( dbUpdate , r , *i , false );
}
}
else {
int left = 5;
while ( true ){
try {
ChunkPtr c = manager->findChunk( chunkFinder );
doWrite( dbUpdate , r , c->getShard() );
c->splitIfShould( d.msg().header()->dataLen() );
break;
}
catch ( StaleConfigException& e ){
if ( left <= 0 )
throw e;
left--;
log() << "update failed b/c of StaleConfigException, retrying "
<< " left:" << left << " ns: " << r.getns() << " query: " << query << endl;
r.reset( false );
manager = r.getChunkManager();
}
}
}
}
示例3: _update
void _update( Request& r , DbMessage& d, ChunkManagerPtr manager ){
int flags = d.pullInt();
BSONObj query = d.nextJsObj();
uassert( 10201 , "invalid update" , d.moreJSObjs() );
BSONObj toupdate = d.nextJsObj();
BSONObj chunkFinder = query;
bool upsert = flags & UpdateOption_Upsert;
bool multi = flags & UpdateOption_Multi;
if ( multi )
uassert( 10202 , "can't mix multi and upsert and sharding" , ! upsert );
if ( upsert && !(manager->hasShardKey(toupdate) ||
(toupdate.firstElement().fieldName()[0] == '$' && manager->hasShardKey(query))))
{
throw UserException( 8012 , "can't upsert something without shard key" );
}
bool save = false;
if ( ! manager->hasShardKey( query ) ){
if ( multi ){
}
else if ( query.nFields() != 1 || strcmp( query.firstElement().fieldName() , "_id" ) ){
throw UserException( 8013 , "can't do update with query that doesn't have the shard key" );
}
else {
save = true;
chunkFinder = toupdate;
}
}
if ( ! save ){
if ( toupdate.firstElement().fieldName()[0] == '$' ){
BSONObjIterator ops(toupdate);
while(ops.more()){
BSONElement op(ops.next());
if (op.type() != Object)
continue;
BSONObjIterator fields(op.embeddedObject());
while(fields.more()){
const string field = fields.next().fieldName();
uassert(13123, "Can't modify shard key's value", ! manager->getShardKey().partOfShardKey(field));
}
}
} else if ( manager->hasShardKey( toupdate ) ){
uassert( 8014, "change would move shards!", manager->getShardKey().compare( query , toupdate ) == 0 );
} else {
uasserted(12376, "shard key must be in update object");
}
}
if ( multi ){
vector<shared_ptr<ChunkRange> > chunks;
manager->getChunksForQuery( chunks , chunkFinder );
set<Shard> seen;
for ( vector<shared_ptr<ChunkRange> >::iterator i=chunks.begin(); i!=chunks.end(); i++){
shared_ptr<ChunkRange> c = *i;
if ( seen.count( c->getShard() ) )
continue;
doWrite( dbUpdate , r , c->getShard() );
seen.insert( c->getShard() );
}
}
else {
ChunkPtr c = manager->findChunk( chunkFinder );
doWrite( dbUpdate , r , c->getShard() );
c->splitIfShould( d.msg().header()->dataLen() );
}
}