mirror of
https://github.com/mongodb/mongo.git
synced 2024-12-01 09:32:32 +01:00
use ClientCursor::extractKeys so can use covered index if possible
This commit is contained in:
parent
5696b25f0a
commit
317c3a4e3b
@ -161,7 +161,7 @@ namespace mongo {
|
||||
// in some cases (clone collection) there won't be a matcher
|
||||
if ( c->matcher() && !c->matcher()->matchesCurrent( c ) ) {
|
||||
}
|
||||
else if ( manager && ! manager->belongsToMe( c->currLoc().obj() ) ){
|
||||
else if ( manager && ! manager->belongsToMe( cc ) ){
|
||||
LOG(2) << "cursor skipping document in un-owned chunk: " << c->current() << endl;
|
||||
}
|
||||
else {
|
||||
@ -592,7 +592,7 @@ namespace mongo {
|
||||
else {
|
||||
_nscannedObjects++;
|
||||
DiskLoc cl = _c->currLoc();
|
||||
if ( _chunkManager && ! _chunkManager->belongsToMe( cl.obj() ) ) {
|
||||
if ( _chunkManager && ! _chunkManager->belongsToMe( cl.obj() ) ) { // TODO: should make this covered at some point
|
||||
_nChunkSkips++;
|
||||
// log() << "TEMP skipping un-owned chunk: " << _c->current() << endl;
|
||||
}
|
||||
|
@ -21,6 +21,7 @@
|
||||
#include "../client/connpool.h"
|
||||
#include "../client/dbclientmockcursor.h"
|
||||
#include "../db/instance.h"
|
||||
#include "../db/clientcursor.h"
|
||||
|
||||
#include "d_chunk_manager.h"
|
||||
|
||||
@ -136,12 +137,22 @@ namespace mongo {
|
||||
static bool contains( const BSONObj& min , const BSONObj& max , const BSONObj& point ) {
|
||||
return point.woCompare( min ) >= 0 && point.woCompare( max ) < 0;
|
||||
}
|
||||
|
||||
bool ShardChunkManager::belongsToMe( ClientCursor* cc ) const {
|
||||
if ( _rangesMap.size() == 0 )
|
||||
return false;
|
||||
|
||||
return _belongsToMe( cc->extractFields( _key ) );
|
||||
}
|
||||
|
||||
bool ShardChunkManager::belongsToMe( const BSONObj& obj ) const {
|
||||
if ( _rangesMap.size() == 0 )
|
||||
return false;
|
||||
|
||||
BSONObj x = obj.extractFields(_key);
|
||||
return _belongsToMe( obj.extractFields( _key ) );
|
||||
}
|
||||
|
||||
bool ShardChunkManager::_belongsToMe( const BSONObj& x ) const {
|
||||
|
||||
RangeMap::const_iterator it = _rangesMap.upper_bound( x );
|
||||
if ( it != _rangesMap.begin() )
|
||||
|
@ -25,6 +25,8 @@
|
||||
|
||||
namespace mongo {
|
||||
|
||||
class ClientCursor;
|
||||
|
||||
/**
|
||||
* Controls the boundaries of all the chunks for a given collection that live in this shard.
|
||||
*
|
||||
@ -101,6 +103,14 @@ namespace mongo {
|
||||
*/
|
||||
bool belongsToMe( const BSONObj& obj ) const;
|
||||
|
||||
/**
|
||||
* Checks whether a document belongs to this shard.
|
||||
*
|
||||
* @param obj document containing sharding keys (and, optionally, other attributes)
|
||||
* @return true if shards hold the object
|
||||
*/
|
||||
bool belongsToMe( ClientCursor* cc ) const;
|
||||
|
||||
/**
|
||||
* Given a chunk's min key (or empty doc), gets the boundary of the chunk following that one (the first).
|
||||
*
|
||||
@ -119,6 +129,13 @@ namespace mongo {
|
||||
|
||||
string toString() const;
|
||||
private:
|
||||
|
||||
/**
|
||||
* @same as belongsToMe to but key has to be the shard key
|
||||
*/
|
||||
bool _belongsToMe( const BSONObj& key ) const;
|
||||
|
||||
|
||||
// highest ShardChunkVersion for which this ShardChunkManager's information is accurate
|
||||
ShardChunkVersion _version;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user