Skip to content

Commit

Permalink
SERVER-2060 test for null values at shardcollection time
Browse files Browse the repository at this point in the history
  • Loading branch information
Alberto Lerner committed Jan 10, 2011
1 parent d1d3df7 commit 6a6ad16
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
10 changes: 10 additions & 0 deletions jstests/sharding/features1.js
Expand Up @@ -160,8 +160,18 @@ assert.throws( function(){ db.foo6.group( { key : { a : 1 } , initial : { count
// ---- can't shard non-empty collection without index -----

db.foo8.save( { a : 1 } );
db.getLastError();
assert( ! s.admin.runCommand( { shardcollection : "test.foo8" , key : { a : 1 } } ).ok , "non-empty collection" );


// ---- can't shard non-empty collection with null values in shard key ----

db.foo9.save( { b : 1 } );
db.getLastError();
db.foo9.ensureIndex( { a : 1 } );
assert( ! s.admin.runCommand( { shardcollection : "test.foo9" , key : { a : 1 } } ).ok , "entry with null value" );


// --- listDatabases ---

r = db.getMongo().getDBs()
Expand Down
14 changes: 14 additions & 0 deletions s/commands_admin.cpp
Expand Up @@ -399,8 +399,22 @@ namespace mongo {
return false;
}

if ( hasShardIndex ) {
// make sure there are no null entries in the sharding index
BSONObjBuilder cmd;
cmd.append( "checkShardingIndex" , ns );
cmd.append( "keyPattern" , key );
BSONObj cmdObj = cmd.obj();
if ( ! conn->runCommand( "admin" , cmdObj , res )) {
errmsg = res["errmsg"].str();
conn.done();
return false;
}
}

if ( ! hasShardIndex && ( conn->count( ns ) != 0 ) ) {
errmsg = "please create an index over the sharding key before sharding.";
conn.done();
return false;
}

Expand Down

0 comments on commit 6a6ad16

Please sign in to comment.