summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEliot Horowitz <eliot@10gen.com>2011-03-01 13:20:54 -0500
committerEliot Horowitz <eliot@10gen.com>2011-03-01 13:21:26 -0500
commit13608bb28320625c31c49f2cae9489874c4f295b (patch)
tree367e89e8796d4ec12dd43112696f02042c2a39e5
parent83282b72fab32cabeb160ec03c56d63f297b905e (diff)
downloadmongo-13608bb28320625c31c49f2cae9489874c4f295b.tar.gz
null is ok in shard key, blank is not SERVER-2648
-rw-r--r--jstests/check_shard_index.js9
-rw-r--r--s/d_split.cpp35
2 files changed, 34 insertions, 10 deletions
diff --git a/jstests/check_shard_index.js b/jstests/check_shard_index.js
index af8a115836e..a5a1fc14c47 100644
--- a/jstests/check_shard_index.js
+++ b/jstests/check_shard_index.js
@@ -32,9 +32,14 @@ f.ensureIndex( { x: 1 , y: 1 } );
assert.eq( 0 , f.count() , "2. initial count should be zero" );
f.save( { x: 1 , y : 1 } );
+f.save( { x: null , y : 1 } );
+
+res = db.runCommand( { checkShardingIndex: "test.jstests_shardingindex" , keyPattern: {x:1, y:1} , force: true });
+assert.eq( true , res.ok , "2a " + tojson(res) );
+
f.save( { y: 2 } );
-assert.eq( 2 , f.count() , "2. count after initial insert should be 2" );
+assert.eq( 3 , f.count() , "2. count after initial insert should be 3" );
res = db.runCommand( { checkShardingIndex: "test.jstests_shardingindex" , keyPattern: {x:1, y:1} , force: true });
-assert.eq( false , res.ok , "2a" );
+assert.eq( false , res.ok , "2b " + tojson(res) );
print("PASSED");
diff --git a/s/d_split.cpp b/s/d_split.cpp
index 1db1c29b0e0..a2e92f9be3e 100644
--- a/s/d_split.cpp
+++ b/s/d_split.cpp
@@ -178,18 +178,37 @@ namespace mongo {
}
// for now, the only check is that all shard keys are filled
+ // null is ok,
// TODO if $exist for nulls were picking the index, it could be used instead efficiently
while ( cc->ok() ) {
BSONObj currKey = c->currKey();
- BSONForEach(key, currKey) {
- if ( key.type() == jstNULL ) {
- ostringstream os;
- os << "found null value in key " << bc->prettyKey( currKey );
- log() << "checkShardingIndex for '" << ns << "' failed: " << os.str() << endl;
+
+ BSONObjIterator i( currKey );
+ int n = 0;
+ while ( i.more() ) {
+ BSONElement key = i.next();
+ n++;
+
+ if ( key.type() && key.type() != jstNULL )
+ continue;
+
+ BSONObj obj = c->current();
+ BSONObjIterator j( keyPattern );
+ BSONElement real;
+ for ( int x=0; x<n; x++ )
+ real = j.next();
+
+ real = obj.getFieldDotted( real.fieldName() );
- errmsg = os.str();
- return false;
- }
+ if ( real.type() )
+ continue;
+
+ ostringstream os;
+ os << "found null value in key " << bc->prettyKey( currKey ) << " for doc: " << real["_id"];
+ log() << "checkShardingIndex for '" << ns << "' failed: " << os.str() << endl;
+
+ errmsg = os.str();
+ return false;
}
cc->advance();
}