本文整理汇总了C++中Shard::getFilter方法的典型用法代码示例。如果您正苦于以下问题:C++ Shard::getFilter方法的具体用法?C++ Shard::getFilter怎么用?C++ Shard::getFilter使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Shard
的用法示例。
在下文中一共展示了Shard::getFilter方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: queryOp
virtual void queryOp( Request& r ){
QueryMessage q( r.d() );
log(3) << "shard query: " << q.ns << " " << q.query << endl;
if ( q.ntoreturn == 1 && strstr(q.ns, ".$cmd") )
throw UserException( "something is wrong, shouldn't see a command here" );
ShardManager * info = r.getShardManager();
assert( info );
Query query( q.query );
vector<Shard*> shards;
info->getShardsForQuery( shards , query.getFilter() );
set<ServerAndQuery> servers;
map<string,int> serverCounts;
for ( vector<Shard*>::iterator i = shards.begin(); i != shards.end(); i++ ){
servers.insert( (*i)->getServer() );
int& num = serverCounts[(*i)->getServer()];
num++;
}
ShardedCursor * cursor = 0;
BSONObj sort = query.getSort();
if ( sort.isEmpty() ){
// 1. no sort, can just hit them in serial
cursor = new SerialServerShardedCursor( servers , q );
}
else {
int shardKeyOrder = info->getShardKey().canOrder( sort );
if ( shardKeyOrder ){
// 2. sort on shard key, can do in serial intelligently
set<ServerAndQuery> buckets;
for ( vector<Shard*>::iterator i = shards.begin(); i != shards.end(); i++ ){
Shard * s = *i;
BSONObj extra = BSONObj();
if ( serverCounts[s->getServer()] > 1 ){
BSONObjBuilder b;
s->getFilter( b );
extra = b.obj();
}
buckets.insert( ServerAndQuery( s->getServer() , extra , s->getMin() ) );
}
cursor = new SerialServerShardedCursor( buckets , q , shardKeyOrder );
}
else {
// 3. sort on non-sharded key, pull back a portion from each server and iterate slowly
cursor = new ParallelSortShardedCursor( servers , q , sort );
}
}
assert( cursor );
if ( ! cursor->sendNextBatch( r ) ){
delete( cursor );
return;
}
log(6) << "storing cursor : " << cursor->getId() << endl;
cursorCache.store( cursor );
}