summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSpencer T Brody <spencer@mongodb.com>2015-04-13 18:20:57 -0400
committerSpencer T Brody <spencer@mongodb.com>2015-04-23 14:30:19 -0400
commit8b7528029686ca1ae0eec681169406d52eb27682 (patch)
treece2e438bd27f875fe26e2c7f58bc9718440e9712 /src
parent4ff9beb8293ab4b0de8ddbb3542331b7e30051b3 (diff)
downloadmongo-8b7528029686ca1ae0eec681169406d52eb27682.tar.gz
SERVER-17971 Make ShardingTest start single-server config servers as replica sets
Diffstat (limited to 'src')
-rwxr-xr-xsrc/mongo/shell/servers.js16
-rw-r--r--src/mongo/shell/shardingtest.js191
2 files changed, 135 insertions, 72 deletions
diff --git a/src/mongo/shell/servers.js b/src/mongo/shell/servers.js
index 3267cb8c6af..c4ec1491a1f 100755
--- a/src/mongo/shell/servers.js
+++ b/src/mongo/shell/servers.js
@@ -493,7 +493,7 @@ MongoRunner.mongosOptions = function( opts ){
}
opts.pathOpts = Object.merge( opts.pathOpts,
- { configdb : opts.configdb.replace( /:|,/g, "-" ) } )
+ { configdb : opts.configdb.replace( /:|\/|,/g, "-" ) } )
if( ! opts.logFile && opts.useLogFiles ){
opts.logFile = MongoRunner.toRealFile( "$dataDir/mongos-$configdb-$port.log",
@@ -538,7 +538,7 @@ MongoRunner.mongosOptions = function( opts ){
MongoRunner.runMongod = function( opts ){
opts = opts || {}
- var useHostName = false;
+ var useHostName = true;
var runId = null;
var waitForConnect = true;
var fullOptions = opts;
@@ -547,8 +547,16 @@ MongoRunner.runMongod = function( opts ){
opts = MongoRunner.mongodOptions( opts );
fullOptions = opts;
-
- useHostName = opts.useHostName || opts.useHostname;
+
+ if (opts.useHostName != undefined) {
+ useHostName = opts.useHostName;
+ }
+ else if (opts.useHostname != undefined) {
+ useHostName = opts.useHostname;
+ }
+ else {
+ useHostName = true; // Default to true
+ }
runId = opts.runId;
waitForConnect = opts.waitForConnect;
diff --git a/src/mongo/shell/shardingtest.js b/src/mongo/shell/shardingtest.js
index 8b79da88093..2a3119e0bbb 100644
--- a/src/mongo/shell/shardingtest.js
+++ b/src/mongo/shell/shardingtest.js
@@ -76,6 +76,7 @@
* d0, d1, ... {Mongo} - same as shard0, shard1, ...
* config0, config1, ... {Mongo} - connection to config servers
* c0, c1, ... {Mongo} - same as config0, config1, ...
+ * configRS - If the config servers are a replset, this will contain the config ReplSetTest object
*/
ShardingTest = function( testName , numShards , verboseLevel , numMongos , otherParams ){
@@ -83,26 +84,21 @@ ShardingTest = function( testName , numShards , verboseLevel , numMongos , other
// Check if testName is an object, if so, pull params from there
var keyFile = undefined
+ var numConfigs = 1;
otherParams = Object.merge( otherParams || {}, {} )
- otherParams.extraOptions = otherParams.extraOptions || {}
-
+
if( isObject( testName ) ){
var params = Object.merge( testName, {} )
testName = params.name || "test"
-
- otherParams = Object.merge( params.other || {}, {} )
- otherParams.extraOptions = otherParams.extraOptions || {}
-
- numShards = params.shards || 2
- verboseLevel = params.verbose || 0
- numMongos = params.mongos || 1
-
- keyFile = params.keyFile || otherParams.keyFile || otherParams.extraOptions.keyFile
- otherParams.nopreallocj = params.nopreallocj || otherParams.nopreallocj
- otherParams.rs = params.rs || ( params.other ? params.other.rs : undefined )
- otherParams.chunksize = params.chunksize || ( params.other ? params.other.chunksize : undefined )
+ otherParams = Object.merge(otherParams, params);
+ otherParams = Object.merge(params.other || {}, otherParams);
+
+ numShards = otherParams.shards || 2
+ verboseLevel = otherParams.verbose || 0
+ numMongos = otherParams.mongos || 1
+ numConfigs = otherParams.config || 1;
var tempCount = 0;
@@ -142,32 +138,28 @@ ShardingTest = function( testName , numShards , verboseLevel , numMongos , other
numMongos = tempCount;
}
- if( Array.isArray( params.config ) ){
- for( var i = 0; i < params.config.length; i++ ){
- otherParams[ "c" + i ] = params.config[i];
+ if( Array.isArray( numConfigs ) ){
+ for( var i = 0; i < numConfigs.length; i++ ){
+ otherParams[ "c" + i ] = numConfigs[i];
}
- if( params.config.length == 3 ) otherParams.sync = true;
- else otherParams.sync = false;
+ numConfigs = numConfigs.length
}
- else if( isObject( params.config ) ){
+ else if( isObject( numConfigs ) ){
tempCount = 0;
- for( var i in params.config ) {
- otherParams[ i ] = params.config[i];
+ for( var i in numConfigs ) {
+ otherParams[ i ] = numConfigs[i];
tempCount++;
}
-
- if( params.config.length == 3 ) otherParams.sync = true;
- else otherParams.sync = false;
- }
- else if( params.config && params.config == 3 ) {
- otherParams.sync = true;
+ numConfigs = tempCount;
}
}
- else {
- // Handle legacy stuff
- keyFile = otherParams.extraOptions.keyFile
- }
+
+ otherParams.extraOptions = otherParams.extraOptions || {};
+ otherParams.useHostname = otherParams.useHostname == undefined ?
+ true : otherParams.useHostname;
+ keyFile = otherParams.keyFile || otherParams.extraOptions.keyFile
+
this._testName = testName
this._otherParams = otherParams
@@ -181,12 +173,6 @@ ShardingTest = function( testName , numShards , verboseLevel , numMongos , other
break
}
}
-
- if( hasRS ){
- otherParams.useHostname = otherParams.useHostname == undefined ? true : otherParams.useHostname
- }
-
- var localhost = otherParams.useHostname ? getHostName() : "localhost";
this._alldbpaths = []
this._connections = []
@@ -274,43 +260,106 @@ ShardingTest = function( testName , numShards , verboseLevel , numMongos , other
rsConn.rs = rs
}
+ if (numConfigs == 3) {
+ // TODO(spencer): Remove this once we support 3 node config server replica sets
+ otherParams.sync = true;
+ }
+
this._configServers = []
- this._configNames = []
+ this._configServersAreRS = !otherParams.sync;
- for ( var i = 0; i < ( otherParams.sync ? 3 : 1 ) ; i++ ) {
+ if (otherParams.sync) {
+ var configNames = [];
+ for ( var i = 0; i < 3 ; i++ ) {
+
+ var options = { useHostname : otherParams.useHostname,
+ noJournalPrealloc : otherParams.nopreallocj,
+ port : 29000 + i,
+ pathOpts : Object.merge( pathOpts, { config : i } ),
+ dbpath : "$testName-config$config",
+ keyFile : keyFile,
+ configsvr : ""
+ }
+
+ options = Object.merge( options, ShardingTest.configOptions || {} )
+
+ if( otherParams.configOptions && otherParams.configOptions.binVersion ){
+ otherParams.configOptions.binVersion =
+ MongoRunner.versionIterator( otherParams.configOptions.binVersion )
+ }
+
+ options = Object.merge( options, otherParams.configOptions )
+ options = Object.merge( options, otherParams["c" + i] )
+
+ var conn = MongoRunner.runMongod( options )
+
+ this._alldbpaths.push( testName + "-config" + i )
+
+ this._configServers.push( conn );
+ configNames.push( conn.name )
+ this["config" + i] = conn
+ this["c" + i] = conn
+ }
+ this._configDB = configNames.join( "," );
+ }
+ else {
+ // Using replica set for config servers
+ assert.eq(1, numConfigs);
+
+ var rstOptions = { useHostName : otherParams.useHostname,
+ startPort : 29000,
+ keyFile : keyFile,
+ name: testName + "-configRS"
+ };
+ var startOptions = { pathOpts: pathOpts,
+ configsvr : "",
+ noJournalPrealloc : otherParams.nopreallocj,
+ };
+
+ startOptions = Object.merge( startOptions, ShardingTest.configOptions || {} )
- var options = { useHostname : otherParams.useHostname,
- noJournalPrealloc : otherParams.nopreallocj,
- port : 29000 + i,
- pathOpts : Object.merge( pathOpts, { config : i } ),
- dbpath : "$testName-config$config",
- keyFile : keyFile,
- configsvr : ""
- }
-
- options = Object.merge( options, ShardingTest.configOptions || {} )
-
if( otherParams.configOptions && otherParams.configOptions.binVersion ){
- otherParams.configOptions.binVersion =
+ otherParams.configOptions.binVersion =
MongoRunner.versionIterator( otherParams.configOptions.binVersion )
}
-
- options = Object.merge( options, otherParams.configOptions )
- options = Object.merge( options, otherParams["c" + i] )
-
- var conn = MongoRunner.runMongod( options )
-
- // TODO: Needed?
- this._alldbpaths.push( testName + "-config" + i )
- this._configServers.push( conn );
- this._configNames.push( conn.name )
- this["config" + i] = conn
- this["c" + i] = conn
+ startOptions = Object.merge( startOptions, otherParams.configOptions )
+ var nodeOptions = [];
+ for (var i = 0; i < numConfigs; ++i) {
+ nodeOptions.push(otherParams["c" + i] || {});
+ }
+ rstOptions["nodes"] = nodeOptions;
+
+ this.configRS = new ReplSetTest(rstOptions);
+ this.configRS.startSet(startOptions);
+ this.configRS.initiate();
+ this.configRS.getMaster(); // Wait for master to be elected before starting mongos
+
+ this._configDB = this.configRS.getURL();
+ this._configServers = this.configRS.nodes;
+ for (var i = 0; i < numConfigs; ++i) {
+ var conn = this._configServers[i];
+ this["config" + i] = conn;
+ this["c" + i] = conn;
+ }
}
- printjson( this._configDB = this._configNames.join( "," ) )
- this._configConnection = new Mongo( this._configDB )
+ printjson("config servers: " + this._configDB);
+ var connectWithRetry = function(url) {
+ var conn = null;
+ assert.soon( function() {
+ try {
+ conn = new Mongo(url);
+ return true;
+ } catch (e) {
+ print("Error connecting to " + url + ": " + e);
+ return false;
+ }
+ });
+ return conn;
+ }
+ this._configConnection = connectWithRetry(this._configDB);
+
print( "ShardingTest " + this._testName + " :\n" + tojson( { config : this._configDB, shards : this._connections } ) );
if ( numMongos == 0 && !otherParams.noChunkSize ) {
@@ -534,8 +583,14 @@ ShardingTest.prototype.stop = function(){
if( this._rs[i] ) this._rs[i].test.stopSet( 15 );
}
}
- for ( var i=0; i<this._configServers.length; i++ ){
- MongoRunner.stopMongod( this._configServers[i] )
+ if (this._configServersAreRS) {
+ this.configRS.stopSet();
+ }
+ else {
+ // Old style config triplet
+ for ( var i=0; i<this._configServers.length; i++ ){
+ MongoRunner.stopMongod( this._configServers[i] )
+ }
}
if ( this._alldbpaths ){
for( i=0; i<this._alldbpaths.length; i++ ){