summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKaloian Manassiev <kaloian.manassiev@mongodb.com>2016-10-14 15:14:40 -0400
committerKaloian Manassiev <kaloian.manassiev@mongodb.com>2016-10-17 15:56:22 -0400
commit347da1ac7c27043421972ae4a2faddfbf9f0db38 (patch)
tree6c51da086edce409b1ed5af8565445eb470a2f38
parentbb7179c0aa703ee2df76acabdd425bcf1371d780 (diff)
downloadmongo-347da1ac7c27043421972ae4a2faddfbf9f0db38.tar.gz
SERVER-26645 Get rid of _shardNames variable in ShardingTest
-rw-r--r--jstests/libs/write_concern_util.js2
-rw-r--r--jstests/noPassthroughWithMongod/no_balance_collection.js4
-rw-r--r--jstests/sharding/commands_that_write_accept_wc_shards.js22
-rw-r--r--jstests/sharding/delayed_shard_identity_upsert.js10
-rw-r--r--jstests/sharding/inserts_consistent.js107
-rw-r--r--jstests/sharding/move_chunk_wc.js4
-rw-r--r--src/mongo/shell/shardingtest.js9
7 files changed, 70 insertions, 88 deletions
diff --git a/jstests/libs/write_concern_util.js b/jstests/libs/write_concern_util.js
index e4ab84361c4..a11fd464240 100644
--- a/jstests/libs/write_concern_util.js
+++ b/jstests/libs/write_concern_util.js
@@ -7,7 +7,7 @@ function shardCollectionWithChunks(st, coll) {
var _db = coll.getDB();
var numberDoc = 20;
coll.ensureIndex({x: 1}, {unique: true});
- st.ensurePrimaryShard(_db.toString(), st._shardNames[0]);
+ st.ensurePrimaryShard(_db.toString(), st.shard0.shardName);
st.shardColl(
coll.getName(), {x: 1}, {x: numberDoc / 2}, {x: numberDoc / 2}, _db.toString(), true);
diff --git a/jstests/noPassthroughWithMongod/no_balance_collection.js b/jstests/noPassthroughWithMongod/no_balance_collection.js
index f6627181b8d..6f238d7b421 100644
--- a/jstests/noPassthroughWithMongod/no_balance_collection.js
+++ b/jstests/noPassthroughWithMongod/no_balance_collection.js
@@ -6,8 +6,8 @@ var st = new ShardingTest({shards: 2, mongos: 1});
assert.throws(sh.disableBalancing, [], "sh.disableBalancing requires a collection");
assert.throws(sh.enableBalancing, [], "sh.enableBalancing requires a collection");
-var shardAName = st._shardNames[0];
-var shardBName = st._shardNames[1];
+var shardAName = st.shard0.shardName;
+var shardBName = st.shard1.shardName;
var collA = st.s.getCollection(jsTest.name() + ".collA");
var collB = st.s.getCollection(jsTest.name() + ".collB");
diff --git a/jstests/sharding/commands_that_write_accept_wc_shards.js b/jstests/sharding/commands_that_write_accept_wc_shards.js
index 5620ac94ade..1637938b4eb 100644
--- a/jstests/sharding/commands_that_write_accept_wc_shards.js
+++ b/jstests/sharding/commands_that_write_accept_wc_shards.js
@@ -29,7 +29,7 @@ load('jstests/libs/write_concern_util.js');
db.runCommand({dropDatabase: 1});
db.extra.insert({a: 1});
coll = db[collName];
- st.ensurePrimaryShard(db.toString(), st._shardNames[0]);
+ st.ensurePrimaryShard(db.toString(), st.shard0.shardName);
assert.eq(0, coll.find().itcount(), "test collection not empty");
assert.eq(1, db.extra.find().itcount(), "extra collection should have 1 document");
}
@@ -56,7 +56,7 @@ load('jstests/libs/write_concern_util.js');
req: {createIndexes: collName, indexes: [{key: {'type': 1}, name: 'type_index'}]},
setupFunc: function() {
coll.insert({type: 'oak'});
- st.ensurePrimaryShard(db.toString(), st._shardNames[0]);
+ st.ensurePrimaryShard(db.toString(), st.shard0.shardName);
assert.eq(coll.getIndexes().length, 1);
},
confirmFunc: function() {
@@ -84,7 +84,7 @@ load('jstests/libs/write_concern_util.js');
db = db.getSiblingDB("renameCollWC");
// Ensure that database is created.
db.leaves.insert({type: 'oak'});
- st.ensurePrimaryShard(db.toString(), st._shardNames[0]);
+ st.ensurePrimaryShard(db.toString(), st.shard0.shardName);
db.leaves.drop();
db.pine_needles.drop();
db.leaves.insert({type: 'oak'});
@@ -367,38 +367,38 @@ load('jstests/libs/write_concern_util.js');
// Create a non-sharded collection in the move-primary-db.
db.getSiblingDB("move-primary-db-sharded").nonshardColl.insert({a: 1});
commands.push({
- req: {movePrimary: "move-primary-db-sharded", to: st._shardNames[1]},
+ req: {movePrimary: "move-primary-db-sharded", to: st.shard1.shardName},
setupFunc: function() {
- st.ensurePrimaryShard("move-primary-db-sharded", st._shardNames[0]);
+ st.ensurePrimaryShard("move-primary-db-sharded", st.shard0.shardName);
assert.eq(db.getSiblingDB('config')
.databases.findOne({_id: 'move-primary-db-sharded'})
.primary,
- st._shardNames[0]);
+ st.shard0.shardName);
},
confirmFunc: function() {
assert.eq(db.getSiblingDB('config')
.databases.findOne({_id: 'move-primary-db-sharded'})
.primary,
- st._shardNames[1]);
+ st.shard1.shardName);
},
admin: true
});
commands.push({
- req: {movePrimary: "move-primary-db-unsharded", to: st._shardNames[1]},
+ req: {movePrimary: "move-primary-db-unsharded", to: st.shard1.shardName},
setupFunc: function() {
db.getSiblingDB("move-primary-db-unsharded").nonshardColl.insert({a: 1});
- st.ensurePrimaryShard("move-primary-db-unsharded", st._shardNames[0]);
+ st.ensurePrimaryShard("move-primary-db-unsharded", st.shard0.shardName);
assert.eq(db.getSiblingDB('config')
.databases.findOne({_id: 'move-primary-db-unsharded'})
.primary,
- st._shardNames[0]);
+ st.shard0.shardName);
},
confirmFunc: function() {
assert.eq(db.getSiblingDB('config')
.databases.findOne({_id: 'move-primary-db-unsharded'})
.primary,
- st._shardNames[1]);
+ st.shard1.shardName);
},
admin: true
});
diff --git a/jstests/sharding/delayed_shard_identity_upsert.js b/jstests/sharding/delayed_shard_identity_upsert.js
index 5662f9d8412..d2d3a59054f 100644
--- a/jstests/sharding/delayed_shard_identity_upsert.js
+++ b/jstests/sharding/delayed_shard_identity_upsert.js
@@ -21,7 +21,7 @@
var testDB = st.s.getDB("test");
assert.commandWorked(testDB.adminCommand({enableSharding: testDB.getName()}));
- st.ensurePrimaryShard(testDB.getName(), st._shardNames[0]);
+ st.ensurePrimaryShard(testDB.getName(), st.shard0.shardName);
// Create a collection sharded on {a: 1}. Add 2dsphere index to test geoNear.
var coll = testDB.getCollection("sharded");
@@ -38,10 +38,10 @@
var chunk3Min = 10;
assert.commandWorked(testDB.adminCommand({split: coll.getFullName(), middle: {a: chunk2Min}}));
assert.commandWorked(testDB.adminCommand({split: coll.getFullName(), middle: {a: chunk3Min}}));
- assert.commandWorked(
- testDB.adminCommand({moveChunk: coll.getFullName(), find: {a: 5}, to: st._shardNames[1]}));
- assert.commandWorked(
- testDB.adminCommand({moveChunk: coll.getFullName(), find: {a: 15}, to: st._shardNames[2]}));
+ assert.commandWorked(testDB.adminCommand(
+ {moveChunk: coll.getFullName(), find: {a: 5}, to: st.shard1.shardName}));
+ assert.commandWorked(testDB.adminCommand(
+ {moveChunk: coll.getFullName(), find: {a: 15}, to: st.shard2.shardName}));
// Put data on each shard.
// Note that the balancer is off by default, so the chunks will stay put.
diff --git a/jstests/sharding/inserts_consistent.js b/jstests/sharding/inserts_consistent.js
index b4ee71bbe7a..86db9ae4e82 100644
--- a/jstests/sharding/inserts_consistent.js
+++ b/jstests/sharding/inserts_consistent.js
@@ -1,84 +1,71 @@
// Test write re-routing on version mismatch.
+(function() {
+ 'use strict';
-var st = new ShardingTest({shards: 2, mongos: 2, verbose: 2});
+ var st = new ShardingTest({shards: 2, mongos: 2});
-jsTest.log("Doing test setup...");
+ var mongos = st.s;
+ var admin = mongos.getDB("admin");
+ var config = mongos.getDB("config");
+ var coll = st.s.getCollection('TestDB.coll');
-// Stop balancer, since it'll just get in the way of this
-st.stopBalancer();
+ assert.commandWorked(mongos.adminCommand({enableSharding: 'TestDB'}));
+ st.ensurePrimaryShard('TestDB', st.shard0.shardName);
+ assert.commandWorked(mongos.adminCommand({shardCollection: 'TestDB.coll', key: {_id: 1}}));
-var mongos = st.s;
-var admin = mongos.getDB("admin");
-var config = mongos.getDB("config");
-var coll = st.s.getCollection(jsTest.name() + ".coll");
+ jsTest.log("Refreshing second mongos...");
-st.shardColl(coll, {_id: 1}, {_id: 0}, false);
+ var mongosB = st.s1;
+ var adminB = mongosB.getDB("admin");
+ var collB = mongosB.getCollection(coll + "");
-jsTest.log("Refreshing second mongos...");
+ // Make sure mongosB knows about the coll
+ assert.eq(0, collB.find().itcount());
-var mongosB = st.s1;
-var adminB = mongosB.getDB("admin");
-var collB = mongosB.getCollection(coll + "");
+ jsTest.log("Moving chunk to create stale mongos...");
+ assert.commandWorked(
+ admin.runCommand({moveChunk: coll + "", find: {_id: 0}, to: st.shard1.shardName}));
-// Make sure mongosB knows about the coll
-assert.eq(0, collB.find().itcount());
-// printjson( adminB.runCommand({ flushRouterConfig : 1 }) )
+ jsTest.log("Inserting docs that needs to be retried...");
-jsTest.log("Moving chunk to create stale mongos...");
-
-var otherShard = config.chunks.findOne({_id: sh._collRE(coll)}).shard;
-for (var i = 0; i < st._shardNames.length; i++) {
- if (otherShard != st._shardNames[i]) {
- otherShard = st._shardNames[i];
- break;
+ var nextId = -1;
+ for (var i = 0; i < 2; i++) {
+ printjson("Inserting " + nextId);
+ assert.writeOK(collB.insert({_id: nextId--, hello: "world"}));
}
-}
-
-print("Other shard : " + otherShard);
-
-printjson(admin.runCommand({moveChunk: coll + "", find: {_id: 0}, to: otherShard}));
-
-jsTest.log("Inserting docs that needs to be retried...");
-var nextId = -1;
-for (var i = 0; i < 2; i++) {
- printjson("Inserting " + nextId);
- assert.writeOK(collB.insert({_id: nextId--, hello: "world"}));
-}
+ jsTest.log("Inserting doc which successfully goes through...");
-jsTest.log("Inserting doc which successfully goes through...");
+ // Do second write
+ assert.writeOK(collB.insert({_id: nextId--, goodbye: "world"}));
-// Do second write
-assert.writeOK(collB.insert({_id: nextId--, goodbye: "world"}));
+ // Assert that write went through
+ assert.eq(coll.find().itcount(), 3);
-// Assert that write went through
-assert.eq(coll.find().itcount(), 3);
+ jsTest.log("Now try moving the actual chunk we're writing to...");
-jsTest.log("Now try moving the actual chunk we're writing to...");
+ // Now move the actual chunk we're writing to
+ printjson(admin.runCommand({moveChunk: coll + "", find: {_id: -1}, to: st.shard1.shardName}));
-// Now move the actual chunk we're writing to
-printjson(admin.runCommand({moveChunk: coll + "", find: {_id: -1}, to: otherShard}));
+ jsTest.log("Inserting second docs to get written back...");
-jsTest.log("Inserting second docs to get written back...");
-
-// Will fail entirely if too many of these, waiting for write to get applied can get too long.
-for (var i = 0; i < 2; i++) {
- collB.insert({_id: nextId--, hello: "world"});
-}
-
-// Refresh server
-printjson(adminB.runCommand({flushRouterConfig: 1}));
+ // Will fail entirely if too many of these, waiting for write to get applied can get too long.
+ for (var i = 0; i < 2; i++) {
+ collB.insert({_id: nextId--, hello: "world"});
+ }
-jsTest.log("Inserting second doc which successfully goes through...");
+ // Refresh server
+ printjson(adminB.runCommand({flushRouterConfig: 1}));
-// Do second write
-assert.writeOK(collB.insert({_id: nextId--, goodbye: "world"}));
+ jsTest.log("Inserting second doc which successfully goes through...");
-jsTest.log("All docs written this time!");
+ // Do second write
+ assert.writeOK(collB.insert({_id: nextId--, goodbye: "world"}));
-// Assert that writes went through.
-assert.eq(coll.find().itcount(), 6);
+ jsTest.log("All docs written this time!");
-jsTest.log("DONE");
+ // Assert that writes went through.
+ assert.eq(coll.find().itcount(), 6);
-st.stop();
+ st.stop();
+})();
diff --git a/jstests/sharding/move_chunk_wc.js b/jstests/sharding/move_chunk_wc.js
index 54a41c2d9fa..85ae3400652 100644
--- a/jstests/sharding/move_chunk_wc.js
+++ b/jstests/sharding/move_chunk_wc.js
@@ -28,8 +28,8 @@ load('jstests/libs/write_concern_util.js');
var collName = 'leaves';
var coll = db[collName];
var numberDoc = 20;
- var s0 = st._shardNames[0];
- var s1 = st._shardNames[1];
+ var s0 = st.shard0.shardName;
+ var s1 = st.shard1.shardName;
coll.ensureIndex({x: 1}, {unique: true});
st.ensurePrimaryShard(db.toString(), s0);
diff --git a/src/mongo/shell/shardingtest.js b/src/mongo/shell/shardingtest.js
index 9ee9deeb14b..c9314aea8b8 100644
--- a/src/mongo/shell/shardingtest.js
+++ b/src/mongo/shell/shardingtest.js
@@ -1411,21 +1411,16 @@ var ShardingTest = function(params) {
try {
if (!otherParams.manualAddShard) {
- this._shardNames = [];
-
var testName = this._testName;
var admin = this.admin;
- var shardNames = this._shardNames;
this._connections.forEach(function(z) {
var n = z.name || z.host || z;
print("ShardingTest " + testName + " going to add shard : " + n);
- var result = admin.runCommand({addshard: n});
- assert.commandWorked(result, "Failed to add shard " + n);
-
- shardNames.push(result.shardAdded);
+ var result = assert.commandWorked(admin.runCommand({addshard: n}),
+ "Failed to add shard " + n);
z.shardName = result.shardAdded;
});
}