Skip to content

Commit

Permalink
simplify getShardsForQuery and getShardsForRange
Browse files Browse the repository at this point in the history
  • Loading branch information
matulef committed Dec 27, 2012
1 parent 871d874 commit 68ab858
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 14 deletions.
17 changes: 5 additions & 12 deletions src/mongo/s/chunk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1118,13 +1118,9 @@ namespace mongo {

if ( frsp->matchPossibleForSingleKeyFRS( _key.key() ) ) {
BoundList ranges = _key.keyBounds( frsp->getSingleKeyFRS() );
for (BoundList::const_iterator it=ranges.begin(), end=ranges.end();
it != end; ++it) {
for ( BoundList::const_iterator it=ranges.begin(); it != ranges.end(); ++it ){

BSONObj minObj = it->first.replaceFieldNames(_key.key());
BSONObj maxObj = it->second.replaceFieldNames(_key.key());

getShardsForRange( shards, minObj, maxObj, false );
getShardsForRange( shards, it->first /*min*/, it->second /*max*/ );

// once we know we need to visit all shards no need to keep looping
if( shards.size() == _shards.size() ) return;
Expand All @@ -1146,12 +1142,9 @@ namespace mongo {
}
}

void ChunkManager::getShardsForRange(set<Shard>& shards, const BSONObj& min, const BSONObj& max, bool fullKeyReq ) const {

if( fullKeyReq ){
uassert(13405, str::stream() << "min value " << min << " does not have shard key", hasShardKey(min));
uassert(13406, str::stream() << "max value " << max << " does not have shard key", hasShardKey(max));
}
void ChunkManager::getShardsForRange( set<Shard>& shards,
const BSONObj& min,
const BSONObj& max ) const {

ChunkRangeMap::const_iterator it = _chunkRanges.upper_bound(min);
ChunkRangeMap::const_iterator end = _chunkRanges.upper_bound(max);
Expand Down
2 changes: 1 addition & 1 deletion src/mongo/s/chunk.h
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ namespace mongo {
void getShardsForQuery( set<Shard>& shards , const BSONObj& query ) const;
void getAllShards( set<Shard>& all ) const;
/** @param shards set to the shards covered by the interval [min, max], see SERVER-4791 */
void getShardsForRange(set<Shard>& shards, const BSONObj& min, const BSONObj& max, bool fullKeyReq = true) const;
void getShardsForRange( set<Shard>& shards, const BSONObj& min, const BSONObj& max ) const;

ChunkMap getChunkMap() const { return _chunkMap; }

Expand Down
7 changes: 6 additions & 1 deletion src/mongo/s/commands_public.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -879,7 +879,12 @@ namespace mongo {
BSONObj max = cmdObj.getObjectField( "max" );
BSONObj keyPattern = cmdObj.getObjectField( "keyPattern" );

uassert(13408, "keyPattern must equal shard key", cm->getShardKey().key() == keyPattern);
uassert( 13408, "keyPattern must equal shard key",
cm->getShardKey().key() == keyPattern );
uassert( 13405, str::stream() << "min value " << min << " does not have shard key",
cm->hasShardKey(min) );
uassert( 13406, str::stream() << "max value " << max << " does not have shard key",
cm->hasShardKey(max) );

// yes these are doubles...
double size = 0;
Expand Down

0 comments on commit 68ab858

Please sign in to comment.