0
0
mirror of https://github.com/mongodb/mongo.git synced 2024-12-01 09:32:32 +01:00

ChunkMatcher compound key support SERVER-951

This commit is contained in:
Mathias Stearn 2010-07-14 12:30:26 -04:00
parent 38c27222e7
commit 72bab0e0d2
2 changed files with 16 additions and 7 deletions

View File

@ -30,9 +30,6 @@ namespace mongo {
// ----------- // -----------
/**
* TODO: this only works with single fields at the moment
*/
class ChunkMatcher { class ChunkMatcher {
typedef map<BSONObj,pair<BSONObj,BSONObj>,BSONObjCmp> MyMap; typedef map<BSONObj,pair<BSONObj,BSONObj>,BSONObjCmp> MyMap;
public: public:
@ -45,7 +42,7 @@ namespace mongo {
void gotRange( const BSONObj& min , const BSONObj& max ); void gotRange( const BSONObj& min , const BSONObj& max );
ConfigVersion _version; ConfigVersion _version;
string _field; BSONObj _key;
MyMap _map; MyMap _map;
friend class ShardingState; friend class ShardingState;

View File

@ -541,8 +541,20 @@ namespace mongo {
} }
void ChunkMatcher::gotRange( const BSONObj& min , const BSONObj& max ){ void ChunkMatcher::gotRange( const BSONObj& min , const BSONObj& max ){
assert( min.nFields() == 1 ); if (_key.isEmpty()){
_field = min.firstElement().fieldName(); BSONObjBuilder b;
BSONForEach(e, min) {
b.append(e.fieldName(), 1);
}
_key = b.obj();
}
//TODO debug mode only?
assert(min.nFields() == _key.nFields());
assert(max.nFields() == _key.nFields());
_map[min] = make_pair(min,max); _map[min] = make_pair(min,max);
} }
@ -550,7 +562,7 @@ namespace mongo {
if ( _map.size() == 0 ) if ( _map.size() == 0 )
return false; return false;
BSONObj x = loc.obj().getFieldDotted( _field.c_str() ).wrap( _field.c_str() ); // TODO: this is slow BSONObj x = loc.obj().extractFieldsDotted(_key);
MyMap::const_iterator a = _map.upper_bound( x ); MyMap::const_iterator a = _map.upper_bound( x );
a--; a--;