summaryrefslogtreecommitdiff
path: root/jstests
diff options
context:
space:
mode:
authorRandolph Tan <randolph@10gen.com>2015-04-10 18:06:07 -0400
committerRandolph Tan <randolph@10gen.com>2015-05-15 10:11:31 -0400
commit280fbae9044af29bc63068dbe9c4e7846e9e6517 (patch)
tree96b6490b5aa9d8ad0facd9356367ecd5f3534a8d /jstests
parentf3d242c808ec6c1b7145dd3f084da438829552cb (diff)
downloadmongo-280fbae9044af29bc63068dbe9c4e7846e9e6517.tar.gz
SERVER-18044 Make sharding test explicitly set primary shards for databases
Diffstat (limited to 'jstests')
-rw-r--r--jstests/aggregation/bugs/server6118.js1
-rw-r--r--jstests/aggregation/bugs/server6179.js1
-rw-r--r--jstests/aggregation/bugs/server7781.js2
-rw-r--r--jstests/aggregation/testshard1.js1
-rw-r--r--jstests/gle/1_sharding_gle_basics_passthrough.js4
-rw-r--r--jstests/multiVersion/balancer_multiVersion_detect.js1
-rw-r--r--jstests/multiVersion/explain.js5
-rw-r--r--jstests/noPassthroughWithMongod/balance_repl.js1
-rw-r--r--jstests/noPassthroughWithMongod/balance_tags1.js6
-rw-r--r--jstests/noPassthroughWithMongod/balance_tags2.js7
-rw-r--r--jstests/noPassthroughWithMongod/large_chunk.js6
-rw-r--r--jstests/noPassthroughWithMongod/sharding_balance1.js1
-rw-r--r--jstests/noPassthroughWithMongod/sharding_balance3.js1
-rw-r--r--jstests/noPassthroughWithMongod/sharding_balance4.js1
-rw-r--r--jstests/noPassthroughWithMongod/sharding_migrateBigObject.js5
-rw-r--r--jstests/noPassthroughWithMongod/sharding_migrate_cursor1.js1
-rw-r--r--jstests/noPassthroughWithMongod/sharding_rs1.js4
-rw-r--r--jstests/noPassthroughWithMongod/sharding_rs2.js4
-rw-r--r--jstests/noPassthroughWithMongod/ttl_sharded.js1
-rw-r--r--jstests/sharding/SERVER-7379.js1
-rw-r--r--jstests/sharding/authCommands.js1
-rw-r--r--jstests/sharding/authConnectionHook.js3
-rw-r--r--jstests/sharding/auto1.js1
-rw-r--r--jstests/sharding/auto2.js1
-rw-r--r--jstests/sharding/batch_write_command_sharded.js1
-rw-r--r--jstests/sharding/bouncing_count.js5
-rw-r--r--jstests/sharding/coll_epoch_test0.js3
-rw-r--r--jstests/sharding/coll_epoch_test1.js2
-rw-r--r--jstests/sharding/coll_epoch_test2.js2
-rw-r--r--jstests/sharding/count1.js1
-rw-r--r--jstests/sharding/count2.js1
-rw-r--r--jstests/sharding/cursor1.js1
-rw-r--r--jstests/sharding/delete_during_migrate.js10
-rw-r--r--jstests/sharding/explain_cmd.js1
-rw-r--r--jstests/sharding/fair_balancer_round.js1
-rw-r--r--jstests/sharding/features1.js1
-rw-r--r--jstests/sharding/features2.js1
-rw-r--r--jstests/sharding/features3.js1
-rw-r--r--jstests/sharding/findandmodify1.js1
-rw-r--r--jstests/sharding/findandmodify2.js1
-rw-r--r--jstests/sharding/geo_near_random1.js1
-rw-r--r--jstests/sharding/geo_near_random2.js1
-rw-r--r--jstests/sharding/geo_shardedgeonear.js1
-rw-r--r--jstests/sharding/hash_basic.js1
-rw-r--r--jstests/sharding/hash_shard1.js1
-rw-r--r--jstests/sharding/hash_shard_non_empty.js1
-rw-r--r--jstests/sharding/hash_shard_num_chunks.js1
-rw-r--r--jstests/sharding/hash_skey_split.js1
-rw-r--r--jstests/sharding/in_memory_sort_limit.js3
-rw-r--r--jstests/sharding/index1.js5
-rw-r--r--jstests/sharding/jumbo1.js1
-rw-r--r--jstests/sharding/key_many.js1
-rw-r--r--jstests/sharding/key_string.js1
-rw-r--r--jstests/sharding/limit_push.js1
-rw-r--r--jstests/sharding/localhostAuthBypass.js11
-rw-r--r--jstests/sharding/mapReduce_inSharded.js1
-rw-r--r--jstests/sharding/mapReduce_inSharded_outSharded.js1
-rw-r--r--jstests/sharding/mapReduce_nonSharded.js1
-rw-r--r--jstests/sharding/mapReduce_outSharded.js1
-rw-r--r--jstests/sharding/migrateBig.js1
-rw-r--r--jstests/sharding/mongos_validate_writes.js1
-rw-r--r--jstests/sharding/movechunk_include.js1
-rw-r--r--jstests/sharding/moveprimary_ignore_sharded.js2
-rw-r--r--jstests/sharding/multi_mongos2.js1
-rw-r--r--jstests/sharding/multi_mongos2a.js1
-rw-r--r--jstests/sharding/parallel.js1
-rw-r--r--jstests/sharding/prefix_shard_key.js1
-rw-r--r--jstests/sharding/presplit.js5
-rw-r--r--jstests/sharding/remove2.js20
-rw-r--r--jstests/sharding/shard1.js1
-rw-r--r--jstests/sharding/shard2.js1
-rw-r--r--jstests/sharding/shard3.js2
-rw-r--r--jstests/sharding/shard4.js1
-rw-r--r--jstests/sharding/shard5.js1
-rw-r--r--jstests/sharding/shard6.js1
-rw-r--r--jstests/sharding/shard7.js1
-rw-r--r--jstests/sharding/shard_existing.js1
-rw-r--r--jstests/sharding/shard_key_immutable.js1
-rw-r--r--jstests/sharding/shard_keycount.js1
-rw-r--r--jstests/sharding/shard_targeting.js1
-rw-r--r--jstests/sharding/shard_with_special_db_names.js2
-rw-r--r--jstests/sharding/sharding_system_namespaces.js1
-rw-r--r--jstests/sharding/sort1.js1
-rw-r--r--jstests/sharding/stats.js1
-rw-r--r--jstests/sharding/sync2.js1
-rw-r--r--jstests/sharding/tag_auto_split.js2
-rw-r--r--jstests/sharding/tag_range.js1
-rw-r--r--jstests/sharding/update_immutable_fields.js1
-rw-r--r--jstests/sharding/update_sharded.js1
-rw-r--r--jstests/sharding/upsert_sharded.js1
-rw-r--r--jstests/sharding/zbigMapReduce.js1
-rw-r--r--jstests/slow1/sharding_multiple_collections.js2
-rw-r--r--jstests/slow2/cursor_timeout.js1
-rw-r--r--jstests/tool/dumprestore9.js3
94 files changed, 150 insertions, 43 deletions
diff --git a/jstests/aggregation/bugs/server6118.js b/jstests/aggregation/bugs/server6118.js
index 56e23af8e5a..2f2e7599ef8 100644
--- a/jstests/aggregation/bugs/server6118.js
+++ b/jstests/aggregation/bugs/server6118.js
@@ -3,6 +3,7 @@
// Set up a sharding test.
s = new ShardingTest( "aggregation_sort1", 2, 0, 2 );
s.adminCommand( { enablesharding:"test" } );
+s.ensurePrimaryShard('test', 'shard0001');
s.adminCommand( { shardcollection:"test.data", key:{ _id:1 } } );
// Test does it's own balancing.
diff --git a/jstests/aggregation/bugs/server6179.js b/jstests/aggregation/bugs/server6179.js
index f5cf6259c4f..260fa38c983 100644
--- a/jstests/aggregation/bugs/server6179.js
+++ b/jstests/aggregation/bugs/server6179.js
@@ -3,6 +3,7 @@
// Set up a sharding test.
s = new ShardingTest( "aggregation_multiple_group", 2, 0, 2 );
s.adminCommand( { enablesharding:"test" } );
+s.ensurePrimaryShard('test', 'shard0001');
s.adminCommand( { shardcollection:"test.data", key:{ _id:1 } } );
s.stopBalancer()
diff --git a/jstests/aggregation/bugs/server7781.js b/jstests/aggregation/bugs/server7781.js
index e22ae786803..81729e4654a 100644
--- a/jstests/aggregation/bugs/server7781.js
+++ b/jstests/aggregation/bugs/server7781.js
@@ -123,7 +123,7 @@ test(db, false, '2dsphere');
var sharded = new ShardingTest({shards: 3, verbose: 0, mongos: 1});
sharded.stopBalancer();
sharded.adminCommand( { enablesharding : "test" } );
-
+sharded.ensurePrimaryShard('test', 'shard0001');
test(sharded.getDB('test'), true, '2d');
test(sharded.getDB('test'), true, '2dsphere');
diff --git a/jstests/aggregation/testshard1.js b/jstests/aggregation/testshard1.js
index 91468ffea24..6bf66fc23cb 100644
--- a/jstests/aggregation/testshard1.js
+++ b/jstests/aggregation/testshard1.js
@@ -28,6 +28,7 @@ jsTestLog("Setting up sharded cluster");
shardedAggTest.adminCommand( { enablesharding : "aggShard" } );
db = shardedAggTest.getDB( "aggShard" );
assert.commandWorked(db.adminCommand({setParameter: 1, logComponentVerbosity: { network: 0 }}));
+shardedAggTest.ensurePrimaryShard('aggShard', 'shard0000');
/* make sure its cleaned up */
db.ts1.drop();
diff --git a/jstests/gle/1_sharding_gle_basics_passthrough.js b/jstests/gle/1_sharding_gle_basics_passthrough.js
index dad1f5ac5a2..6b9f51c59cc 100644
--- a/jstests/gle/1_sharding_gle_basics_passthrough.js
+++ b/jstests/gle/1_sharding_gle_basics_passthrough.js
@@ -8,7 +8,7 @@
var passST = new ShardingTest({ name : "passST", shards : 2, mongos : 1 });
var passMongos = passST.s0;
assert.commandWorked(passMongos.getDB("admin").runCommand({ enableSharding : "testSharded" }));
-
+ passST.ensurePrimaryShard('testSharded', 'shard0001');
// Remember the global 'db' var
var lastDB = db;
@@ -46,4 +46,4 @@
db = lastDB;
passST.stop();
-}()); \ No newline at end of file
+}());
diff --git a/jstests/multiVersion/balancer_multiVersion_detect.js b/jstests/multiVersion/balancer_multiVersion_detect.js
index 25bf8d27b12..c68072b3e80 100644
--- a/jstests/multiVersion/balancer_multiVersion_detect.js
+++ b/jstests/multiVersion/balancer_multiVersion_detect.js
@@ -20,6 +20,7 @@ var admin = mongos.getDB("admin");
var coll = mongos.getCollection("foo.bar");
printjson(admin.runCommand({ enableSharding : coll.getDB() + "" }));
+st.ensurePrimaryShard(coll.getDB().getName(), 'shard0001');
printjson(admin.runCommand({ shardCollection : coll + "", key : { _id : 1 } }));
assert.soon( function() {
diff --git a/jstests/multiVersion/explain.js b/jstests/multiVersion/explain.js
index 2579c12f164..07d01204f99 100644
--- a/jstests/multiVersion/explain.js
+++ b/jstests/multiVersion/explain.js
@@ -50,6 +50,7 @@ coll = testDb.standalone;
coll.drop();
assert.commandWorked(testDb.adminCommand({enableSharding: testDb.getName()}));
+st.ensurePrimaryShard(testDb.getName(), 'shard0001');
testDb.adminCommand({shardCollection: coll.getFullName(), key: {_id: 1}});
coll.insert({_id: 1, a: 1});
@@ -94,6 +95,7 @@ coll = testDb.standalone;
coll.drop();
assert.commandWorked(testDb.adminCommand({enableSharding: testDb.getName()}));
+st.ensurePrimaryShard(testDb.getName(), 'shard0001');
testDb.adminCommand({shardCollection: coll.getFullName(), key: {_id: 1}});
coll.insert({_id: 1, a: 1});
@@ -138,8 +140,7 @@ coll = testDb.standalone;
coll.drop();
assert.commandWorked(testDb.adminCommand({enableSharding: testDb.getName()}));
-var res = testDb.adminCommand({movePrimary: testDb.getName(), to: 'shard0001'});
-assert(res.ok || res.errmsg == "it is already the primary");
+st.ensurePrimaryShard(testDb.getName(), 'shard0001');
testDb.adminCommand({shardCollection: coll.getFullName(), key: {_id: 1}});
// Disable the balancer and pre-split in order to ensure chunks on both shards.
diff --git a/jstests/noPassthroughWithMongod/balance_repl.js b/jstests/noPassthroughWithMongod/balance_repl.js
index 412dc95e9ac..ea2a7f87226 100644
--- a/jstests/noPassthroughWithMongod/balance_repl.js
+++ b/jstests/noPassthroughWithMongod/balance_repl.js
@@ -14,6 +14,7 @@ serverName = s.getServerName( "test" )
other = s.config.shards.findOne( { _id : { $ne : serverName } } );
s.adminCommand( { enablesharding : "test" } )
+s.ensurePrimaryShard('test', 'test-rs0');
s.adminCommand( { shardcollection : "test.foo" , key : { _id : 1 } } );
for ( i=0; i<20; i++ )
diff --git a/jstests/noPassthroughWithMongod/balance_tags1.js b/jstests/noPassthroughWithMongod/balance_tags1.js
index 05b5ca31dc2..cf20d7ab488 100644
--- a/jstests/noPassthroughWithMongod/balance_tags1.js
+++ b/jstests/noPassthroughWithMongod/balance_tags1.js
@@ -2,14 +2,16 @@
s = new ShardingTest( "balance_tags1" , 3 , 1 , 1 , { sync:true, chunksize : 1 , nopreallocj : true } )
s.config.settings.update({ _id: "balancer" }, { $set: { stopped: false }}, true);
+s.adminCommand({ enablesharding: "test" });
+s.ensurePrimaryShard('test', 'shard0001');
+
db = s.getDB( "test" );
var bulk = db.foo.initializeUnorderedBulkOp();
-for ( i=0; i<21; i++ ) {
+for (i = 0; i < 21; i++) {
bulk.insert({ _id: i, x: i });
}
assert.writeOK(bulk.execute());
-s.adminCommand( { enablesharding : "test" } )
s.adminCommand( { shardcollection : "test.foo" , key : { _id : 1 } } );
s.stopBalancer();
diff --git a/jstests/noPassthroughWithMongod/balance_tags2.js b/jstests/noPassthroughWithMongod/balance_tags2.js
index 01389bb43cc..9ae1f680591 100644
--- a/jstests/noPassthroughWithMongod/balance_tags2.js
+++ b/jstests/noPassthroughWithMongod/balance_tags2.js
@@ -6,14 +6,15 @@ s = new ShardingTest( "balance_tags2" , 3 , 1 , 1 ,
s.config.settings.save({ _id: "balancer" });
db = s.getDB( "test" );
+
+sh.enableSharding("test");
+s.ensurePrimaryShard('test', 'shard0001');
var bulk = db.foo.initializeUnorderedBulkOp();
-for ( i=0; i<21; i++ ) {
+for (i = 0; i < 21; i++) {
bulk.insert({ _id: i, x: i });
}
assert.writeOK(bulk.execute());
-// enable sharding, shard, and stop balancer
-sh.enableSharding("test");
sh.shardCollection("test.foo" , { _id : 1 });
sh.stopBalancer();
diff --git a/jstests/noPassthroughWithMongod/large_chunk.js b/jstests/noPassthroughWithMongod/large_chunk.js
index 019e4313e48..13183896ae8 100644
--- a/jstests/noPassthroughWithMongod/large_chunk.js
+++ b/jstests/noPassthroughWithMongod/large_chunk.js
@@ -14,6 +14,10 @@ db = s.getDB( "test" );
// Step 1 - Test moving a large chunk
//
+// Turn on sharding on the 'test.foo' collection and generate a large chunk
+s.adminCommand( { enablesharding : "test" } );
+s.ensurePrimaryShard('test', 'shard0001');
+
bigString = ""
while ( bigString.length < 10000 )
bigString += "asdasdasdasdadasdasdasdasdasdasdasdasda";
@@ -27,8 +31,6 @@ while ( inserted < ( 400 * 1024 * 1024 ) ){
}
assert.writeOK(bulk.execute());
-// Turn on sharding on the 'test.foo' collection and generate a large chunk
-s.adminCommand( { enablesharding : "test" } );
s.adminCommand( { shardcollection : "test.foo" , key : { _id : 1 } } );
assert.eq( 1 , s.config.chunks.count() , "step 1 - need one large chunk" );
diff --git a/jstests/noPassthroughWithMongod/sharding_balance1.js b/jstests/noPassthroughWithMongod/sharding_balance1.js
index 32bb8ba508e..e7897d6e87f 100644
--- a/jstests/noPassthroughWithMongod/sharding_balance1.js
+++ b/jstests/noPassthroughWithMongod/sharding_balance1.js
@@ -4,6 +4,7 @@
s = new ShardingTest( "slow_sharding_balance1" , 2 , 1 , 1 , { chunksize : 1, enableBalancer : true } )
s.adminCommand( { enablesharding : "test" } );
+s.ensurePrimaryShard('test', 'shard0001');
s.config.settings.find().forEach( printjson )
diff --git a/jstests/noPassthroughWithMongod/sharding_balance3.js b/jstests/noPassthroughWithMongod/sharding_balance3.js
index 03787c756ac..fb34a09e24d 100644
--- a/jstests/noPassthroughWithMongod/sharding_balance3.js
+++ b/jstests/noPassthroughWithMongod/sharding_balance3.js
@@ -5,6 +5,7 @@
s = new ShardingTest( "slow_sharding_balance3" , 2 , 3 , 1 , { chunksize : 1, enableBalancer : true } );
s.adminCommand( { enablesharding : "test" } );
+s.ensurePrimaryShard('test', 'shard0001');
s.config.settings.find().forEach( printjson );
diff --git a/jstests/noPassthroughWithMongod/sharding_balance4.js b/jstests/noPassthroughWithMongod/sharding_balance4.js
index fa50deb7645..9ce404d9f95 100644
--- a/jstests/noPassthroughWithMongod/sharding_balance4.js
+++ b/jstests/noPassthroughWithMongod/sharding_balance4.js
@@ -6,6 +6,7 @@ s = new ShardingTest( "slow_sharding_balance4" , 2 , 1 , 1 , { chunksize : 1 } )
s.stopBalancer();
s.adminCommand( { enablesharding : "test" } );
+s.ensurePrimaryShard('test', 'shard0001');
s.adminCommand( { shardcollection : "test.foo" , key : { _id : 1 } } );
assert.eq( 1 , s.config.chunks.count() , "setup1" );
diff --git a/jstests/noPassthroughWithMongod/sharding_migrateBigObject.js b/jstests/noPassthroughWithMongod/sharding_migrateBigObject.js
index c819b65477d..cfa91a6ec77 100644
--- a/jstests/noPassthroughWithMongod/sharding_migrateBigObject.js
+++ b/jstests/noPassthroughWithMongod/sharding_migrateBigObject.js
@@ -5,6 +5,9 @@ var admin = mongos.getDB("admin");
db = mongos.getDB("test");
var coll = db.getCollection("stuff")
+assert.commandWorked(admin.runCommand({ enablesharding : coll.getDB().getName() }));
+st.ensurePrimaryShard(coll.getDB().getName(), 'shard0001');
+
var data = "x"
var nsq = 16
var n = 255
@@ -24,8 +27,6 @@ assert.eq( 40 , coll.count() , "prep1" );
printjson( coll.stats() )
-admin.runCommand({ enablesharding : "" + coll.getDB() })
-
admin.printShardingStatus()
admin.runCommand({ shardcollection : "" + coll, key : { _id : 1 } })
diff --git a/jstests/noPassthroughWithMongod/sharding_migrate_cursor1.js b/jstests/noPassthroughWithMongod/sharding_migrate_cursor1.js
index c4484356dd4..93422301de2 100644
--- a/jstests/noPassthroughWithMongod/sharding_migrate_cursor1.js
+++ b/jstests/noPassthroughWithMongod/sharding_migrate_cursor1.js
@@ -8,6 +8,7 @@ s.config.settings.update( { _id: "balancer" }, { $set : { stopped: true } } , tr
s.adminCommand( { enablesharding : "test" } );
db = s.getDB( "test" )
+s.ensurePrimaryShard('test', 'shard0001');
t = db.foo
bigString = ""
diff --git a/jstests/noPassthroughWithMongod/sharding_rs1.js b/jstests/noPassthroughWithMongod/sharding_rs1.js
index c7959c08aee..d9b9233f364 100644
--- a/jstests/noPassthroughWithMongod/sharding_rs1.js
+++ b/jstests/noPassthroughWithMongod/sharding_rs1.js
@@ -1,8 +1,10 @@
// tests sharding with replica sets
-s = new ShardingTest( "rs1" , 3 /* numShards */, 1 /* verboseLevel */, 2 /* numMongos */, { rs : true , chunksize : 1, enableBalancer : true } )
+var s = new ShardingTest({ shards: 3, verbose: 1, mongos: 2,
+ other: { rs: true , chunksize: 1, enableBalancer: true }});
s.adminCommand( { enablesharding : "test" } );
+s.ensurePrimaryShard('test', 'test-rs0');
s.config.settings.update( { _id: "balancer" }, { $set : { _waitForDelete : true } } , true );
s.config.settings.find().forEach( printjson )
diff --git a/jstests/noPassthroughWithMongod/sharding_rs2.js b/jstests/noPassthroughWithMongod/sharding_rs2.js
index 04cbdeafa4c..117b180a6b5 100644
--- a/jstests/noPassthroughWithMongod/sharding_rs2.js
+++ b/jstests/noPassthroughWithMongod/sharding_rs2.js
@@ -6,6 +6,9 @@ var s = new ShardingTest({ shards: { rs0: { nodes: 2 }, rs1: { nodes: 2 }},
db = s.getDB( "test" )
t = db.foo
+s.adminCommand( { enablesharding : "test" } );
+s.ensurePrimaryShard('test', 'test-rs0');
+
// -------------------------------------------------------------------------------------------
// ---------- test that config server updates when replica set config changes ----------------
// -------------------------------------------------------------------------------------------
@@ -114,7 +117,6 @@ gc(); gc(); gc();
assert.eq( 100 , db.foo.count() , "C1" )
-s.adminCommand( { enablesharding : "test" } );
s.adminCommand( { shardcollection : "test.foo" , key : { x : 1 } } );
// We're doing some manual chunk stuff, so stop the balancer first
diff --git a/jstests/noPassthroughWithMongod/ttl_sharded.js b/jstests/noPassthroughWithMongod/ttl_sharded.js
index 2d551d1e09e..c7146b63cb7 100644
--- a/jstests/noPassthroughWithMongod/ttl_sharded.js
+++ b/jstests/noPassthroughWithMongod/ttl_sharded.js
@@ -16,6 +16,7 @@ t = s.getDB( dbname ).getCollection( coll );
// enable sharding of the collection. Only 1 chunk initially
s.adminCommand( { enablesharding : dbname } );
+s.ensurePrimaryShard(dbname, 'shard0001');
s.adminCommand( { shardcollection : ns , key: { _id : 1 } } );
// insert 24 docs, with timestamps at one hour intervals
diff --git a/jstests/sharding/SERVER-7379.js b/jstests/sharding/SERVER-7379.js
index f4730495624..f59ec8d139f 100644
--- a/jstests/sharding/SERVER-7379.js
+++ b/jstests/sharding/SERVER-7379.js
@@ -1,6 +1,7 @@
var st = new ShardingTest({ shards: 2 });
st.adminCommand({ enablesharding: "test" });
+st.ensurePrimaryShard('test', 'shard0001');
st.adminCommand({ shardcollection: "test.offerChange", key: { "categoryId": 1, "store": 1, "_id": 1 } });
var db = st.s.getDB('test');
diff --git a/jstests/sharding/authCommands.js b/jstests/sharding/authCommands.js
index 9624da7d34f..e97a319d9f1 100644
--- a/jstests/sharding/authCommands.js
+++ b/jstests/sharding/authCommands.js
@@ -49,6 +49,7 @@ st.rs1.getPrimary().getDB( 'admin' ).createUser({user: 'user',
jsTestLog('Creating initial data');
st.adminCommand( { enablesharding : "test" } );
+st.ensurePrimaryShard('test', 'test-rs0');
st.adminCommand( { shardcollection : "test.foo" , key : { i : 1, j : 1 } } );
// Stop the balancer, so no moveChunks will interfere with the splits we're testing
diff --git a/jstests/sharding/authConnectionHook.js b/jstests/sharding/authConnectionHook.js
index 52a2b25b050..180ceff7eb4 100644
--- a/jstests/sharding/authConnectionHook.js
+++ b/jstests/sharding/authConnectionHook.js
@@ -12,6 +12,7 @@ adminDB.createUser({user: 'admin', pwd: 'password', roles: jsTest.adminUserRoles
adminDB.auth('admin', 'password');
adminDB.runCommand({enableSharding : "test"});
+st.ensurePrimaryShard('test', 'shard0001');
adminDB.runCommand({shardCollection : "test.foo", key : {x : 1}});
st.stopBalancer();
@@ -42,4 +43,4 @@ assert.soon( function() {
printjson(db.foo.findOne({x:25}));
printjson(db.foo.findOne({x:75}));
-st.stop(); \ No newline at end of file
+st.stop();
diff --git a/jstests/sharding/auto1.js b/jstests/sharding/auto1.js
index 781630d7405..70249c85c8d 100644
--- a/jstests/sharding/auto1.js
+++ b/jstests/sharding/auto1.js
@@ -3,6 +3,7 @@
s = new ShardingTest( "auto1" , 2 , 1 , 1, { enableBalancer : 1 } );
s.adminCommand( { enablesharding : "test" } );
+s.ensurePrimaryShard('test', 'shard0001');
s.adminCommand( { shardcollection : "test.foo" , key : { num : 1 } } );
bigString = "";
diff --git a/jstests/sharding/auto2.js b/jstests/sharding/auto2.js
index 06346c34298..6eb46bb45c4 100644
--- a/jstests/sharding/auto2.js
+++ b/jstests/sharding/auto2.js
@@ -3,6 +3,7 @@
s = new ShardingTest( "auto2" , 2 , 1 , 2 );
s.adminCommand( { enablesharding : "test" } );
+s.ensurePrimaryShard('test', 'shard0001');
s.adminCommand( { shardcollection : "test.foo" , key : { num : 1 } } );
bigString = "";
diff --git a/jstests/sharding/batch_write_command_sharded.js b/jstests/sharding/batch_write_command_sharded.js
index b23963c5f4f..a7aa05c0b4e 100644
--- a/jstests/sharding/batch_write_command_sharded.js
+++ b/jstests/sharding/batch_write_command_sharded.js
@@ -29,6 +29,7 @@ var result;
var coll = mongos.getCollection("foo.bar");
assert.commandWorked(admin.runCommand({ enableSharding : coll.getDB().toString() }));
+st.ensurePrimaryShard(coll.getDB().getName(), 'shard0001');
assert.commandWorked(admin.runCommand({ shardCollection : coll.toString(),
key : { _id : 1 } }));
diff --git a/jstests/sharding/bouncing_count.js b/jstests/sharding/bouncing_count.js
index d9630a4e930..c5f22f0b170 100644
--- a/jstests/sharding/bouncing_count.js
+++ b/jstests/sharding/bouncing_count.js
@@ -13,7 +13,8 @@ var collA = mongosA.getCollection( "foo.bar" )
var collB = mongosB.getCollection( "" + collA )
var collC = mongosB.getCollection( "" + collA )
-admin.runCommand({ enableSharding : "" + collA.getDB() })
+admin.runCommand({ enableSharding : "" + collA.getDB() });
+st.ensurePrimaryShard(collA.getDB().getName(), 'shard0001');
admin.runCommand({ shardCollection : "" + collA, key : { _id : 1 } })
var shards = config.shards.find().sort({ _id : 1 }).toArray()
@@ -46,4 +47,4 @@ jsTestLog( "Running count!" )
printjson( collB.count() )
printjson( collC.find().toArray() )
-st.stop() \ No newline at end of file
+st.stop()
diff --git a/jstests/sharding/coll_epoch_test0.js b/jstests/sharding/coll_epoch_test0.js
index 1b9c6294b85..73614c095f5 100644
--- a/jstests/sharding/coll_epoch_test0.js
+++ b/jstests/sharding/coll_epoch_test0.js
@@ -10,6 +10,7 @@ var coll = st.s.getCollection( "foo.bar" )
// First enable sharding
admin.runCommand({ enableSharding : coll.getDB() + "" })
+st.ensurePrimaryShard(coll.getDB().getName(), 'shard0001');
admin.runCommand({ shardCollection : coll + "", key : { _id : 1 } })
var primary = config.databases.find({ _id : coll.getDB() + "" }).primary
@@ -44,4 +45,4 @@ printjson( admin.runCommand({ moveChunk : coll + "", find : { _id : 0 }, to : no
// Check all the chunks for epochs
checkEpochs();
-st.stop() \ No newline at end of file
+st.stop()
diff --git a/jstests/sharding/coll_epoch_test1.js b/jstests/sharding/coll_epoch_test1.js
index c6b6680469e..3fd97e8105f 100644
--- a/jstests/sharding/coll_epoch_test1.js
+++ b/jstests/sharding/coll_epoch_test1.js
@@ -28,6 +28,7 @@ config.shards.find().forEach( function( doc ){
jsTest.log( "Enabling sharding for the first time..." )
admin.runCommand({ enableSharding : coll.getDB() + "" })
+st.ensurePrimaryShard(coll.getDB().getName(), 'shard0001');
admin.runCommand({ shardCollection : coll + "", key : { _id : 1 } })
var bulk = insertMongos.getCollection( coll + "" ).initializeUnorderedBulkOp();
@@ -47,6 +48,7 @@ coll.drop()
jsTest.log( "Re-enabling sharding with a different key..." )
admin.runCommand({ enableSharding : coll.getDB() + "" })
+st.ensurePrimaryShard(coll.getDB().getName(), 'shard0001');
coll.ensureIndex({ notId : 1 })
admin.runCommand({ shardCollection : coll + "", key : { notId : 1 } })
diff --git a/jstests/sharding/coll_epoch_test2.js b/jstests/sharding/coll_epoch_test2.js
index eb7969b9480..03488168d9e 100644
--- a/jstests/sharding/coll_epoch_test2.js
+++ b/jstests/sharding/coll_epoch_test2.js
@@ -32,6 +32,7 @@ config.shards.find().forEach( function( doc ){
jsTest.log( "Enabling sharding for the first time..." )
admin.runCommand({ enableSharding : coll.getDB() + "" })
+st.ensurePrimaryShard(coll.getDB().getName(), 'shard0001');
admin.runCommand({ shardCollection : coll + "", key : { _id : 1 } })
assert.writeOK(coll.insert({ hello : "world" }));
@@ -78,6 +79,7 @@ assert(droppedCollDoc.lastmodEpoch.equals(new ObjectId("000000000000000000000000
"epoch not zero: " + droppedCollDoc.lastmodEpoch);
admin.runCommand({ enableSharding : coll.getDB() + "" })
+st.ensurePrimaryShard(coll.getDB().getName(), 'shard0001');
admin.runCommand({ shardCollection : coll + "", key : { _id : 1 } })
var bulk = coll.initializeUnorderedBulkOp();
diff --git a/jstests/sharding/count1.js b/jstests/sharding/count1.js
index 082281f5f84..19d70456d1f 100644
--- a/jstests/sharding/count1.js
+++ b/jstests/sharding/count1.js
@@ -35,6 +35,7 @@ assert.eq( 1 , db.bar.find( { n : 1 } ).count() , "bar 2" );
// part 1
s.adminCommand( { enablesharding : "test" } )
+s.ensurePrimaryShard('test', 'shard0001');
s.adminCommand( { shardcollection : "test.foo" , key : { name : 1 } } );
primary = s.getServer( "test" ).getDB( "test" );
diff --git a/jstests/sharding/count2.js b/jstests/sharding/count2.js
index edac3b692ec..7c84c415646 100644
--- a/jstests/sharding/count2.js
+++ b/jstests/sharding/count2.js
@@ -5,6 +5,7 @@ s2 = s1._mongos[1];
s1.stopBalancer();
s1.adminCommand( { enablesharding: "test" } );
+s1.ensurePrimaryShard('test', 'shard0001');
s1.adminCommand( { shardcollection: "test.foo" , key : { name : 1 } } );
db1 = s1.getDB( "test" ).foo;
diff --git a/jstests/sharding/cursor1.js b/jstests/sharding/cursor1.js
index 6ca7e5ff1cb..c0c3439ac5b 100644
--- a/jstests/sharding/cursor1.js
+++ b/jstests/sharding/cursor1.js
@@ -9,6 +9,7 @@ s.config.settings.find().forEach( printjson )
// create a sharded 'test.foo', for the moment with just one chunk
s.adminCommand( { enablesharding: "test" } );
+s.ensurePrimaryShard('test', 'shard0001');
s.adminCommand( { shardcollection: "test.foo", key: { _id: 1 } } )
db = s.getDB( "test" );
diff --git a/jstests/sharding/delete_during_migrate.js b/jstests/sharding/delete_during_migrate.js
index 4b01d16734a..81daf3c3e52 100644
--- a/jstests/sharding/delete_during_migrate.js
+++ b/jstests/sharding/delete_during_migrate.js
@@ -14,15 +14,19 @@ var ns = dbname + "." + coll;
var s = st.s0;
var t = s.getDB( dbname ).getCollection( coll );
+s.adminCommand({ enablesharding: dbname });
+st.ensurePrimaryShard(dbname, 'shard0001');
+
// Create fresh collection with lots of docs
t.drop();
-for ( i=0; i<200000; i++ ){
- t.insert( { a : i } );
+var bulk = t.initializeUnorderedBulkOp();
+for (var i = 0; i < 200000; i++) {
+ bulk.insert({ a: i });
}
+assert.writeOK(bulk.execute());
// enable sharding of the collection. Only 1 chunk.
t.ensureIndex( { a : 1 } );
-s.adminCommand( { enablesharding : dbname } );
s.adminCommand( { shardcollection : ns , key: { a : 1 } } );
// start a parallel shell that deletes things
diff --git a/jstests/sharding/explain_cmd.js b/jstests/sharding/explain_cmd.js
index 062f39f5957..bf9ed176617 100644
--- a/jstests/sharding/explain_cmd.js
+++ b/jstests/sharding/explain_cmd.js
@@ -15,6 +15,7 @@ collSharded.ensureIndex({b: 1});
// Enable sharding.
assert.commandWorked(db.adminCommand({enableSharding: db.getName()}));
+st.ensurePrimaryShard(db.getName(), 'shard0001');
db.adminCommand({shardCollection: collSharded.getFullName(), key: {a: 1}});
// Pre-split the collection to ensure that both shards have chunks. Explicitly
diff --git a/jstests/sharding/fair_balancer_round.js b/jstests/sharding/fair_balancer_round.js
index a565b469667..d741a2aa2c6 100644
--- a/jstests/sharding/fair_balancer_round.js
+++ b/jstests/sharding/fair_balancer_round.js
@@ -15,6 +15,7 @@ var coll = mongos.getCollection("foo.bar");
// Shard collection through first mongos
assert(mongos.adminCommand({enableSharding : coll.getDB() + ""}).ok);
+st.ensurePrimaryShard(coll.getDB().getName(), 'shard0001');
assert(mongos.adminCommand({shardCollection : coll + "", key : {_id : 1}}).ok);
// Create a bunch of chunks
diff --git a/jstests/sharding/features1.js b/jstests/sharding/features1.js
index 23424075d1b..22fed89fef8 100644
--- a/jstests/sharding/features1.js
+++ b/jstests/sharding/features1.js
@@ -5,6 +5,7 @@ s = new ShardingTest( "features1" , 2 , 1 , 1 );
s.stopBalancer();
s.adminCommand( { enablesharding : "test" } );
+s.ensurePrimaryShard('test', 'shard0001');
// ---- can't shard system namespaces ----
diff --git a/jstests/sharding/features2.js b/jstests/sharding/features2.js
index 4689630718e..c5c77e884b2 100644
--- a/jstests/sharding/features2.js
+++ b/jstests/sharding/features2.js
@@ -7,6 +7,7 @@ s = new ShardingTest( "features2" , 2 , 1 , 1 );
s.stopBalancer()
s.adminCommand( { enablesharding : "test" } );
+s.ensurePrimaryShard('test', 'shard0001');
a = s._connections[0].getDB( "test" );
b = s._connections[1].getDB( "test" );
diff --git a/jstests/sharding/features3.js b/jstests/sharding/features3.js
index 67ba574e63c..afa7eeb1367 100644
--- a/jstests/sharding/features3.js
+++ b/jstests/sharding/features3.js
@@ -18,6 +18,7 @@ s.stopBalancer()
// shard test.foo and add a split point
s.adminCommand({enablesharding: "test"});
+s.ensurePrimaryShard('test', 'shard0001');
s.adminCommand({shardcollection : "test.foo", key: {_id: 1}});
s.adminCommand({split : "test.foo", middle: {_id: numDocs/2}});
diff --git a/jstests/sharding/findandmodify1.js b/jstests/sharding/findandmodify1.js
index 058016e22c1..bc15a40f48d 100644
--- a/jstests/sharding/findandmodify1.js
+++ b/jstests/sharding/findandmodify1.js
@@ -2,6 +2,7 @@ s = new ShardingTest( "find_and_modify_sharded" , 2 , 2);
s.adminCommand( { enablesharding : "test" } );
db = s.getDB( "test" );
+s.ensurePrimaryShard('test', 'shard0001');
primary = s.getServer( "test" ).getDB( "test" );
secondary = s.getOther( primary ).getDB( "test" );
diff --git a/jstests/sharding/findandmodify2.js b/jstests/sharding/findandmodify2.js
index ad7b1688ca2..189838d76d3 100644
--- a/jstests/sharding/findandmodify2.js
+++ b/jstests/sharding/findandmodify2.js
@@ -2,6 +2,7 @@ var s = new ShardingTest({ name: "find_and_modify_sharded_2", shards: 2, verbose
s.adminCommand( { enablesharding : "test" } );
var db = s.getDB( "test" );
+s.ensurePrimaryShard('test', 'shard0001');
var primary = s.getServer( "test" ).getDB( "test" );
var secondary = s.getOther( primary ).getDB( "test" );
diff --git a/jstests/sharding/geo_near_random1.js b/jstests/sharding/geo_near_random1.js
index 1284e9b893e..c899ff8b776 100644
--- a/jstests/sharding/geo_near_random1.js
+++ b/jstests/sharding/geo_near_random1.js
@@ -11,6 +11,7 @@ db = s.getDB("test"); // global db
var test = new GeoNearRandomTest(testName);
s.adminCommand({enablesharding:'test'});
+s.ensurePrimaryShard('test', 'shard0001');
s.adminCommand({shardcollection: ('test.' + testName), key: {_id:1} });
test.insertPts(50);
diff --git a/jstests/sharding/geo_near_random2.js b/jstests/sharding/geo_near_random2.js
index 621295ebc8d..1fd139017a6 100644
--- a/jstests/sharding/geo_near_random2.js
+++ b/jstests/sharding/geo_near_random2.js
@@ -11,6 +11,7 @@ db = s.getDB("test"); // global db
var test = new GeoNearRandomTest(testName);
s.adminCommand({enablesharding:'test'});
+s.ensurePrimaryShard('test', 'shard0001');
s.adminCommand({shardcollection: ('test.' + testName), key: {_id:1} });
test.insertPts(5000);
diff --git a/jstests/sharding/geo_shardedgeonear.js b/jstests/sharding/geo_shardedgeonear.js
index 85aef9eb894..caa1287be92 100644
--- a/jstests/sharding/geo_shardedgeonear.js
+++ b/jstests/sharding/geo_shardedgeonear.js
@@ -41,6 +41,7 @@ var sharded = new ShardingTest({shards: 3, verbose: 0, mongos: 1});
sharded.stopBalancer();
sharded.adminCommand( { enablesharding : "test" } );
var shardedDB = sharded.getDB('test');
+sharded.ensurePrimaryShard('test', 'shard0001');
printjson(shardedDB);
test(shardedDB, true, '2dsphere');
diff --git a/jstests/sharding/hash_basic.js b/jstests/sharding/hash_basic.js
index 0cd11e5c1bf..6ddefdbb552 100644
--- a/jstests/sharding/hash_basic.js
+++ b/jstests/sharding/hash_basic.js
@@ -6,6 +6,7 @@ st.stopBalancer();
var testDB = st.s.getDB('test');
testDB.adminCommand({ enableSharding: 'test' });
+st.ensurePrimaryShard('test', 'shard0001');;
testDB.adminCommand({ shardCollection: 'test.user', key: { x: 'hashed' }});
var configDB = st.s.getDB('config');
diff --git a/jstests/sharding/hash_shard1.js b/jstests/sharding/hash_shard1.js
index dc164324c2a..1021a26f8d8 100644
--- a/jstests/sharding/hash_shard1.js
+++ b/jstests/sharding/hash_shard1.js
@@ -9,6 +9,7 @@ var ns = dbname + "." + coll;
var db = s.getDB( dbname );
var t = db.getCollection( coll );
db.adminCommand( { enablesharding : dbname } );
+s.ensurePrimaryShard(dbname, 'shard0001');
// for simplicity start by turning off balancer
s.stopBalancer();
diff --git a/jstests/sharding/hash_shard_non_empty.js b/jstests/sharding/hash_shard_non_empty.js
index 25335f16610..c743e3a48ce 100644
--- a/jstests/sharding/hash_shard_non_empty.js
+++ b/jstests/sharding/hash_shard_non_empty.js
@@ -6,6 +6,7 @@ var dbname = "test";
var coll = "foo";
var db = s.getDB(dbname);
db.adminCommand({ enablesharding : dbname });
+s.ensurePrimaryShard('test', 'shard0001');
//for simplicity turn off balancer
s.stopBalancer();
diff --git a/jstests/sharding/hash_shard_num_chunks.js b/jstests/sharding/hash_shard_num_chunks.js
index ee7f752d3d4..608e7c7674c 100644
--- a/jstests/sharding/hash_shard_num_chunks.js
+++ b/jstests/sharding/hash_shard_num_chunks.js
@@ -6,6 +6,7 @@ var dbname = "test";
var coll = "foo";
var db = s.getDB(dbname);
db.adminCommand({ enablesharding : dbname });
+s.ensurePrimaryShard(dbname, 'shard0001');
//for simplicity turn off balancer
s.stopBalancer();
diff --git a/jstests/sharding/hash_skey_split.js b/jstests/sharding/hash_skey_split.js
index 817e6154c4a..4c24c8ab1b2 100644
--- a/jstests/sharding/hash_skey_split.js
+++ b/jstests/sharding/hash_skey_split.js
@@ -6,6 +6,7 @@ st.stopBalancer();
var configDB = st.s.getDB('config');
configDB.adminCommand({ enableSharding: 'test' });
+st.ensurePrimaryShard('test', 'shard0001');
configDB.adminCommand({ shardCollection: 'test.user', key: { x: 'hashed' }, numInitialChunks: 2 });
var metadata = st.d0.getDB('admin').runCommand({ getShardVersion: 'test.user',
diff --git a/jstests/sharding/in_memory_sort_limit.js b/jstests/sharding/in_memory_sort_limit.js
index 7dc494875e9..1ba8b2368a1 100644
--- a/jstests/sharding/in_memory_sort_limit.js
+++ b/jstests/sharding/in_memory_sort_limit.js
@@ -8,6 +8,7 @@
var db = st.s.getDB('test');
var mongosCol = db.getCollection('skip');
db.adminCommand({ enableSharding: 'test' });
+ st.ensurePrimaryShard('test', 'shard0001');
db.adminCommand({ shardCollection: 'test.skip', key: { _id: 1 }});
var filler = new Array(10000).toString();
@@ -38,4 +39,4 @@
jsTestLog("Test error with limit of " + failLimit + " on mongos");
assert.throws( function() {mongosCol.find().sort({x:1}).limit(failLimit).itcount(); } );
- })(); \ No newline at end of file
+ })();
diff --git a/jstests/sharding/index1.js b/jstests/sharding/index1.js
index 4d581837083..77ed3ba7444 100644
--- a/jstests/sharding/index1.js
+++ b/jstests/sharding/index1.js
@@ -18,7 +18,10 @@ for ( var i = 0; i < 22; i++ ) {
}
assert.writeOK(bulk.execute());
- if(i == 0) s.adminCommand( { enablesharding : "" + coll._db } );
+ if (i == 0) {
+ s.adminCommand({ enablesharding: "" + coll._db });
+ s.ensurePrimaryShard(coll.getDB().getName(), 'shard0001');
+ }
print("\n\n\n\n\nTest # " + i)
diff --git a/jstests/sharding/jumbo1.js b/jstests/sharding/jumbo1.js
index ccf31e83f2a..b8882f632ea 100644
--- a/jstests/sharding/jumbo1.js
+++ b/jstests/sharding/jumbo1.js
@@ -3,6 +3,7 @@
s = new ShardingTest( "jump1" , 2 /* numShards */, 2 /* verboseLevel */, 1 /* numMongos */, { chunksize : 1 } )
s.adminCommand( { enablesharding : "test" } );
+s.ensurePrimaryShard('test', 'shard0001');
s.adminCommand( { shardcollection : "test.foo" , key : { x : 1 } } );
db = s.getDB( "test" );
diff --git a/jstests/sharding/key_many.js b/jstests/sharding/key_many.js
index 5691932f83b..a458d5a9284 100644
--- a/jstests/sharding/key_many.js
+++ b/jstests/sharding/key_many.js
@@ -20,6 +20,7 @@ s.setBalancer( false )
s.adminCommand( { enablesharding : "test" } )
db = s.getDB( "test" );
+s.ensurePrimaryShard('test', 'shard0001');
primary = s.getServer( "test" ).getDB( "test" );
secondary = s.getOther( primary ).getDB( "test" );
diff --git a/jstests/sharding/key_string.js b/jstests/sharding/key_string.js
index 225cf019ee4..2b15e657497 100644
--- a/jstests/sharding/key_string.js
+++ b/jstests/sharding/key_string.js
@@ -5,6 +5,7 @@ s.stopBalancer();
db = s.getDB( "test" );
s.adminCommand( { enablesharding : "test" } )
+s.ensurePrimaryShard('test', 'shard0001');
s.adminCommand( { shardcollection : "test.foo" , key : { name : 1 } } );
primary = s.getServer( "test" ).getDB( "test" );
diff --git a/jstests/sharding/limit_push.js b/jstests/sharding/limit_push.js
index ad9d8b9a383..5aa9bd5bee0 100644
--- a/jstests/sharding/limit_push.js
+++ b/jstests/sharding/limit_push.js
@@ -15,6 +15,7 @@ assert.eq( 100 , db.limit_push.find().length() , "Incorrect number of documents"
// Shard the collection
s.adminCommand( { enablesharding : "test" } );
+s.ensurePrimaryShard('test', 'shard0001');
s.adminCommand( { shardcollection : "test.limit_push" , key : { x : 1 } } );
// Now split the and move the data between the shards
diff --git a/jstests/sharding/localhostAuthBypass.js b/jstests/sharding/localhostAuthBypass.js
index 5bd334fb9dc..7c0f8ae4999 100644
--- a/jstests/sharding/localhostAuthBypass.js
+++ b/jstests/sharding/localhostAuthBypass.js
@@ -60,7 +60,7 @@ var assertCannotRunCommands = function(mongo, st) {
assert.writeError(test.foo.remove({ _id: 0 }));
// Multi-shard
- assert.throws(function() {
+ assert.throws(function() {
test.foo.mapReduce(
function() { emit(1, 1); },
function(id, count) { return Array.sum(count); },
@@ -151,9 +151,12 @@ var authenticate = function(mongo) {
mongo.getDB("admin").auth(username, password);
};
-var setupSharding = function(mongo) {
+var setupSharding = function(shardingTest) {
+ var mongo = shardingTest.s;
+
print("============ enabling sharding on test.foo.");
mongo.getDB("admin").runCommand({enableSharding : "test"});
+ shardingTest.ensurePrimaryShard('test', 'shard0001');
mongo.getDB("admin").runCommand({shardCollection : "test.foo", key : {_id : 1}});
var test = mongo.getDB("test");
@@ -230,10 +233,10 @@ var runTest = function() {
createUser(mongo);
authenticate(mongo);
- setupSharding(mongo);
+ authenticate(st.s);
+ setupSharding(st);
addUsersToEachShard(st);
- authenticate(st.s);
st.printShardingStatus();
assertCanRunCommands(mongo, st);
diff --git a/jstests/sharding/mapReduce_inSharded.js b/jstests/sharding/mapReduce_inSharded.js
index 8616600bdda..ae35861fb5a 100644
--- a/jstests/sharding/mapReduce_inSharded.js
+++ b/jstests/sharding/mapReduce_inSharded.js
@@ -10,6 +10,7 @@ var st = new ShardingTest({ shards : 2, verbose : 1, mongos : 1, other : { chunk
st.startBalancer();
st.adminCommand( { enablesharding : "mrShard" } )
+st.ensurePrimaryShard('mrShard', 'shard0001');
st.adminCommand( { shardcollection : "mrShard.srcSharded", key : { "_id" : 1 } } )
var db = st.getDB( "mrShard" );
diff --git a/jstests/sharding/mapReduce_inSharded_outSharded.js b/jstests/sharding/mapReduce_inSharded_outSharded.js
index f0a8a09e779..69174f2589d 100644
--- a/jstests/sharding/mapReduce_inSharded_outSharded.js
+++ b/jstests/sharding/mapReduce_inSharded_outSharded.js
@@ -10,6 +10,7 @@ var st = new ShardingTest({ shards : 2, verbose : 1, mongos : 1, other : { chunk
st.startBalancer();
st.adminCommand( { enablesharding : "mrShard" } )
+st.ensurePrimaryShard('mrShard', 'shard0001');
st.adminCommand( { shardcollection : "mrShard.srcSharded", key : { "_id" : 1 } } )
var db = st.getDB( "mrShard" );
diff --git a/jstests/sharding/mapReduce_nonSharded.js b/jstests/sharding/mapReduce_nonSharded.js
index 7cef68622a3..cd1437b83a5 100644
--- a/jstests/sharding/mapReduce_nonSharded.js
+++ b/jstests/sharding/mapReduce_nonSharded.js
@@ -10,6 +10,7 @@ var st = new ShardingTest({ shards : 2, verbose : 1, mongos : 1, other : { chunk
st.startBalancer();
st.adminCommand( { enablesharding : "mrShard" } )
+st.ensurePrimaryShard('mrShard', 'shard0001');
st.adminCommand( { shardcollection : "mrShard.srcSharded", key : { "_id" : 1 } } )
var db = st.getDB( "mrShard" );
diff --git a/jstests/sharding/mapReduce_outSharded.js b/jstests/sharding/mapReduce_outSharded.js
index 4a9d4e40eca..a42eb166e65 100644
--- a/jstests/sharding/mapReduce_outSharded.js
+++ b/jstests/sharding/mapReduce_outSharded.js
@@ -10,6 +10,7 @@ var st = new ShardingTest({ shards : 2, verbose : 1, mongos : 1, other : { chunk
st.startBalancer();
st.adminCommand( { enablesharding : "mrShard" } )
+st.ensurePrimaryShard('mrShard', 'shard0001');
st.adminCommand( { shardcollection : "mrShard.srcSharded", key : { "_id" : 1 } } )
var db = st.getDB( "mrShard" );
diff --git a/jstests/sharding/migrateBig.js b/jstests/sharding/migrateBig.js
index bf28cad6ea7..424eddb9042 100644
--- a/jstests/sharding/migrateBig.js
+++ b/jstests/sharding/migrateBig.js
@@ -2,6 +2,7 @@
s = new ShardingTest( "migrateBig" , 2 , 0 , 1 , { chunksize : 1 } );
s.config.settings.update( { _id: "balancer" }, { $set : { stopped : true, _waitForDelete : true } } , true );
s.adminCommand( { enablesharding : "test" } );
+s.ensurePrimaryShard('test', 'shard0001');
s.adminCommand( { shardcollection : "test.foo" , key : { x : 1 } } );
db = s.getDB( "test" )
diff --git a/jstests/sharding/mongos_validate_writes.js b/jstests/sharding/mongos_validate_writes.js
index 3ef7b4715c3..d54349f8d6c 100644
--- a/jstests/sharding/mongos_validate_writes.js
+++ b/jstests/sharding/mongos_validate_writes.js
@@ -25,6 +25,7 @@ var staleCollA = staleMongosA.getCollection( coll + "" )
var staleCollB = staleMongosB.getCollection( coll + "" )
printjson( admin.runCommand({ enableSharding : coll.getDB() + "" }) )
+st.ensurePrimaryShard(coll.getDB().getName(), 'shard0001');
coll.ensureIndex({ a : 1 })
printjson( admin.runCommand({ shardCollection : coll + "", key : { a : 1 } }) )
diff --git a/jstests/sharding/movechunk_include.js b/jstests/sharding/movechunk_include.js
index 8ffa1664526..d2ea5e31e62 100644
--- a/jstests/sharding/movechunk_include.js
+++ b/jstests/sharding/movechunk_include.js
@@ -6,6 +6,7 @@ function setupMoveChunkTest(st) {
var testcoll = testdb.foo;
st.adminCommand( { enablesharding : "test" } );
+ st.ensurePrimaryShard('test', 'shard0001');
st.adminCommand( { shardcollection : "test.foo" , key : { _id : 1 } } );
var str = "";
diff --git a/jstests/sharding/moveprimary_ignore_sharded.js b/jstests/sharding/moveprimary_ignore_sharded.js
index c5fda358840..c378eb5856a 100644
--- a/jstests/sharding/moveprimary_ignore_sharded.js
+++ b/jstests/sharding/moveprimary_ignore_sharded.js
@@ -23,7 +23,9 @@ assert.writeOK(mongosA.getCollection("bar.coll2").insert({ hello : "world" }));
// Enable sharding
printjson( adminA.runCommand({ enableSharding : "foo" }) );
+st.ensurePrimaryShard('foo', 'shard0001');
printjson( adminA.runCommand({ enableSharding : "bar" }) );
+st.ensurePrimaryShard('bar', 'shard0000');
// Setup three collections per-db
// 0 : not sharded
diff --git a/jstests/sharding/multi_mongos2.js b/jstests/sharding/multi_mongos2.js
index d5ec67171b7..bcb66fc79e3 100644
--- a/jstests/sharding/multi_mongos2.js
+++ b/jstests/sharding/multi_mongos2.js
@@ -7,6 +7,7 @@ s1 = new ShardingTest( "multi_mongos1" , 2 , 1 , 2 );
s2 = s1._mongos[1];
s1.adminCommand( { enablesharding : "test" } );
+s1.ensurePrimaryShard('test', 'shard0001');
s1.adminCommand( { shardcollection : "test.foo" , key : { num : 1 } } );
s1.config.databases.find().forEach( printjson )
diff --git a/jstests/sharding/multi_mongos2a.js b/jstests/sharding/multi_mongos2a.js
index 9b907cc9478..75583f9cd91 100644
--- a/jstests/sharding/multi_mongos2a.js
+++ b/jstests/sharding/multi_mongos2a.js
@@ -7,6 +7,7 @@ s1 = new ShardingTest( "multi_mongos1" , 2 , 1 , 2 );
s2 = s1._mongos[1];
s1.adminCommand( { enablesharding : "test" } );
+s1.ensurePrimaryShard('test', 'shard0001');
s1.adminCommand( { shardcollection : "test.foo" , key : { num : 1 } } );
s1.config.databases.find().forEach( printjson )
diff --git a/jstests/sharding/parallel.js b/jstests/sharding/parallel.js
index ffaa967dba6..be2aab23d17 100644
--- a/jstests/sharding/parallel.js
+++ b/jstests/sharding/parallel.js
@@ -4,6 +4,7 @@ s = new ShardingTest( "parallel" , numShards , 2 , 2 , { sync : true } );
s.setBalancer( false )
s.adminCommand( { enablesharding : "test" } );
+s.ensurePrimaryShard('test', 'shard0001');
s.adminCommand( { shardcollection : "test.foo" , key : { _id : 1 } } );
db = s.getDB( "test" );
diff --git a/jstests/sharding/prefix_shard_key.js b/jstests/sharding/prefix_shard_key.js
index 632628ebf58..c83ac366ef6 100644
--- a/jstests/sharding/prefix_shard_key.js
+++ b/jstests/sharding/prefix_shard_key.js
@@ -17,6 +17,7 @@ var shard0 = new Mongo( shards[0].host );
var shard1 = new Mongo( shards[1].host );
s.adminCommand( { enablesharding : "test" } );
+s.ensurePrimaryShard('test', 'shard0001');
//******************Part 1********************
diff --git a/jstests/sharding/presplit.js b/jstests/sharding/presplit.js
index 6820a5fb332..894ea473a79 100644
--- a/jstests/sharding/presplit.js
+++ b/jstests/sharding/presplit.js
@@ -3,6 +3,9 @@
// Starts a new sharding environment limiting the chunksize to 1MB.
s = new ShardingTest( "presplit" , 2 , 2 , 1 , { chunksize : 1 } );
+s.adminCommand( { enablesharding : "test" } );
+s.ensurePrimaryShard('test', 'shard0001');
+
// Insert enough data in 'test.foo' to fill several chunks, if it was sharded.
bigString = "";
while ( bigString.length < 10000 ){
@@ -25,8 +28,6 @@ primary = s.getServer( "test" ).getDB( "test" );
assert.eq( 0 , s.config.chunks.count() , "single chunk assertion" );
assert.eq( num , primary.foo.count() );
-// Turn on sharding on the 'test.foo' collection
-s.adminCommand( { enablesharding : "test" } );
s.adminCommand( { shardcollection : "test.foo" , key : { _id : 1 } } );
// Make sure the collection's original chunk got split
diff --git a/jstests/sharding/remove2.js b/jstests/sharding/remove2.js
index da92ebd1d53..48bb95e1e95 100644
--- a/jstests/sharding/remove2.js
+++ b/jstests/sharding/remove2.js
@@ -71,16 +71,15 @@ addShard = function(st, replTest) {
print( "Shard added successfully" );
};
-var st = new ShardingTest( testName = "remove2",
- numShards = 2,
- verboseLevel = 0,
- numMongos = 1,
- { chunkSize : 1,
- rs : true,
- rs0 : { nodes : 2 },
- rs1 : { nodes : 2 },
- enableBalancer: true
- });
+var st = new ShardingTest({ shards: {
+ rs0: { nodes: 2 },
+ rs1: { nodes: 2 }
+ },
+ verbose: 0,
+ other: {
+ chunkSize: 1,
+ enableBalancer: true
+ }});
// Pending resolution of SERVER-8598, we need to wait for deletion after chunk migrations to avoid
// a pending delete re-creating a database after it was dropped.
@@ -104,6 +103,7 @@ for( var i = 0; i < rst0.nodes.length; i++ ) {
}
st.admin.runCommand({ enableSharding : coll.getDB().getName() });
+st.ensurePrimaryShard(coll.getDB().getName(), 'test-rs0');
st.admin.runCommand({ shardCollection : coll.getFullName(), key: { i : 1 }});
// Setup initial data
diff --git a/jstests/sharding/shard1.js b/jstests/sharding/shard1.js
index b14ec95f66f..c13b2888e8c 100644
--- a/jstests/sharding/shard1.js
+++ b/jstests/sharding/shard1.js
@@ -16,6 +16,7 @@ shardCommand = { shardcollection : "test.foo" , key : { num : 1 } };
assert.throws( function(){ s.adminCommand( shardCommand ); } );
s.adminCommand( { enablesharding : "test" } );
+s.ensurePrimaryShard('test', 'shard0001');
assert.eq( 3 , db.foo.find().length() , "after partitioning count failed" );
s.adminCommand( shardCommand );
diff --git a/jstests/sharding/shard2.js b/jstests/sharding/shard2.js
index 41b46158167..7c389f87558 100644
--- a/jstests/sharding/shard2.js
+++ b/jstests/sharding/shard2.js
@@ -27,6 +27,7 @@ s.stopBalancer()
db = s.getDB( "test" );
s.adminCommand( { enablesharding : "test" } );
+s.ensurePrimaryShard('test', 'shard0001');
s.adminCommand( { shardcollection : "test.foo" , key : { num : 1 } } );
assert.eq( 1 , s.config.chunks.count() , "sanity check 1" );
diff --git a/jstests/sharding/shard3.js b/jstests/sharding/shard3.js
index 290349aee58..197f90f3980 100644
--- a/jstests/sharding/shard3.js
+++ b/jstests/sharding/shard3.js
@@ -9,6 +9,7 @@ s2 = s._mongos[1];
db = s.getDB( "test" )
s.adminCommand( { enablesharding : "test" } );
+s.ensurePrimaryShard('test', 'shard0001');
s.adminCommand( { shardcollection : "test.foo" , key : { num : 1 } } );
assert( sh.getBalancerState() , "A1" )
@@ -145,6 +146,7 @@ assert.eq( 0 , doCounts( "after dropDatabase called" ) )
// ---- retry commands SERVER-1471 ----
s.adminCommand( { enablesharding : "test2" } );
+s.ensurePrimaryShard('test2', 'shard0000')
s.adminCommand( { shardcollection : "test2.foo" , key : { num : 1 } } );
dba = s.getDB( "test2" );
dbb = s2.getDB( "test2" );
diff --git a/jstests/sharding/shard4.js b/jstests/sharding/shard4.js
index 6b48b02bc2f..0252810460b 100644
--- a/jstests/sharding/shard4.js
+++ b/jstests/sharding/shard4.js
@@ -6,6 +6,7 @@ s.stopBalancer()
s2 = s._mongos[1];
s.adminCommand( { enablesharding : "test" } );
+s.ensurePrimaryShard('test', 'shard0001');
s.adminCommand( { shardcollection : "test.foo" , key : { num : 1 } } );
s.getDB( "test" ).foo.save( { num : 1 } );
diff --git a/jstests/sharding/shard5.js b/jstests/sharding/shard5.js
index 2dffecace9b..1822a3fcb81 100644
--- a/jstests/sharding/shard5.js
+++ b/jstests/sharding/shard5.js
@@ -8,6 +8,7 @@ s.stopBalancer();
s2 = s._mongos[1];
s.adminCommand( { enablesharding : "test" } );
+s.ensurePrimaryShard('test', 'shard0001');
s.adminCommand( { shardcollection : "test.foo" , key : { num : 1 } } );
s.getDB( "test" ).foo.save( { num : 1 } );
diff --git a/jstests/sharding/shard6.js b/jstests/sharding/shard6.js
index 55ae710ab44..1a7b5727f36 100644
--- a/jstests/sharding/shard6.js
+++ b/jstests/sharding/shard6.js
@@ -7,6 +7,7 @@ s = new ShardingTest( "shard6" , 2 , 0 , 2 );
s.config.settings.update( { _id: "balancer" }, { $set : { stopped: true } } , true );
s.adminCommand( { enablesharding : "test" } );
+s.ensurePrimaryShard('test', 'shard0001');
s.adminCommand( { shardcollection : "test.data" , key : { num : 1 } } );
db = s.getDB( "test" );
diff --git a/jstests/sharding/shard7.js b/jstests/sharding/shard7.js
index 7d37fdf60f6..77943686ead 100644
--- a/jstests/sharding/shard7.js
+++ b/jstests/sharding/shard7.js
@@ -8,6 +8,7 @@ c = db[ 'foo' ];
c.drop();
s.adminCommand( { enablesharding: '' + db } );
+s.ensurePrimaryShard(db.getName(), 'shard0001');
s.adminCommand( { shardcollection: '' + c, key: { a:1,b:1 } } );
// Check query operation with some satisfiable and unsatisfiable queries.
diff --git a/jstests/sharding/shard_existing.js b/jstests/sharding/shard_existing.js
index e6a55040877..f2dca5a7b7a 100644
--- a/jstests/sharding/shard_existing.js
+++ b/jstests/sharding/shard_existing.js
@@ -23,6 +23,7 @@ var dataSize = db.data.stats().size;
assert.lte(totalSize, dataSize);
s.adminCommand( { enablesharding : "test" } );
+s.ensurePrimaryShard('test', 'shard0001');
res = s.adminCommand( { shardcollection : "test.data" , key : { _id : 1 } } );
printjson(res);
diff --git a/jstests/sharding/shard_key_immutable.js b/jstests/sharding/shard_key_immutable.js
index 0cd79d4252d..c05ff17e365 100644
--- a/jstests/sharding/shard_key_immutable.js
+++ b/jstests/sharding/shard_key_immutable.js
@@ -40,6 +40,7 @@
var st = new ShardingTest({ shards: 2 });
st.adminCommand({ enablesharding: "test" });
+st.ensurePrimaryShard('test', 'shard0001');
st.adminCommand({ shardcollection: "test.col0", key: { a: 1, b: 1 }});
st.adminCommand({ shardcollection: "test.col1", key: { 'x.a': 1 }});
diff --git a/jstests/sharding/shard_keycount.js b/jstests/sharding/shard_keycount.js
index e2bedcb5bdb..408774785c8 100644
--- a/jstests/sharding/shard_keycount.js
+++ b/jstests/sharding/shard_keycount.js
@@ -17,6 +17,7 @@ for(var i = 0; i < 10; i++){
// Enable sharding on DB
s.adminCommand( { enablesharding : dbName } );
+s.ensurePrimaryShard(dbName, 'shard0001');
// Enable sharding on collection
s.adminCommand( { shardcollection : ns, key : { _id : 1 } } );
diff --git a/jstests/sharding/shard_targeting.js b/jstests/sharding/shard_targeting.js
index 7b47a2907cd..6a2634f40a0 100644
--- a/jstests/sharding/shard_targeting.js
+++ b/jstests/sharding/shard_targeting.js
@@ -6,6 +6,7 @@
var s = new ShardingTest("shard_targeting", 2, 0, 1);
s.adminCommand({ enablesharding : "test" });
+s.ensurePrimaryShard('test', 'shard0001');
s.stopBalancer();
var db = s.getDB("test");
diff --git a/jstests/sharding/shard_with_special_db_names.js b/jstests/sharding/shard_with_special_db_names.js
index 7277abac580..2887f364743 100644
--- a/jstests/sharding/shard_with_special_db_names.js
+++ b/jstests/sharding/shard_with_special_db_names.js
@@ -5,11 +5,13 @@ var specialDB = "[a-z]+";
var specialNS = specialDB + ".special";
s.adminCommand( { enablesharding : "test" } );
+s.ensurePrimaryShard('test', 'shard0001');
s.adminCommand( { shardcollection : "test.data" , key : { num : 1 } } );
// Test that the database will not complain "cannot have 2 database names that
// differs on case"
s.adminCommand( { enablesharding : specialDB } );
+s.ensurePrimaryShard(specialDB, 'shard0000');
s.adminCommand( { shardcollection : specialNS, key : { num : 1 } } );
var exists = s.getDB("config").collections.find( { _id: specialNS } ).count();
diff --git a/jstests/sharding/sharding_system_namespaces.js b/jstests/sharding/sharding_system_namespaces.js
index 894230f76e1..b27c3635c5d 100644
--- a/jstests/sharding/sharding_system_namespaces.js
+++ b/jstests/sharding/sharding_system_namespaces.js
@@ -44,6 +44,7 @@ if (Array.contains(storageEngines, "wiredTiger")) {
checkCollectionOptions(db);
assert.commandWorked(db.adminCommand({ enableSharding: 'test' }));
+ st.ensurePrimaryShard('test', 'shard0001');
assert.commandWorked(db.adminCommand({ shardCollection: coll + '', key: { x: 1 }}));
coll.insert({x: 0});
diff --git a/jstests/sharding/sort1.js b/jstests/sharding/sort1.js
index aea55741251..f2a682a82d2 100644
--- a/jstests/sharding/sort1.js
+++ b/jstests/sharding/sort1.js
@@ -3,6 +3,7 @@ s = new ShardingTest( "sort1" , 2 , 0 , 2 )
s.stopBalancer();
s.adminCommand( { enablesharding : "test" } );
+s.ensurePrimaryShard('test', 'shard0001');
s.adminCommand( { shardcollection : "test.data" , key : { 'sub.num' : 1 } } );
db = s.getDB( "test" );
diff --git a/jstests/sharding/stats.js b/jstests/sharding/stats.js
index 41fa2534cf7..6c21e3861da 100644
--- a/jstests/sharding/stats.js
+++ b/jstests/sharding/stats.js
@@ -5,6 +5,7 @@ a = s._connections[0].getDB( "test" );
b = s._connections[1].getDB( "test" );
db = s.getDB( "test" );
+s.ensurePrimaryShard('test', 'shard0001');
function numKeys(o){
var num = 0;
diff --git a/jstests/sharding/sync2.js b/jstests/sharding/sync2.js
index bdb639e59e5..de4ea6b2ddc 100644
--- a/jstests/sharding/sync2.js
+++ b/jstests/sharding/sync2.js
@@ -6,6 +6,7 @@ s.stopBalancer()
var s2 = s._mongos[1];
s.adminCommand( { enablesharding : "test" } );
+s.ensurePrimaryShard('test', 'shard0001');
s.adminCommand( { shardcollection : "test.foo" , key : { num : 1 } } );
s.config.settings.update( { _id: "balancer" }, { $set : { stopped: true } } , true );
diff --git a/jstests/sharding/tag_auto_split.js b/jstests/sharding/tag_auto_split.js
index 80dae792b10..5e2fe256619 100644
--- a/jstests/sharding/tag_auto_split.js
+++ b/jstests/sharding/tag_auto_split.js
@@ -5,6 +5,7 @@ s = new ShardingTest( "tag_auto_split", 2, 0, 1, { nopreallocj : true, enableBal
db = s.getDB( "test" );
s.adminCommand( { enablesharding : "test" } )
+s.ensurePrimaryShard('test', 'shard0001');
s.adminCommand( { shardcollection : "test.foo" , key : { _id : 1 } } );
assert.eq( 1, s.config.chunks.count() );
@@ -29,6 +30,7 @@ s = new ShardingTest( "tag_auto_split2", 2, 0, 1, { nopreallocj : true, enableBa
db = s.getDB( "test" );
s.adminCommand( { enablesharding : "test" } )
+s.ensurePrimaryShard('test', 'shard0001');
s.adminCommand( { shardcollection : "test.foo" , key : { _id : 1, a : 1 } } );
assert.eq( 1, s.config.chunks.count() );
diff --git a/jstests/sharding/tag_range.js b/jstests/sharding/tag_range.js
index 8d8244c82c1..e934a0b01e9 100644
--- a/jstests/sharding/tag_range.js
+++ b/jstests/sharding/tag_range.js
@@ -10,6 +10,7 @@ s = new ShardingTest( "tag_range" , 2 , 0 , 1 , { nopreallocj : true } );
db = s.getDB( "tag_range" );
s.adminCommand( { enableSharding : "test" } );
+s.ensurePrimaryShard('test', 'shard0001');
s.adminCommand( { shardCollection : "test.tag_range" , key : { _id : 1 } } );
assert.eq( 1 , s.config.chunks.count() );
diff --git a/jstests/sharding/update_immutable_fields.js b/jstests/sharding/update_immutable_fields.js
index 87ef28477ce..0ba27bd2706 100644
--- a/jstests/sharding/update_immutable_fields.js
+++ b/jstests/sharding/update_immutable_fields.js
@@ -10,6 +10,7 @@ var coll = mongos.getCollection(jsTestName() + ".coll1");
var shard0 = st.shard0;
printjson(config.adminCommand({enableSharding : coll.getDB() + ""}))
+st.ensurePrimaryShard(coll.getDB().getName(), 'shard0000');
printjson(config.adminCommand({shardCollection : "" + coll, key : {a : 1}}))
var getDirectShardedConn = function( st, collName ) {
diff --git a/jstests/sharding/update_sharded.js b/jstests/sharding/update_sharded.js
index 466e7bfdfa8..948781e6d66 100644
--- a/jstests/sharding/update_sharded.js
+++ b/jstests/sharding/update_sharded.js
@@ -4,6 +4,7 @@
s = new ShardingTest( "auto1" , 2 , 1 , 1 );
s.adminCommand( { enablesharding : "test" } );
+s.ensurePrimaryShard('test', 'shard0001');
// repeat same tests with hashed shard key, to ensure identical behavior
s.adminCommand( { shardcollection : "test.update0" , key : { key : 1 } } );
s.adminCommand( { shardcollection : "test.update1" , key : { key : "hashed" } } );
diff --git a/jstests/sharding/upsert_sharded.js b/jstests/sharding/upsert_sharded.js
index fad0218da8c..885dc23fcfa 100644
--- a/jstests/sharding/upsert_sharded.js
+++ b/jstests/sharding/upsert_sharded.js
@@ -14,6 +14,7 @@ var shards = mongos.getCollection( "config.shards" ).find().toArray();
var coll = mongos.getCollection( "foo.bar" );
assert( admin.runCommand({ enableSharding : coll.getDB() + "" }).ok );
+st.ensurePrimaryShard(coll.getDB().getName(), 'shard0001');
var upsertedResult = function(query, expr) {
coll.remove({});
diff --git a/jstests/sharding/zbigMapReduce.js b/jstests/sharding/zbigMapReduce.js
index 0dbda139fd4..79813ff06fd 100644
--- a/jstests/sharding/zbigMapReduce.js
+++ b/jstests/sharding/zbigMapReduce.js
@@ -17,6 +17,7 @@ function setupTest() {
config.settings.save({_id: "chunksize", value: 1});
s.adminCommand( { enablesharding : "test" } )
+ s.ensurePrimaryShard('test', 'test-rs0');
s.adminCommand( { shardcollection : "test.foo", key : { "_id" : 1 } } )
return s;
}
diff --git a/jstests/slow1/sharding_multiple_collections.js b/jstests/slow1/sharding_multiple_collections.js
index 6577e0050fa..922087ba2aa 100644
--- a/jstests/slow1/sharding_multiple_collections.js
+++ b/jstests/slow1/sharding_multiple_collections.js
@@ -3,8 +3,8 @@
s = new ShardingTest( "multcollections" , 2 , 1 , 1 , { chunksize : 1, enableBalancer : true } );
s.adminCommand( { enablesharding : "test" } );
-
db = s.getDB( "test" )
+s.ensurePrimaryShard('test', 'shard0001');
N = 100000
diff --git a/jstests/slow2/cursor_timeout.js b/jstests/slow2/cursor_timeout.js
index 3e80e6c6fa7..4fe24727391 100644
--- a/jstests/slow2/cursor_timeout.js
+++ b/jstests/slow2/cursor_timeout.js
@@ -6,6 +6,7 @@ var configDB = st.config;
var coll = st.s.getDB( 'test' ).user;
adminDB.runCommand({ enableSharding: coll.getDB().getName() });
+st.ensurePrimaryShard(coll.getDB().getName(), 'shard0001');
adminDB.runCommand({ shardCollection: coll.getFullName(), key: { x: 1 }});
var data = 'c';
diff --git a/jstests/tool/dumprestore9.js b/jstests/tool/dumprestore9.js
index cef9a623cf1..8661452c4dd 100644
--- a/jstests/tool/dumprestore9.js
+++ b/jstests/tool/dumprestore9.js
@@ -11,6 +11,7 @@ s = new ShardingTest( "dumprestore9a", 2, 0, 3, { chunksize : 1, enableBalancer
step("Shard collection");
s.adminCommand( { enablesharding : "aaa" } ); // Make this db alphabetically before 'config' so it gets restored first
+s.ensurePrimaryShard('aaa', 'shard0001');
s.adminCommand( { shardcollection : "aaa.foo" , key : { x : 1 } } );
db = s.getDB( "aaa" );
@@ -76,4 +77,4 @@ for (var i = 0; i < s._connections.length; i++) {
step("Stop cluster");
s.stop();
step("SUCCESS");
-} \ No newline at end of file
+}