Skip to content

Commit

Permalink
backport of SERVER-4612 - fix chhunk boundary checking on idhack queries
Browse files Browse the repository at this point in the history
  • Loading branch information
erh committed Mar 2, 2012
1 parent 32cc883 commit 816af21
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
13 changes: 13 additions & 0 deletions db/ops/query.cpp
Expand Up @@ -916,6 +916,19 @@ namespace mongo {
Client& c = cc(); Client& c = cc();
bool found = Helpers::findById( c, ns , query , resObject , &nsFound , &indexFound ); bool found = Helpers::findById( c, ns , query , resObject , &nsFound , &indexFound );
if ( nsFound == false || indexFound == true ) { if ( nsFound == false || indexFound == true ) {

if ( shardingState.needShardChunkManager( ns ) ) {
ShardChunkManagerPtr m = shardingState.getShardChunkManager( ns );
if ( m && ! m->belongsToMe( resObject ) ) {
// I have something this _id
// but it doesn't belong to me
// so return nothing
resObject = BSONObj();
found = false;
}
}


BufBuilder bb(sizeof(QueryResult)+resObject.objsize()+32); BufBuilder bb(sizeof(QueryResult)+resObject.objsize()+32);
bb.skip(sizeof(QueryResult)); bb.skip(sizeof(QueryResult));


Expand Down
8 changes: 7 additions & 1 deletion jstests/sharding/shard3.js
Expand Up @@ -61,14 +61,20 @@ function doCounts( name , total , onlyItCounts ){
} }


var total = doCounts( "before wrong save" ) var total = doCounts( "before wrong save" )
secondary.save( { num : -3 } ); secondary.save( { _id : 111 , num : -3 } );
printjson( secondary.getDB().getLastError() ) printjson( secondary.getDB().getLastError() )
doCounts( "after wrong save" , total , true ) doCounts( "after wrong save" , total , true )
e = a.find().explain(); e = a.find().explain();
assert.eq( 3 , e.n , "ex1" ) assert.eq( 3 , e.n , "ex1" )
assert.eq( 4 , e.nscanned , "ex2" ) assert.eq( 4 , e.nscanned , "ex2" )
assert.eq( 1 , e.nChunkSkips , "ex3" ) assert.eq( 1 , e.nChunkSkips , "ex3" )



// SERVER-4612
// make sure idhack obeys chunks
x = a.findOne( { _id : 111 } )
assert( ! x , "idhack didn't obey chunk boundaries " + tojson(x) );

// --- move all to 1 --- // --- move all to 1 ---
print( "MOVE ALL TO 1" ); print( "MOVE ALL TO 1" );


Expand Down

0 comments on commit 816af21

Please sign in to comment.