Permalink
Browse files

backport of SERVER-4612 - fix chhunk boundary checking on idhack queries

  • Loading branch information...
1 parent 32cc883 commit 816af2185cb85726bf47f4be724bb58ece20703f @erh erh committed Mar 2, 2012
Showing with 20 additions and 1 deletion.
  1. +13 −0 db/ops/query.cpp
  2. +7 −1 jstests/sharding/shard3.js
View
@@ -916,6 +916,19 @@ namespace mongo {
Client& c = cc();
bool found = Helpers::findById( c, ns , query , resObject , &nsFound , &indexFound );
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);
bb.skip(sizeof(QueryResult));
@@ -61,14 +61,20 @@ function doCounts( name , total , onlyItCounts ){
}
var total = doCounts( "before wrong save" )
-secondary.save( { num : -3 } );
+secondary.save( { _id : 111 , num : -3 } );
printjson( secondary.getDB().getLastError() )
doCounts( "after wrong save" , total , true )
e = a.find().explain();
assert.eq( 3 , e.n , "ex1" )
assert.eq( 4 , e.nscanned , "ex2" )
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 ---
print( "MOVE ALL TO 1" );

0 comments on commit 816af21

Please sign in to comment.