Skip to content

Commit

Permalink
SERVER-18044 Make sharding test explicitly set primary shards for dat…
Browse files Browse the repository at this point in the history
…abases
  • Loading branch information
renctan committed May 15, 2015
1 parent f3d242c commit 280fbae
Show file tree
Hide file tree
Showing 95 changed files with 159 additions and 43 deletions.
1 change: 1 addition & 0 deletions jstests/aggregation/bugs/server6118.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions jstests/aggregation/bugs/server6179.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
2 changes: 1 addition & 1 deletion jstests/aggregation/bugs/server7781.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down
1 change: 1 addition & 0 deletions jstests/aggregation/testshard1.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions jstests/gle/1_sharding_gle_basics_passthrough.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -46,4 +46,4 @@
db = lastDB;
passST.stop();

}());
}());
1 change: 1 addition & 0 deletions jstests/multiVersion/balancer_multiVersion_detect.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
5 changes: 3 additions & 2 deletions jstests/multiVersion/explain.js
Original file line number Diff line number Diff line change
Expand Up @@ -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});
Expand Down Expand Up @@ -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});
Expand Down Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions jstests/noPassthroughWithMongod/balance_repl.js
Original file line number Diff line number Diff line change
Expand Up @@ -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++ )
Expand Down
6 changes: 4 additions & 2 deletions jstests/noPassthroughWithMongod/balance_tags1.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
7 changes: 4 additions & 3 deletions jstests/noPassthroughWithMongod/balance_tags2.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
6 changes: 4 additions & 2 deletions jstests/noPassthroughWithMongod/large_chunk.js
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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" );
Expand Down
1 change: 1 addition & 0 deletions jstests/noPassthroughWithMongod/sharding_balance1.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 )

Expand Down
1 change: 1 addition & 0 deletions jstests/noPassthroughWithMongod/sharding_balance3.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 );

Expand Down
1 change: 1 addition & 0 deletions jstests/noPassthroughWithMongod/sharding_balance4.js
Original file line number Diff line number Diff line change
Expand Up @@ -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" );

Expand Down
5 changes: 3 additions & 2 deletions jstests/noPassthroughWithMongod/sharding_migrateBigObject.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 } })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ""
Expand Down
4 changes: 3 additions & 1 deletion jstests/noPassthroughWithMongod/sharding_rs1.js
Original file line number Diff line number Diff line change
@@ -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 )
Expand Down
4 changes: 3 additions & 1 deletion jstests/noPassthroughWithMongod/sharding_rs2.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 ----------------
// -------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions jstests/noPassthroughWithMongod/ttl_sharded.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions jstests/sharding/SERVER-7379.js
Original file line number Diff line number Diff line change
@@ -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');
Expand Down
1 change: 1 addition & 0 deletions jstests/sharding/authCommands.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion jstests/sharding/authConnectionHook.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -42,4 +43,4 @@ assert.soon( function() {
printjson(db.foo.findOne({x:25}));
printjson(db.foo.findOne({x:75}));

st.stop();
st.stop();
1 change: 1 addition & 0 deletions jstests/sharding/auto1.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "";
Expand Down
1 change: 1 addition & 0 deletions jstests/sharding/auto2.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "";
Expand Down
1 change: 1 addition & 0 deletions jstests/sharding/batch_write_command_sharded.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 } }));

Expand Down
5 changes: 3 additions & 2 deletions jstests/sharding/bouncing_count.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -46,4 +47,4 @@ jsTestLog( "Running count!" )
printjson( collB.count() )
printjson( collC.find().toArray() )

st.stop()
st.stop()
3 changes: 2 additions & 1 deletion jstests/sharding/coll_epoch_test0.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -44,4 +45,4 @@ printjson( admin.runCommand({ moveChunk : coll + "", find : { _id : 0 }, to : no
// Check all the chunks for epochs
checkEpochs();

st.stop()
st.stop()
2 changes: 2 additions & 0 deletions jstests/sharding/coll_epoch_test1.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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 } })

Expand Down
2 changes: 2 additions & 0 deletions jstests/sharding/coll_epoch_test2.js
Original file line number Diff line number Diff line change
Expand Up @@ -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" }));
Expand Down Expand Up @@ -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();
Expand Down
1 change: 1 addition & 0 deletions jstests/sharding/count1.js
Original file line number Diff line number Diff line change
Expand Up @@ -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" );
Expand Down
1 change: 1 addition & 0 deletions jstests/sharding/count2.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions jstests/sharding/cursor1.js
Original file line number Diff line number Diff line change
Expand Up @@ -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" );
Expand Down
Loading

0 comments on commit 280fbae

Please sign in to comment.