summaryrefslogtreecommitdiff
path: root/src/mongo/shell/shardingtest.js
diff options
context:
space:
mode:
authorJonathan Abrahams <jonathan@mongodb.com>2016-03-09 11:51:31 -0500
committerJonathan Abrahams <jonathan@mongodb.com>2016-03-09 11:51:31 -0500
commita025d43f3ce2efc1fb1282a718f5d286fa0a4dc1 (patch)
treea71ec459d031c8b76ebe1efc20a1150339161949 /src/mongo/shell/shardingtest.js
parent4019e38d105597df8320e4958cc2be784157378d (diff)
downloadmongo-a025d43f3ce2efc1fb1282a718f5d286fa0a4dc1.tar.gz
SERVER-22469 Format JS code with approved style in src/mongo/shell & src/mongo/scripting
Diffstat (limited to 'src/mongo/shell/shardingtest.js')
-rw-r--r--src/mongo/shell/shardingtest.js529
1 files changed, 278 insertions, 251 deletions
diff --git a/src/mongo/shell/shardingtest.js b/src/mongo/shell/shardingtest.js
index 34f511b630e..4d38aa88544 100644
--- a/src/mongo/shell/shardingtest.js
+++ b/src/mongo/shell/shardingtest.js
@@ -1,20 +1,20 @@
/**
* Starts up a sharded cluster with the given specifications. The cluster
* will be fully operational after the execution of this constructor function.
- *
+ *
* @param {Object} params Contains the key-value pairs for the cluster
* configuration. Accepted keys are:
- *
+ *
* {
* name {string}: name for this test
* verbose {number}: the verbosity for the mongos
* keyFile {string}: the location of the keyFile
* chunksize {number}:
* nopreallocj {boolean|number}:
- *
+ *
* mongos {number|Object|Array.<Object>}: number of mongos or mongos
* configuration object(s)(*). @see MongoRunner.runMongos
- *
+ *
* rs {Object|Array.<Object>}: replica set configuration object. Can
* contain:
* {
@@ -25,32 +25,32 @@
* to ReplSetTest.prototype.initiate().
* For other options, @see ReplSetTest#start
* }
- *
+ *
* shards {number|Object|Array.<Object>}: number of shards or shard
* configuration object(s)(*). @see MongoRunner.runMongod
- *
+ *
* config {number|Object|Array.<Object>}: number of config server or
* config server configuration object(s)(*). If this field has 3 or
* more members, it implies other.sync = true. @see MongoRunner.runMongod
- *
+ *
* (*) There are two ways For multiple configuration objects.
* (1) Using the object format. Example:
- *
+ *
* { d0: { verbose: 5 }, d1: { auth: '' }, rs2: { oplogsize: 10 }}
- *
+ *
* In this format, d = mongod, s = mongos & c = config servers
- *
+ *
* (2) Using the array format. Example:
- *
+ *
* [{ verbose: 5 }, { auth: '' }]
- *
+ *
* Note: you can only have single server shards for array format.
*
* Note: A special "bridgeOptions" property can be specified in both the object and array
* formats to configure the options for the mongobridge corresponding to that node. These
* options are merged with the params.bridgeOptions options, where the node-specific
* options take precedence.
- *
+ *
* other: {
* nopreallocj: same as above
* rs: same as above
@@ -58,7 +58,7 @@
*
* shardOptions {Object}: same as the shards property above.
* Can be used to specify options that are common all shards.
- *
+ *
* sync {boolean}: Use SyncClusterConnection, and readies
* 1 or 3 config servers, based on the value of numConfigs.
* configOptions {Object}: same as the config property above.
@@ -120,15 +120,15 @@ var ShardingTest = function(params) {
try {
conn = new Mongo(url);
return true;
- } catch (e) {
- print("Error connecting to " + url + ": " + e);
- return false;
- }
+ } catch (e) {
+ print("Error connecting to " + url + ": " + e);
+ return false;
+ }
});
return conn;
}
-
+
/**
* Constructs a human-readable string representing a chunk's range.
*/
@@ -149,7 +149,7 @@ var ShardingTest = function(params) {
}
if (dbName) {
- var x = self.config.databases.findOne({ _id : dbname });
+ var x = self.config.databases.findOne({_id: dbname});
if (x)
return x.partitioned;
else
@@ -157,7 +157,7 @@ var ShardingTest = function(params) {
}
if (collName) {
- var x = self.config.collections.findOne({ _id : collName });
+ var x = self.config.collections.findOne({_id: collName});
if (x)
return true;
else
@@ -165,49 +165,56 @@ var ShardingTest = function(params) {
}
}
- function connectionURLTheSame( a , b ){
- if ( a == b )
+ function connectionURLTheSame(a, b) {
+ if (a == b)
return true;
- if ( ! a || ! b )
+ if (!a || !b)
return false;
- if( a.host ) return connectionURLTheSame( a.host, b );
- if( b.host ) return connectionURLTheSame( a, b.host );
+ if (a.host)
+ return connectionURLTheSame(a.host, b);
+ if (b.host)
+ return connectionURLTheSame(a, b.host);
- if( a.name ) return connectionURLTheSame( a.name, b );
- if( b.name ) return connectionURLTheSame( a, b.name );
+ if (a.name)
+ return connectionURLTheSame(a.name, b);
+ if (b.name)
+ return connectionURLTheSame(a, b.name);
- if( a.indexOf( "/" ) < 0 && b.indexOf( "/" ) < 0 ){
- a = a.split( ":" );
- b = b.split( ":" );
+ if (a.indexOf("/") < 0 && b.indexOf("/") < 0) {
+ a = a.split(":");
+ b = b.split(":");
- if( a.length != b.length ) return false;
+ if (a.length != b.length)
+ return false;
- if( a.length == 2 && a[1] != b[1] ) return false;
+ if (a.length == 2 && a[1] != b[1])
+ return false;
- if( a[0] == "localhost" || a[0] == "127.0.0.1" ) a[0] = getHostName();
- if( b[0] == "localhost" || b[0] == "127.0.0.1" ) b[0] = getHostName();
+ if (a[0] == "localhost" || a[0] == "127.0.0.1")
+ a[0] = getHostName();
+ if (b[0] == "localhost" || b[0] == "127.0.0.1")
+ b[0] = getHostName();
return a[0] == b[0];
- }
- else {
- var a0 = a.split( "/" )[0];
- var b0 = b.split( "/" )[0];
+ } else {
+ var a0 = a.split("/")[0];
+ var b0 = b.split("/")[0];
return a0 == b0;
}
}
- assert( connectionURLTheSame( "foo" , "foo" ) );
- assert( ! connectionURLTheSame( "foo" , "bar" ) );
+ assert(connectionURLTheSame("foo", "foo"));
+ assert(!connectionURLTheSame("foo", "bar"));
- assert( connectionURLTheSame( "foo/a,b" , "foo/b,a" ) );
- assert( ! connectionURLTheSame( "foo/a,b" , "bar/a,b" ) );
+ assert(connectionURLTheSame("foo/a,b", "foo/b,a"));
+ assert(!connectionURLTheSame("foo/a,b", "bar/a,b"));
// ShardingTest API
this.getRSEntry = function(setName) {
- for (var i=0; i<this._rs.length; i++)
+ for (var i = 0; i < this._rs.length; i++)
if (this._rs[i].setName == setName)
return this._rs[i];
throw Error("can't find rs: " + setName);
@@ -221,7 +228,7 @@ var ShardingTest = function(params) {
* Finds the _id of the primary shard for database 'dbname', e.g., 'test-rs0'
*/
this.getPrimaryShardIdForDatabase = function(dbname) {
- var x = this.config.databases.findOne({ _id : "" + dbname });
+ var x = this.config.databases.findOne({_id: "" + dbname});
if (x) {
return x.primary;
}
@@ -231,23 +238,24 @@ var ShardingTest = function(params) {
countDBsFound++;
printjson(db);
});
- throw Error("couldn't find dbname: " + dbname + " in config.databases. Total DBs: "
- + countDBsFound);
+ throw Error("couldn't find dbname: " + dbname + " in config.databases. Total DBs: " +
+ countDBsFound);
};
this.getNonPrimaries = function(dbname) {
- var x = this.config.databases.findOne({ _id : dbname });
- if (! x) {
+ var x = this.config.databases.findOne({_id: dbname});
+ if (!x) {
this.config.databases.find().forEach(printjson);
- throw Error("couldn't find dbname: " + dbname + " total: " + this.config.databases.count());
+ throw Error("couldn't find dbname: " + dbname + " total: " +
+ this.config.databases.count());
}
- return this.config.shards.find({ _id: { $ne: x.primary } }).map(z => z._id);
+ return this.config.shards.find({_id: {$ne: x.primary}}).map(z => z._id);
};
this.getConnNames = function() {
var names = [];
- for (var i=0; i<this._connections.length; i++) {
+ for (var i = 0; i < this._connections.length; i++) {
names.push(this._connections[i].name);
}
return names;
@@ -258,13 +266,13 @@ var ShardingTest = function(params) {
*/
this.getPrimaryShard = function(dbname) {
var dbPrimaryShardId = this.getPrimaryShardIdForDatabase(dbname);
- var primaryShard = this.config.shards.findOne({ _id : dbPrimaryShardId });
+ var primaryShard = this.config.shards.findOne({_id: dbPrimaryShardId});
if (primaryShard) {
shardConnectionString = primaryShard.host;
var rsName = shardConnectionString.substring(0, shardConnectionString.indexOf("/"));
- for (var i=0; i<this._connections.length; i++) {
+ for (var i = 0; i < this._connections.length; i++) {
var c = this._connections[i];
if (connectionURLTheSame(shardConnectionString, c.name) ||
connectionURLTheSame(rsName, c.name))
@@ -272,12 +280,12 @@ var ShardingTest = function(params) {
}
}
- throw Error("can't find server connection for db '" + dbname + "'s primary shard: "
- + tojson(primaryShard));
+ throw Error("can't find server connection for db '" + dbname + "'s primary shard: " +
+ tojson(primaryShard));
};
this.normalize = function(x) {
- var z = this.config.shards.findOne({ host : x });
+ var z = this.config.shards.findOne({host: x});
if (z)
return z._id;
return x;
@@ -295,7 +303,7 @@ var ShardingTest = function(params) {
one = one._mongo;
}
- for(var i = 0; i < this._connections.length; i++) {
+ for (var i = 0; i < this._connections.length; i++) {
if (this._connections[i] != one) {
return this._connections[i];
}
@@ -313,7 +321,7 @@ var ShardingTest = function(params) {
one = one._mongo;
}
- for(var i = 0; i < this._connections.length; i++) {
+ for (var i = 0; i < this._connections.length; i++) {
if (this._connections[i] == one)
return this._connections[(i + 1) % this._connections.length];
}
@@ -358,7 +366,7 @@ var ShardingTest = function(params) {
var timeMillis = new Date().getTime() - _startTime.getTime();
print('*** ShardingTest ' + this._testName + " completed successfully in " +
- (timeMillis / 1000) + " seconds ***");
+ (timeMillis / 1000) + " seconds ***");
};
this.adminCommand = function(cmd) {
@@ -377,12 +385,12 @@ var ShardingTest = function(params) {
msg += " " + z.ns + "\t";
if (z.what == "split") {
- msg += _rangeToString(z.details.before) + " -->> (" + _rangeToString(z.details.left) + "), (" + _rangeToString(z.details.right) + ")";
- }
- else if (z.what == "multi-split") {
- msg += _rangeToString(z.details.before) + " -->> (" + z.details.number + "/" + z.details.of + " " + _rangeToString(z.details.chunk) + ")";
- }
- else {
+ msg += _rangeToString(z.details.before) + " -->> (" +
+ _rangeToString(z.details.left) + "), (" + _rangeToString(z.details.right) + ")";
+ } else if (z.what == "multi-split") {
+ msg += _rangeToString(z.details.before) + " -->> (" + z.details.number + "/" +
+ z.details.of + " " + _rangeToString(z.details.chunk) + ")";
+ } else {
msg += tojsononeline(z.details);
}
@@ -397,10 +405,12 @@ var ShardingTest = function(params) {
}
var s = "";
- this.config.chunks.find(q).sort({ ns : 1, min : 1 }).forEach(function(z) {
- s += " " + z._id + "\t" + z.lastmod.t + "|" + z.lastmod.i + "\t" +
- tojson(z.min) + " -> " + tojson(z.max) + " " + z.shard + " " + z.ns + "\n";
- });
+ this.config.chunks.find(q)
+ .sort({ns: 1, min: 1})
+ .forEach(function(z) {
+ s += " " + z._id + "\t" + z.lastmod.t + "|" + z.lastmod.i + "\t" + tojson(z.min) +
+ " -> " + tojson(z.max) + " " + z.shard + " " + z.ns + "\n";
+ });
return s;
};
@@ -420,16 +430,16 @@ var ShardingTest = function(params) {
}
out += "sharding collection info: " + ns + "\n";
- for (var i = 0; i<this._connections.length; i++) {
+ for (var i = 0; i < this._connections.length; i++) {
var c = this._connections[i];
out += " mongod " + c + " " +
- tojson(c.getCollection(ns).getShardVersion(), " ", true) + "\n";
+ tojson(c.getCollection(ns).getShardVersion(), " ", true) + "\n";
}
for (var i = 0; i < this._mongos.length; i++) {
var c = this._mongos[i];
out += " mongos " + c + " " +
- tojson(c.getCollection(ns).getShardVersion(), " ", true) + "\n";
+ tojson(c.getCollection(ns).getShardVersion(), " ", true) + "\n";
}
out += this.getChunksString(ns);
@@ -479,12 +489,13 @@ var ShardingTest = function(params) {
x[z._id] = 0;
});
- this.config.chunks.find({ ns : dbName + "." + collName }).forEach(function(z) {
- if (x[z.shard])
- x[z.shard]++;
- else
- x[z.shard] = 1;
- });
+ this.config.chunks.find({ns: dbName + "." + collName})
+ .forEach(function(z) {
+ if (x[z.shard])
+ x[z.shard]++;
+ else
+ x[z.shard] = 1;
+ });
return x;
};
@@ -522,9 +533,11 @@ var ShardingTest = function(params) {
this.getShardNames = function() {
var shards = [];
- this.s.getCollection("config.shards").find().forEach(function(shardDoc) {
- shards.push(shardDoc._id);
- });
+ this.s.getCollection("config.shards")
+ .find()
+ .forEach(function(shardDoc) {
+ shards.push(shardDoc._id);
+ });
return shards;
};
@@ -549,18 +562,18 @@ var ShardingTest = function(params) {
var plannerShards = explain.queryPlanner.winningPlan.shards;
if (execStages.shards) {
- for(var i = 0; i < execStages.shards.length; i++) {
+ for (var i = 0; i < execStages.shards.length; i++) {
var hasResults = execStages.shards[i].executionStages.nReturned &&
- execStages.shards[i].executionStages.nReturned > 0;
+ execStages.shards[i].executionStages.nReturned > 0;
if (includeEmpty || hasResults) {
shards.push(plannerShards[i].connectionString);
}
}
}
- for(var i = 0; i < shards.length; i++) {
- for(var j = 0; j < this._connections.length; j++) {
- if (connectionURLTheSame( this._connections[j], shards[i])) {
+ for (var i = 0; i < shards.length; i++) {
+ for (var j = 0; j < this._connections.length; j++) {
+ if (connectionURLTheSame(this._connections[j], shards[i])) {
shards[i] = this._connections[j];
break;
}
@@ -576,7 +589,7 @@ var ShardingTest = function(params) {
if (collName.getDB)
dbName = "" + collName.getDB();
- else
+ else
dbName = dbName || "test";
var c = dbName + "." + collName;
@@ -587,10 +600,10 @@ var ShardingTest = function(params) {
var isEmpty = (this.s.getCollection(c).count() == 0);
if (!_isSharded(dbName)) {
- this.s.adminCommand({ enableSharding : dbName });
+ this.s.adminCommand({enableSharding: dbName});
}
- var result = this.s.adminCommand({ shardcollection : c, key : key });
+ var result = this.s.adminCommand({shardcollection: c, key: key});
if (!result.ok) {
printjson(result);
assert(false);
@@ -600,8 +613,8 @@ var ShardingTest = function(params) {
return;
}
- result = this.s.adminCommand({ split : c, middle : split });
- if (! result.ok) {
+ result = this.s.adminCommand({split: c, middle: split});
+ if (!result.ok) {
printjson(result);
assert(false);
}
@@ -611,13 +624,12 @@ var ShardingTest = function(params) {
}
var result;
- for(var i = 0; i < 5; i++) {
+ for (var i = 0; i < 5; i++) {
var otherShard = this.getOther(this.getPrimaryShard(dbName)).name;
- result = this.s.adminCommand({ movechunk: c,
- find: move,
- to: otherShard,
- _waitForDelete: waitForDelete });
- if (result.ok) break;
+ result = this.s.adminCommand(
+ {movechunk: c, find: move, to: otherShard, _waitForDelete: waitForDelete});
+ if (result.ok)
+ break;
sleep(5 * 1000);
}
@@ -638,8 +650,7 @@ var ShardingTest = function(params) {
try {
assert.writeOK(sh.setBalancerState(false));
sh.waitForBalancer(false, timeout, interval);
- }
- finally {
+ } finally {
db = oldDB;
}
};
@@ -656,8 +667,7 @@ var ShardingTest = function(params) {
try {
assert.writeOK(sh.setBalancerState(true));
sh.waitForBalancer(true, timeout, interval);
- }
- finally {
+ } finally {
db = oldDB;
}
};
@@ -666,8 +676,8 @@ var ShardingTest = function(params) {
* Returns true after the balancer has completed a balancing round.
*
* Checks that three pings were sent to config.mongos. The balancer writes a ping
- * at the start and end of a balancing round. If the balancer is in the middle of
- * a round, there could be three pings before the first full balancing round
+ * at the start and end of a balancing round. If the balancer is in the middle of
+ * a round, there could be three pings before the first full balancing round
* completes: end ping of a round, and start and end pings of the following round.
*/
this.waitForBalancerRound = function() {
@@ -677,7 +687,7 @@ var ShardingTest = function(params) {
var oldDB = db;
db = this.config;
- var getPings = function(){
+ var getPings = function() {
return sh._getConfigDB().mongos.find().toArray();
};
@@ -685,15 +695,14 @@ var ShardingTest = function(params) {
// If sh.waitForPingChange returns a non-empty array, config.mongos
// was not successfully updated and no balancer round was reported.
for (var i = 0; i < 3; ++i) {
- if ( sh.waitForPingChange(getPings()).length != 0 ) {
+ if (sh.waitForPingChange(getPings()).length != 0) {
return false;
}
}
db = oldDB;
return true;
- }
- catch (e) {
+ } catch (e) {
print("Error running waitForPingChange: " + tojson(e));
db = oldDB;
return false;
@@ -701,13 +710,12 @@ var ShardingTest = function(params) {
};
this.isAnyBalanceInFlight = function() {
- if (this.config.locks.find({ _id : { $ne : "balancer" }, state : 2 }).count() > 0)
+ if (this.config.locks.find({_id: {$ne: "balancer"}, state: 2}).count() > 0)
return true;
var allCurrent = this.s.getDB("admin").currentOp().inprog;
for (var i = 0; i < allCurrent.length; i++) {
- if (allCurrent[i].desc &&
- allCurrent[i].desc.indexOf("cleanupOldData") == 0)
+ if (allCurrent[i].desc && allCurrent[i].desc.indexOf("cleanupOldData") == 0)
return true;
}
return false;
@@ -772,16 +780,18 @@ var ShardingTest = function(params) {
this.stopMongos(n);
if (otherParams.useBridge) {
- var bridgeOptions = (opts !== mongos) ? opts.bridgeOptions
- : mongos.fullOptions.bridgeOptions;
+ var bridgeOptions =
+ (opts !== mongos) ? opts.bridgeOptions : mongos.fullOptions.bridgeOptions;
bridgeOptions = Object.merge(otherParams.bridgeOptions, bridgeOptions || {});
- bridgeOptions = Object.merge(bridgeOptions, {
- hostName: otherParams.useHostname ? hostName : "localhost",
- port: this._mongos[n].port,
- // The mongos processes identify themselves to mongobridge as host:port, where the
- // host is the actual hostname of the machine and not localhost.
- dest: hostName + ":" + opts.port,
- });
+ bridgeOptions = Object.merge(
+ bridgeOptions,
+ {
+ hostName: otherParams.useHostname ? hostName : "localhost",
+ port: this._mongos[n].port,
+ // The mongos processes identify themselves to mongobridge as host:port, where the
+ // host is the actual hostname of the machine and not localhost.
+ dest: hostName + ":" + opts.port,
+ });
this._mongos[n] = new MongoBridge(bridgeOptions);
}
@@ -826,15 +836,17 @@ var ShardingTest = function(params) {
this.stopMongod(n);
if (otherParams.useBridge) {
- var bridgeOptions = Object.merge(otherParams.bridgeOptions,
- mongod.fullOptions.bridgeOptions || {});
- bridgeOptions = Object.merge(bridgeOptions, {
- hostName: otherParams.useHostname ? hostName : "localhost",
- port: this._connections[n].port,
- // The mongod processes identify themselves to mongobridge as host:port, where the
- // host is the actual hostname of the machine and not localhost.
- dest: hostName + ":" + mongod.port,
- });
+ var bridgeOptions =
+ Object.merge(otherParams.bridgeOptions, mongod.fullOptions.bridgeOptions || {});
+ bridgeOptions = Object.merge(
+ bridgeOptions,
+ {
+ hostName: otherParams.useHostname ? hostName : "localhost",
+ port: this._connections[n].port,
+ // The mongod processes identify themselves to mongobridge as host:port, where the
+ // host is the actual hostname of the machine and not localhost.
+ dest: hostName + ":" + mongod.port,
+ });
this._connections[n] = new MongoBridge(bridgeOptions);
}
@@ -876,15 +888,17 @@ var ShardingTest = function(params) {
this.stopConfigServer(n);
if (otherParams.useBridge) {
- var bridgeOptions = Object.merge(otherParams.bridgeOptions,
- mongod.fullOptions.bridgeOptions || {});
- bridgeOptions = Object.merge(bridgeOptions, {
- hostName: otherParams.useHostname ? hostName : "localhost",
- port: this._configServers[n].port,
- // The mongod processes identify themselves to mongobridge as host:port, where the
- // host is the actual hostname of the machine and not localhost.
- dest: hostName + ":" + mongod.port,
- });
+ var bridgeOptions =
+ Object.merge(otherParams.bridgeOptions, mongod.fullOptions.bridgeOptions || {});
+ bridgeOptions = Object.merge(
+ bridgeOptions,
+ {
+ hostName: otherParams.useHostname ? hostName : "localhost",
+ port: this._configServers[n].port,
+ // The mongod processes identify themselves to mongobridge as host:port, where the
+ // host is the actual hostname of the machine and not localhost.
+ dest: hostName + ":" + mongod.port,
+ });
this._configServers[n] = new MongoBridge(bridgeOptions);
}
@@ -912,7 +926,7 @@ var ShardingTest = function(params) {
*/
this.ensurePrimaryShard = function(dbName, shardName) {
var db = this.s0.getDB('admin');
- var res = db.adminCommand({ movePrimary: dbName, to: shardName });
+ var res = db.adminCommand({movePrimary: dbName, to: shardName});
assert(res.ok || res.errmsg == "it is already the primary", tojson(res));
};
@@ -933,15 +947,14 @@ var ShardingTest = function(params) {
// config : [ { smallfiles : "" } ],
// shards : { rs : true, d : true } }
if (Array.isArray(numShards)) {
- for(var i = 0; i < numShards.length; i++) {
+ for (var i = 0; i < numShards.length; i++) {
otherParams["d" + i] = numShards[i];
}
numShards = numShards.length;
- }
- else if (isObject(numShards)) {
+ } else if (isObject(numShards)) {
var tempCount = 0;
- for(var i in numShards) {
+ for (var i in numShards) {
otherParams[i] = numShards[i];
tempCount++;
}
@@ -950,15 +963,14 @@ var ShardingTest = function(params) {
}
if (Array.isArray(numMongos)) {
- for(var i = 0; i < numMongos.length; i++) {
+ for (var i = 0; i < numMongos.length; i++) {
otherParams["s" + i] = numMongos[i];
}
numMongos = numMongos.length;
- }
- else if (isObject(numMongos)) {
+ } else if (isObject(numMongos)) {
var tempCount = 0;
- for(var i in numMongos) {
+ for (var i in numMongos) {
otherParams[i] = numMongos[i];
tempCount++;
}
@@ -967,15 +979,14 @@ var ShardingTest = function(params) {
}
if (Array.isArray(numConfigs)) {
- for(var i = 0; i < numConfigs.length; i++) {
+ for (var i = 0; i < numConfigs.length; i++) {
otherParams["c" + i] = numConfigs[i];
}
numConfigs = numConfigs.length;
- }
- else if (isObject(numConfigs)) {
+ } else if (isObject(numConfigs)) {
var tempCount = 0;
- for(var i in numConfigs) {
+ for (var i in numConfigs) {
otherParams[i] = numConfigs[i];
tempCount++;
}
@@ -984,8 +995,7 @@ var ShardingTest = function(params) {
}
otherParams.extraOptions = otherParams.extraOptions || {};
- otherParams.useHostname = otherParams.useHostname == undefined ?
- true : otherParams.useHostname;
+ otherParams.useHostname = otherParams.useHostname == undefined ? true : otherParams.useHostname;
otherParams.useBridge = otherParams.useBridge || false;
otherParams.bridgeOptions = otherParams.bridgeOptions || {};
@@ -995,9 +1005,11 @@ var ShardingTest = function(params) {
this._testName = testName;
this._otherParams = otherParams;
- var pathOpts = { testName: testName };
+ var pathOpts = {
+ testName: testName
+ };
- for(var k in otherParams) {
+ for (var k in otherParams) {
if (k.startsWith("rs") && otherParams[k] != undefined) {
break;
}
@@ -1018,10 +1030,12 @@ var ShardingTest = function(params) {
if (otherParams.rs || otherParams["rs" + i]) {
var setName = testName + "-rs" + i;
- var rsDefaults = { useHostname : otherParams.useHostname,
- noJournalPrealloc : otherParams.nopreallocj,
- oplogSize : 16,
- pathOpts : Object.merge(pathOpts, { shard : i })};
+ var rsDefaults = {
+ useHostname: otherParams.useHostname,
+ noJournalPrealloc: otherParams.nopreallocj,
+ oplogSize: 16,
+ pathOpts: Object.merge(pathOpts, {shard: i})
+ };
rsDefaults = Object.merge(rsDefaults, otherParams.rs);
rsDefaults = Object.merge(rsDefaults, otherParams.rsOptions);
@@ -1036,19 +1050,23 @@ var ShardingTest = function(params) {
var initiateTimeout = rsDefaults.initiateTimeout;
delete rsDefaults.initiateTimeout;
- var rs = new ReplSetTest({ name : setName,
- nodes : numReplicas,
- useHostName : otherParams.useHostname,
- useBridge: otherParams.useBridge,
- bridgeOptions: otherParams.bridgeOptions,
- keyFile : keyFile,
- protocolVersion: protocolVersion,
- shardSvr : true });
+ var rs = new ReplSetTest({
+ name: setName,
+ nodes: numReplicas,
+ useHostName: otherParams.useHostname,
+ useBridge: otherParams.useBridge,
+ bridgeOptions: otherParams.bridgeOptions,
+ keyFile: keyFile,
+ protocolVersion: protocolVersion,
+ shardSvr: true
+ });
- this._rs[i] = { setName : setName,
- test : rs,
- nodes : rs.startSet(rsDefaults),
- url : rs.getURL() };
+ this._rs[i] = {
+ setName: setName,
+ test: rs,
+ nodes: rs.startSet(rsDefaults),
+ url: rs.getURL()
+ };
rs.initiate(null, null, initiateTimeout);
@@ -1061,8 +1079,7 @@ var ShardingTest = function(params) {
if (otherParams.useBridge) {
unbridgedConnections.push(null);
}
- }
- else {
+ } else {
var options = {
useHostname: otherParams.useHostname,
noJournalPrealloc: otherParams.nopreallocj,
@@ -1082,14 +1099,16 @@ var ShardingTest = function(params) {
options.port = options.port || allocatePort();
if (otherParams.useBridge) {
- var bridgeOptions = Object.merge(otherParams.bridgeOptions,
- options.bridgeOptions || {});
- bridgeOptions = Object.merge(bridgeOptions, {
- hostName: otherParams.useHostname ? hostName : "localhost",
- // The mongod processes identify themselves to mongobridge as host:port, where
- // the host is the actual hostname of the machine and not localhost.
- dest: hostName + ":" + options.port,
- });
+ var bridgeOptions =
+ Object.merge(otherParams.bridgeOptions, options.bridgeOptions || {});
+ bridgeOptions = Object.merge(
+ bridgeOptions,
+ {
+ hostName: otherParams.useHostname ? hostName : "localhost",
+ // The mongod processes identify themselves to mongobridge as host:port, where
+ // the host is the actual hostname of the machine and not localhost.
+ dest: hostName + ":" + options.port,
+ });
var bridge = new MongoBridge(bridgeOptions);
}
@@ -1123,10 +1142,14 @@ var ShardingTest = function(params) {
}
var rs = this._rs[i].test;
- rs.getPrimary().getDB("admin").foo.save({ x : 1 });
+ rs.getPrimary().getDB("admin").foo.save({x: 1});
if (keyFile) {
- authutil.asCluster(rs.nodes, keyFile, function() { rs.awaitReplication(); });
+ authutil.asCluster(rs.nodes,
+ keyFile,
+ function() {
+ rs.awaitReplication();
+ });
}
rs.awaitSecondaryNodes();
@@ -1141,9 +1164,8 @@ var ShardingTest = function(params) {
// Default to using 3-node legacy config servers if jsTestOptions().useLegacyOptions is true
// and the user didn't explicity specify a different config server configuration
- if (jsTestOptions().useLegacyConfigServers &&
- otherParams.sync !== false &&
- (typeof(otherParams.config) === 'undefined' || numConfigs === 3)) {
+ if (jsTestOptions().useLegacyConfigServers && otherParams.sync !== false &&
+ (typeof(otherParams.config) === 'undefined' || numConfigs === 3)) {
otherParams.sync = true;
}
@@ -1157,14 +1179,16 @@ var ShardingTest = function(params) {
var configNames = [];
for (var i = 0; i < numConfigs; i++) {
- var options = { useHostname : otherParams.useHostname,
- noJournalPrealloc : otherParams.nopreallocj,
- pathOpts : Object.merge(pathOpts, { config : i }),
- dbpath : "$testName-config$config",
- keyFile : keyFile,
- // Ensure that journaling is always enabled for config servers.
- journal : "",
- configsvr : "" };
+ var options = {
+ useHostname: otherParams.useHostname,
+ noJournalPrealloc: otherParams.nopreallocj,
+ pathOpts: Object.merge(pathOpts, {config: i}),
+ dbpath: "$testName-config$config",
+ keyFile: keyFile,
+ // Ensure that journaling is always enabled for config servers.
+ journal: "",
+ configsvr: ""
+ };
if (otherParams.configOptions && otherParams.configOptions.binVersion) {
otherParams.configOptions.binVersion =
@@ -1177,14 +1201,16 @@ var ShardingTest = function(params) {
options.port = options.port || allocatePort();
if (otherParams.useBridge) {
- var bridgeOptions = Object.merge(otherParams.bridgeOptions,
- options.bridgeOptions || {});
- bridgeOptions = Object.merge(bridgeOptions, {
- hostName: otherParams.useHostname ? hostName : "localhost",
- // The mongod processes identify themselves to mongobridge as host:port, where
- // the host is the actual hostname of the machine and not localhost.
- dest: hostName + ":" + options.port,
- });
+ var bridgeOptions =
+ Object.merge(otherParams.bridgeOptions, options.bridgeOptions || {});
+ bridgeOptions = Object.merge(
+ bridgeOptions,
+ {
+ hostName: otherParams.useHostname ? hostName : "localhost",
+ // The mongod processes identify themselves to mongobridge as host:port, where
+ // the host is the actual hostname of the machine and not localhost.
+ dest: hostName + ":" + options.port,
+ });
var bridge = new MongoBridge(bridgeOptions);
}
@@ -1210,24 +1236,25 @@ var ShardingTest = function(params) {
}
this._configDB = configNames.join(',');
- }
- else {
+ } else {
// Using replica set for config servers
- var rstOptions = { useHostName : otherParams.useHostname,
- useBridge : otherParams.useBridge,
- bridgeOptions : otherParams.bridgeOptions,
- keyFile : keyFile,
- name: testName + "-configRS",
- };
+ var rstOptions = {
+ useHostName: otherParams.useHostname,
+ useBridge: otherParams.useBridge,
+ bridgeOptions: otherParams.bridgeOptions,
+ keyFile: keyFile,
+ name: testName + "-configRS",
+ };
// when using CSRS, always use wiredTiger as the storage engine
- var startOptions = { pathOpts: pathOpts,
- // Ensure that journaling is always enabled for config servers.
- journal : "",
- configsvr : "",
- noJournalPrealloc : otherParams.nopreallocj,
- storageEngine : "wiredTiger",
- };
+ var startOptions = {
+ pathOpts: pathOpts,
+ // Ensure that journaling is always enabled for config servers.
+ journal: "",
+ configsvr: "",
+ noJournalPrealloc: otherParams.nopreallocj,
+ storageEngine: "wiredTiger",
+ };
if (otherParams.configOptions && otherParams.configOptions.binVersion) {
otherParams.configOptions.binVersion =
@@ -1253,7 +1280,7 @@ var ShardingTest = function(params) {
var initiateTimeout = otherParams.rsOptions && otherParams.rsOptions.initiateTimeout;
this.configRS.initiate(config, null, initiateTimeout);
- this.configRS.getPrimary(); // Wait for master to be elected before starting mongos
+ this.configRS.getPrimary(); // Wait for master to be elected before starting mongos
this._configDB = this.configRS.getURL();
this._configServers = this.configRS.nodes;
@@ -1269,16 +1296,14 @@ var ShardingTest = function(params) {
var configConnection = _connectWithRetry(this._configDB);
print("ShardingTest " + this._testName + " :\n" +
- tojson({ config : this._configDB, shards : this._connections }));
+ tojson({config: this._configDB, shards: this._connections}));
if (numMongos == 0 && !otherParams.noChunkSize) {
if (keyFile) {
throw Error("Cannot set chunk size without any mongos when using auth");
} else {
- configConnection.getDB("config").settings.insert({
- _id : "chunksize",
- value : otherParams.chunksize || otherParams.chunkSize || 50
- });
+ configConnection.getDB("config").settings.insert(
+ {_id: "chunksize", value: otherParams.chunksize || otherParams.chunkSize || 50});
}
}
@@ -1310,14 +1335,16 @@ var ShardingTest = function(params) {
options.port = options.port || allocatePort();
if (otherParams.useBridge) {
- var bridgeOptions = Object.merge(otherParams.bridgeOptions,
- options.bridgeOptions || {});
- bridgeOptions = Object.merge(bridgeOptions, {
- hostName: otherParams.useHostname ? hostName : "localhost",
- // The mongos processes identify themselves to mongobridge as host:port, where the
- // host is the actual hostname of the machine and not localhost.
- dest: hostName + ":" + options.port,
- });
+ var bridgeOptions =
+ Object.merge(otherParams.bridgeOptions, options.bridgeOptions || {});
+ bridgeOptions = Object.merge(
+ bridgeOptions,
+ {
+ hostName: otherParams.useHostname ? hostName : "localhost",
+ // The mongos processes identify themselves to mongobridge as host:port, where the
+ // host is the actual hostname of the machine and not localhost.
+ dest: hostName + ":" + options.port,
+ });
var bridge = new MongoBridge(bridgeOptions);
}
@@ -1347,11 +1374,13 @@ var ShardingTest = function(params) {
// If auth is enabled for the test, login the mongos connections as system in order to
// configure the instances and then log them out again.
if (keyFile) {
- authutil.assertAuthenticate(this._mongos, 'admin', {
- user: '__system',
- mechanism: 'MONGODB-CR',
- pwd: cat(keyFile).replace(/[\011-\015\040]/g, '')
- });
+ authutil.assertAuthenticate(this._mongos,
+ 'admin',
+ {
+ user: '__system',
+ mechanism: 'MONGODB-CR',
+ pwd: cat(keyFile).replace(/[\011-\015\040]/g, '')
+ });
}
try {
@@ -1365,7 +1394,7 @@ var ShardingTest = function(params) {
// errors. This attempt is best-effort and failure should not have effect on the actual
// test execution, just the execution time.
this._mongos.forEach(function(mongos) {
- var res = mongos.adminCommand({ setParameter: 1, replMonitorMaxFailedChecks: 2 });
+ var res = mongos.adminCommand({setParameter: 1, replMonitorMaxFailedChecks: 2});
// For tests, which use x509 certificate for authentication, the command above will not
// work due to authorization error.
@@ -1386,25 +1415,23 @@ var ShardingTest = function(params) {
var admin = this.admin;
var shardNames = this._shardNames;
- this._connections.forEach(
- function(z) {
- var n = z.name;
+ this._connections.forEach(function(z) {
+ var n = z.name;
+ if (!n) {
+ n = z.host;
if (!n) {
- n = z.host;
- if (!n) {
- n = z;
- }
+ n = z;
}
+ }
- print("ShardingTest " + testName + " going to add shard : " + n);
+ print("ShardingTest " + testName + " going to add shard : " + n);
- var result = admin.runCommand({ addshard: n });
- assert.commandWorked(result, "Failed to add shard " + n);
+ var result = admin.runCommand({addshard: n});
+ assert.commandWorked(result, "Failed to add shard " + n);
- shardNames.push(result.shardAdded);
- z.shardName = result.shardAdded;
- }
- );
+ shardNames.push(result.shardAdded);
+ z.shardName = result.shardAdded;
+ });
}
if (jsTestOptions().keyFile) {