Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

SERVER-6809 SERVER-6811 cleanup and add prefix sharding tests

  • Loading branch information...
commit 814e1526cae18e828c83ab4e6ce40ba8423cd1fe 1 parent 774bafe
matulef matulef authored
43 jstests/sharding/deletion_range.js
View
@@ -1,43 +0,0 @@
-//
-// Tests deletion ranges for a sharded system when using prefix shard key
-//
-
-var st = new ShardingTest({ shards : 2, mongos : 2 });
-
-st.stopBalancer();
-
-var mongos = st.s0;
-var config = mongos.getDB( "config" );
-var admin = mongos.getDB( "admin" );
-var shards = config.shards.find().toArray();
-var shard0 = new Mongo( shards[0].host );
-var shard1 = new Mongo( shards[1].host );
-
-var coll = mongos.getCollection( "foo.bar" );
-
-printjson( admin.runCommand({ enableSharding : coll.getDB() + "" }) );
-printjson( admin.runCommand({ movePrimary : coll.getDB() + "", to : shards[0]._id }) );
-printjson( coll.ensureIndex({ skey : 1, extra : 1 }) );
-printjson( admin.runCommand({ shardCollection : coll + "", key : { skey : 1 } }) );
-
-for( var i = 0; i < 5; i++ ){
- coll.insert({ skey : 0, extra : i });
-}
-assert.eq( null, coll.getDB().getLastError() );
-
-printjson( admin.runCommand({ split : coll + "", middle : { skey : 0 } }) );
-printjson( admin.runCommand({ moveChunk : coll + "", find : { skey : 0 }, to : shards[1]._id }) );
-
-printjson( shard0.getCollection( coll + "" ).find().toArray() );
-printjson( shard1.getCollection( coll + "" ).find().toArray() );
-
-assert( coll.find().itcount() == 5 );
-
-printjson( admin.runCommand({ moveChunk : coll + "", find : { skey : -1 }, to : shards[1]._id }) );
-
-assert.eq( 0 , shard0.getCollection( coll + "" ).find().itcount() );
-assert.eq( 5 , shard1.getCollection( coll + "" ).find().itcount() );
-
-assert( coll.find().itcount() == 5 );
-
-st.stop()
77 jstests/sharding/prefix_shard_key.js
View
@@ -1,14 +1,28 @@
-// Test that you can shard and move chunks around with a shard key that's
-// only a prefix of an existing index
+// Test that you can shard with shard key that's only a prefix of an existing index.
+//
+// Part 1: Shard new collection on {num : 1} with an index on {num : 1, x : 1}.
+// Test that you can split and move chunks around.
+// Part 2: Test that adding an array value for x makes it unusuable. Deleting the
+// array value and re-indexing makes it usable again.
+// Part 3: Shard new collection on {skey : 1} but with a longer index.
+// Insert docs with same val for 'skey' but different vals for 'extra'.
+// Move chunks around and check that [min,max) chunk boundaries are properly obeyed.
var s = new ShardingTest({ name : jsTestName(), shards : 2 });
var db = s.getDB( "test" );
var admin = s.getDB( "admin" );
-var coll = db.foo;
+var config = s.getDB( "config" );
+var shards = config.shards.find().toArray();
+var shard0 = new Mongo( shards[0].host );
+var shard1 = new Mongo( shards[1].host );
s.adminCommand( { enablesharding : "test" } );
+//******************Part 1********************
+
+var coll = db.foo;
+
var longStr = 'a';
while ( longStr.length < 1024 * 128 ) { longStr += longStr; }
for( i=0 ; i<100; i++){
@@ -54,6 +68,8 @@ printjson( result3 );
assert.eq( 1, result3.ok , "moveChunk didn't succeed");
+//******************Part 2********************
+
// Test that inserting array values fails because we don't support multi-key indexes for the shard key
coll.save({ num : [1,2], x : 1});
err = db.getLastError();
@@ -76,5 +92,60 @@ var result4 = admin.runCommand( { movechunk : coll.getFullName() , find : { num
printjson( result4 );
assert.eq( 1, result4.ok , "moveChunk failed after rebuilding index");
+//******************Part 3********************
+
+// Check chunk boundaries obeyed when using prefix shard key.
+// This test repeats with shard key as the prefix of different longer indices.
+
+for( i=0; i < 3; i++ ){
+
+ // setup new collection on shard0
+ var coll2 = db.foo2;
+ coll2.drop();
+ var moveRes = admin.runCommand( { movePrimary : coll2.getDB() + "", to : shards[0]._id } );
+ assert.eq( moveRes.ok , 1 , "primary not moved correctly" );
+
+ // declare a longer index
+ if ( i == 0 ) {
+ coll2.ensureIndex( { skey : 1, extra : 1 } );
+ }
+ else if ( i == 1 ) {
+ coll2.ensureIndex( { skey : 1, extra : -1 } );
+ }
+ else if ( i == 2 ) {
+ coll2.ensureIndex( { skey : 1, extra : 1 , superfluous : -1 } );
+ }
+ db.getLastError();
+
+ // then shard collection on prefix
+ var shardRes = admin.runCommand( { shardCollection : coll2 + "", key : { skey : 1 } } );
+ assert.eq( shardRes.ok , 1 , "collection not sharded" );
+
+ // insert docs with same value for skey
+ for( var i = 0; i < 5; i++ ){
+ for( var j = 0; j < 5; j++ ){
+ coll2.insert( { skey : 0, extra : i , superfluous : j } );
+ }
+ }
+ assert.eq( null, coll2.getDB().getLastError() , "inserts didn't work" );
+
+ // split on that key, and check it makes 2 chunks
+ var splitRes = admin.runCommand( { split : coll2 + "", middle : { skey : 0 } } );
+ assert.eq( splitRes.ok , 1 , "split didn't work" );
+ assert.eq( config.chunks.find( { ns : coll2.getFullName() } ).count() , 2 );
+
+ // movechunk should move ALL docs since they have same value for skey
+ var moveRes = admin.runCommand( { moveChunk : coll2 + "", find : { skey : 0 }, to : shards[1]._id } );
+ assert.eq( moveRes.ok , 1 , "movechunk didn't work" );
+
+ // check no orphaned docs on the shards
+ assert.eq( 0 , shard0.getCollection( coll2 + "" ).find().itcount() );
+ assert.eq( 25 , shard1.getCollection( coll2 + "" ).find().itcount() );
+
+ // and check total
+ assert.eq( 25 , coll2.find().itcount() , "bad total number of docs after move" );
+
+ db.printShardingStatus();
+}
s.stop();
24 jstests/splitvector.js
View
@@ -258,23 +258,47 @@ f.ensureIndex( { x: 1, y: 1 } );
case4();
f.drop();
+f.ensureIndex( { x: 1, y: -1 , z : 1 } );
+case4();
+
+f.drop();
f.ensureIndex( { x: 1, y: 1 } );
case5();
f.drop();
+f.ensureIndex( { x: 1, y: -1 , z : 1 } );
+case5();
+
+f.drop();
f.ensureIndex( { x: 1, y: 1 } );
case6();
f.drop();
+f.ensureIndex( { x: 1, y: -1 , z : 1 } );
+case6();
+
+f.drop();
f.ensureIndex( { x: 1, y: 1 } );
case7();
f.drop();
+f.ensureIndex( { x: 1, y: -1 , z : 1 } );
+case7();
+
+f.drop();
f.ensureIndex( { x: 1, y: 1 } );
case8();
f.drop();
+f.ensureIndex( { x: 1, y: -1 , z : 1 } );
+case8();
+
+f.drop();
f.ensureIndex( { x: 1, y: 1 } );
case9();
+f.drop();
+f.ensureIndex( { x: 1, y: -1 , z : 1 } );
+case9();
+
print("PASSED");
Please sign in to comment.
Something went wrong with that request. Please try again.