summaryrefslogtreecommitdiff
path: root/jstests/sharding/split_with_force_small.js
diff options
context:
space:
mode:
authorGreg Studer <greg@10gen.com>2013-07-20 13:59:57 -0400
committerGreg Studer <greg@10gen.com>2013-07-22 17:39:15 -0400
commitb51ad40a7b582baea1ba25b46020f6b4275878e9 (patch)
tree59a20ab285c86f85cfc7e4257730fea2d1eaa505 /jstests/sharding/split_with_force_small.js
parent3cf081b971bc0bc8efccf1b9591e95ec71a42d7c (diff)
downloadmongo-b51ad40a7b582baea1ba25b46020f6b4275878e9.tar.gz
SERVER-9365 make forced halfway split work with chunks with many docs
Additional test fixes.
Diffstat (limited to 'jstests/sharding/split_with_force_small.js')
-rw-r--r--jstests/sharding/split_with_force_small.js68
1 files changed, 68 insertions, 0 deletions
diff --git a/jstests/sharding/split_with_force_small.js b/jstests/sharding/split_with_force_small.js
new file mode 100644
index 00000000000..02abfe6230e
--- /dev/null
+++ b/jstests/sharding/split_with_force_small.js
@@ -0,0 +1,68 @@
+//
+// Tests autosplit locations with force : true, for small collections
+//
+
+var options = { separateConfig : true,
+ chunksize : 1, // MB
+ mongosOptions : { noAutoSplit : "" }
+ };
+
+var st = new ShardingTest({ shards : 1, mongos : 1, other : options });
+st.stopBalancer();
+
+var mongos = st.s0;
+var admin = mongos.getDB( "admin" );
+var config = mongos.getDB( "config" );
+var shardAdmin = st.shard0.getDB( "admin" );
+var coll = mongos.getCollection( "foo.bar" );
+
+assert( admin.runCommand({ enableSharding : coll.getDB() + "" }).ok );
+assert( admin.runCommand({ shardCollection : coll + "", key : { _id : 1 } }).ok );
+assert( admin.runCommand({ split : coll + "", middle : { _id : 0 } }).ok );
+
+jsTest.log( "Insert a bunch of data into the low chunk of a collection," +
+ " to prevent relying on stats." );
+
+var data128k = "x";
+for ( var i = 0; i < 7; i++ ) data128k += data128k;
+
+for ( var i = 0; i < 1024; i++ ) {
+ coll.insert({ _id : -(i + 1) });
+}
+assert.eq( null, coll.getDB().getLastError() );
+
+jsTest.log( "Insert 32 docs into the high chunk of a collection" );
+
+for ( var i = 0; i < 32; i++ ) {
+ coll.insert({ _id : i });
+}
+assert.eq( null, coll.getDB().getLastError() );
+
+jsTest.log( "Split off MaxKey chunk..." );
+
+assert( admin.runCommand({ split : coll + "", middle : { _id : 32 } }).ok );
+
+jsTest.log( "Keep splitting chunk multiple times..." );
+
+st.printShardingStatus();
+
+for ( var i = 0; i < 5; i++ ) {
+ assert( admin.runCommand({ split : coll + "", find : { _id : 0 } }).ok );
+ st.printShardingStatus();
+}
+
+// Make sure we can't split further than 5 (2^5) times
+assert( !admin.runCommand({ split : coll + "", find : { _id : 0 } }).ok );
+
+var chunks = config.chunks.find({ 'min._id' : { $gte : 0, $lt : 32 } }).sort({ min : 1 }).toArray();
+printjson( chunks );
+
+// Make sure the chunks grow by 2x (except the first)
+var nextSize = 1;
+for ( var i = 0; i < chunks.size; i++ ) {
+ assert.eq( coll.count({ _id : { $gte : chunks[i].min._id, $lt : chunks[i].max._id } }),
+ nextSize );
+ if ( i != 0 ) nextSize += nextSize;
+}
+
+st.stop();