2015-08-18 21:44:13 +02:00
|
|
|
//
|
|
|
|
// Tests initialization of an empty cluster with multiple mongoses.
|
2016-03-09 18:17:50 +01:00
|
|
|
// Starts a bunch of mongoses in parallel, and ensures that there's only a single config
|
2015-08-18 21:44:13 +02:00
|
|
|
// version initialization.
|
|
|
|
//
|
|
|
|
|
2016-03-09 18:17:50 +01:00
|
|
|
var configRS = new ReplSetTest({name: "configRS", nodes: 3, useHostName: true});
|
|
|
|
configRS.startSet({configsvr: '', journal: "", storageEngine: 'wiredTiger'});
|
2015-08-18 21:44:13 +02:00
|
|
|
var replConfig = configRS.getReplSetConfig();
|
|
|
|
replConfig.configsvr = true;
|
|
|
|
configRS.initiate(replConfig);
|
|
|
|
|
|
|
|
//
|
|
|
|
// Start a bunch of mongoses which will probably interfere
|
|
|
|
//
|
|
|
|
|
|
|
|
jsTest.log("Starting first set of mongoses in parallel...");
|
|
|
|
|
|
|
|
var mongoses = [];
|
|
|
|
for (var i = 0; i < 3; i++) {
|
2016-03-09 18:17:50 +01:00
|
|
|
var mongos = MongoRunner.runMongos(
|
|
|
|
{binVersion: "latest", configdb: configRS.getURL(), waitForConnect: false});
|
2015-08-18 21:44:13 +02:00
|
|
|
mongoses.push(mongos);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Eventually connect to a mongo host, to be sure that the config upgrade happened
|
|
|
|
// (This can take longer on extremely slow bbots or VMs)
|
|
|
|
var mongosConn = null;
|
|
|
|
assert.soon(function() {
|
|
|
|
try {
|
|
|
|
mongosConn = new Mongo(mongoses[0].host);
|
|
|
|
return true;
|
2016-03-09 18:17:50 +01:00
|
|
|
} catch (e) {
|
2015-08-18 21:44:13 +02:00
|
|
|
print("Waiting for connect...");
|
|
|
|
printjson(e);
|
|
|
|
return false;
|
|
|
|
}
|
2016-03-09 18:17:50 +01:00
|
|
|
}, "Mongos " + mongoses[0].host + " did not start.", 5 * 60 * 1000);
|
2015-08-18 21:44:13 +02:00
|
|
|
|
|
|
|
var version = mongosConn.getCollection("config.version").findOne();
|
|
|
|
|
|
|
|
//
|
|
|
|
// Start a second set of mongoses which should respect the initialized version
|
|
|
|
//
|
|
|
|
|
|
|
|
jsTest.log("Starting second set of mongoses...");
|
|
|
|
|
|
|
|
for (var i = 0; i < 3; i++) {
|
2016-03-09 18:17:50 +01:00
|
|
|
var mongos = MongoRunner.runMongos(
|
|
|
|
{binVersion: "latest", configdb: configRS.getURL(), waitForConnect: false});
|
2015-08-18 21:44:13 +02:00
|
|
|
mongoses.push(mongos);
|
|
|
|
}
|
|
|
|
|
2016-03-16 14:57:56 +01:00
|
|
|
var connectToMongos = function(host) {
|
|
|
|
// Eventually connect to a host
|
|
|
|
assert.soon(function() {
|
|
|
|
try {
|
|
|
|
mongosConn = new Mongo(host);
|
|
|
|
return true;
|
|
|
|
} catch (e) {
|
|
|
|
print("Waiting for connect to " + host);
|
|
|
|
printjson(e);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}, "mongos " + host + " did not start.", 5 * 60 * 1000);
|
|
|
|
};
|
|
|
|
|
|
|
|
for (var i = 0; i < mongoses.length; i++) {
|
|
|
|
connectToMongos(mongoses[i].host);
|
|
|
|
}
|
2015-08-18 21:44:13 +02:00
|
|
|
|
|
|
|
// Shut down our mongoses now that we've tested them
|
|
|
|
for (var i = 0; i < mongoses.length; i++) {
|
|
|
|
MongoRunner.stopMongos(mongoses[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Check version and that the version was only updated once
|
|
|
|
//
|
|
|
|
|
|
|
|
assert.eq(5, version.minCompatibleVersion);
|
|
|
|
assert.eq(6, version.currentVersion);
|
|
|
|
assert(version.clusterId);
|
|
|
|
assert.eq(undefined, version.excluding);
|
|
|
|
|
|
|
|
var oplog = configRS.getPrimary().getDB('local').oplog.rs;
|
2016-03-09 18:17:50 +01:00
|
|
|
var updates = oplog.find({ns: "config.version"}).toArray();
|
2015-08-18 21:44:13 +02:00
|
|
|
assert.eq(1, updates.length, 'ops to config.version: ' + tojson(updates));
|
|
|
|
|
|
|
|
configRS.stopSet(15);
|