diff options
author | Jonathan Abrahams <jonathan@mongodb.com> | 2016-11-16 11:07:13 -0500 |
---|---|---|
committer | Jonathan Abrahams <jonathan@mongodb.com> | 2016-11-16 11:07:13 -0500 |
commit | 4344dbc672937b4d20d229a0763bfc22faf664f6 (patch) | |
tree | f722ea968bbe50cf6dada058abac258d7db53193 | |
parent | e7fa7097b7f9057ce8333bdf21247be3f12604cc (diff) | |
download | mongo-4344dbc672937b4d20d229a0763bfc22faf664f6.tar.gz |
SERVER-26993 Extend concurrency suite options
-rw-r--r-- | jstests/concurrency/fsm_all_replication.js | 2 | ||||
-rw-r--r-- | jstests/concurrency/fsm_all_sharded_replication.js | 2 | ||||
-rw-r--r-- | jstests/concurrency/fsm_all_sharded_replication_with_balancer.js | 9 | ||||
-rw-r--r-- | jstests/concurrency/fsm_libs/cluster.js | 139 |
4 files changed, 112 insertions, 40 deletions
diff --git a/jstests/concurrency/fsm_all_replication.js b/jstests/concurrency/fsm_all_replication.js index 93be7b7dfe2..4d09dcb293c 100644 --- a/jstests/concurrency/fsm_all_replication.js +++ b/jstests/concurrency/fsm_all_replication.js @@ -19,4 +19,4 @@ var blacklist = [ runWorkloadsSerially(ls(dir).filter(function(file) { return !Array.contains(blacklist, file); }), - {replication: true}); + {replication: {enabled: true}}); diff --git a/jstests/concurrency/fsm_all_sharded_replication.js b/jstests/concurrency/fsm_all_sharded_replication.js index f524d122ffb..bd732c0d0ed 100644 --- a/jstests/concurrency/fsm_all_sharded_replication.js +++ b/jstests/concurrency/fsm_all_sharded_replication.js @@ -98,4 +98,4 @@ var blacklist = [ runWorkloadsSerially(ls(dir).filter(function(file) { return !Array.contains(blacklist, file); }), - {sharded: true, replication: true}); + {sharded: {enabled: true}, replication: {enabled: true}}); diff --git a/jstests/concurrency/fsm_all_sharded_replication_with_balancer.js b/jstests/concurrency/fsm_all_sharded_replication_with_balancer.js index bc10f840949..ad1bef53c86 100644 --- a/jstests/concurrency/fsm_all_sharded_replication_with_balancer.js +++ b/jstests/concurrency/fsm_all_sharded_replication_with_balancer.js @@ -105,7 +105,8 @@ var blacklist = [ return dir + '/' + file; }); -runWorkloadsSerially(ls(dir).filter(function(file) { - return !Array.contains(blacklist, file); -}), - {sharded: true, replication: true, enableBalancer: true}); +runWorkloadsSerially( + ls(dir).filter(function(file) { + return !Array.contains(blacklist, file); + }), + {sharded: {enabled: true, enableBalancer: true}, replication: {enabled: true}}); diff --git a/jstests/concurrency/fsm_libs/cluster.js b/jstests/concurrency/fsm_libs/cluster.js index bb69b6c8242..1194410023b 100644 --- a/jstests/concurrency/fsm_libs/cluster.js +++ b/jstests/concurrency/fsm_libs/cluster.js @@ -10,33 +10,65 @@ var Cluster = function(options) { return new Cluster(options); } + function getObjectKeys(obj) { + var values = []; + if (typeof obj !== "object") { + return values; + } + Object.keys(obj).forEach(key => { + if (key.indexOf('.') > -1) { + throw new Error('illegal key specified ' + key); + } + var subKeys = getObjectKeys(obj[key]); + if (subKeys.length === 0) { + values.push(key); + } else { + subKeys.forEach(subKey => { + values.push(key + "." + subKey); + }); + } + }); + return values; + } + function validateClusterOptions(options) { var allowedKeys = [ - 'enableBalancer', 'masterSlave', - 'replication', + 'replication.enabled', + 'replication.numNodes', 'sameCollection', 'sameDB', 'setupFunctions', - 'sharded', + 'sharded.enabled', + 'sharded.enableBalancer', + 'sharded.numMongos', + 'sharded.numShards', 'teardownFunctions' ]; - Object.keys(options).forEach(function(option) { + getObjectKeys(options).forEach(function(option) { assert.contains(option, allowedKeys, 'invalid option: ' + tojson(option) + '; valid options are: ' + tojson(allowedKeys)); }); - options.enableBalancer = options.enableBalancer || false; - assert.eq('boolean', typeof options.enableBalancer); - options.masterSlave = options.masterSlave || false; assert.eq('boolean', typeof options.masterSlave); - options.replication = options.replication || false; - assert.eq('boolean', typeof options.replication); + options.replication = options.replication || {}; + assert.eq('object', typeof options.replication); + + options.replication.enabled = options.replication.enabled || false; + assert.eq('boolean', typeof options.replication.enabled); + + if (typeof options.replication.numNodes !== 'undefined') { + assert(options.replication.enabled, + "Must have replication.enabled be true if 'replication.numNodes' is specified"); + } + + options.replication.numNodes = options.replication.numNodes || 3; + assert.eq('number', typeof options.replication.numNodes); options.sameCollection = options.sameCollection || false; assert.eq('boolean', typeof options.sameCollection); @@ -44,8 +76,35 @@ var Cluster = function(options) { options.sameDB = options.sameDB || false; assert.eq('boolean', typeof options.sameDB); - options.sharded = options.sharded || false; - assert.eq('boolean', typeof options.sharded); + options.sharded = options.sharded || {}; + assert.eq('object', typeof options.sharded); + + options.sharded.enabled = options.sharded.enabled || false; + assert.eq('boolean', typeof options.sharded.enabled); + + if (typeof options.sharded.enableBalancer !== 'undefined') { + assert(options.sharded.enabled, + "Must have sharded.enabled be true if 'sharded.enableBalancer' is specified"); + } + + options.sharded.enableBalancer = options.sharded.enableBalancer || false; + assert.eq('boolean', typeof options.sharded.enableBalancer); + + if (typeof options.sharded.numMongos !== 'undefined') { + assert(options.sharded.enabled, + "Must have sharded.enabled be true if 'sharded.numMongos' is specified"); + } + + options.sharded.numMongos = options.sharded.numMongos || 2; + assert.eq('number', typeof options.sharded.numMongos); + + if (typeof options.sharded.numShards !== 'undefined') { + assert(options.sharded.enabled, + "Must have sharded.enabled be true if 'sharded.numShards' is specified"); + } + + options.sharded.numShards = options.sharded.numShards || 2; + assert.eq('number', typeof options.sharded.numShards); options.setupFunctions = options.setupFunctions || {}; assert.eq('object', typeof options.setupFunctions); @@ -57,7 +116,8 @@ var Cluster = function(options) { 'Expected setupFunctions.mongod to be an array of functions'); if (typeof options.setupFunctions.mongos !== 'undefined') { - assert(options.sharded, "Must be sharded if 'setupFunctions.mongos' is specified"); + assert(options.sharded.enabled, + "Must have sharded.enabled be true if 'setupFunctions.mongos' is specified"); } options.setupFunctions.mongos = options.setupFunctions.mongos || []; @@ -76,7 +136,8 @@ var Cluster = function(options) { 'Expected teardownFunctions.mongod to be an array of functions'); if (typeof options.teardownFunctions.mongos !== 'undefined') { - assert(options.sharded, "Must be sharded if 'teardownFunctions.mongos' is specified"); + assert(options.sharded.enabled, + "Must have sharded.enabled be true if 'teardownFunctions.mongos' is specified"); } options.teardownFunctions.mongos = options.teardownFunctions.mongos || []; @@ -85,10 +146,23 @@ var Cluster = function(options) { assert(options.teardownFunctions.mongos.every(f => (typeof f === 'function')), 'Expected teardownFunctions.mongos to be an array of functions'); - assert(!options.masterSlave || !options.replication, - "Both 'masterSlave' and " + "'replication' cannot be true"); - assert(!options.masterSlave || !options.sharded, - "Both 'masterSlave' and 'sharded' cannot" + "be true"); + assert(!options.masterSlave || !options.replication.enabled, + "Both 'masterSlave' and " + "'replication.enabled' cannot be true"); + assert(!options.masterSlave || !options.sharded.enabled, + "Both 'masterSlave' and 'sharded.enabled' cannot" + "be true"); + } + + function makeReplSetTestConfig(numReplSetNodes) { + const REPL_SET_VOTING_LIMIT = 7; + // Workaround for SERVER-26893 to specify when numReplSetNodes > REPL_SET_VOTING_LIMIT. + var rstConfig = []; + for (var i = 0; i < numReplSetNodes; i++) { + rstConfig[i] = {}; + if (i >= REPL_SET_VOTING_LIMIT) { + rstConfig[i].rsConfig = {priority: 0, votes: 0}; + } + } + return rstConfig; } var conn; @@ -102,9 +176,6 @@ var Cluster = function(options) { var nextConn = 0; var replSets = []; - // TODO: Define size of replica set from options - var replSetNodes = 3; - validateClusterOptions(options); Object.freeze(options); @@ -116,19 +187,19 @@ var Cluster = function(options) { throw new Error('cluster has already been initialized'); } - if (options.sharded) { + if (options.sharded.enabled) { // TODO: allow 'options' to specify the number of shards and mongos processes var shardConfig = { - shards: 2, - mongos: 2, + shards: options.sharded.numShards, + mongos: options.sharded.numMongos, verbose: verbosityLevel, - other: {enableBalancer: options.enableBalancer} + other: {enableBalancer: options.sharded.enableBalancer} }; // TODO: allow 'options' to specify an 'rs' config - if (options.replication) { + if (options.replication.enabled) { shardConfig.rs = { - nodes: replSetNodes, + nodes: makeReplSetTestConfig(options.replication.numNodes), // Increase the oplog size (in MB) to prevent rollover // during write-heavy workloads oplogSize: 1024, @@ -178,10 +249,9 @@ var Cluster = function(options) { ++i; mongod = st['d' + i]; } - } else if (options.replication) { - // TODO: allow 'options' to specify the number of nodes + } else if (options.replication.enabled) { var replSetConfig = { - nodes: replSetNodes, + nodes: makeReplSetTestConfig(options.replication.numNodes), // Increase the oplog size (in MB) to prevent rollover during write-heavy workloads oplogSize: 1024, nodeOptions: {verbose: verbosityLevel} @@ -291,11 +361,11 @@ var Cluster = function(options) { }; this.isSharded = function isSharded() { - return options.sharded; + return options.sharded.enabled; }; this.isReplication = function isReplication() { - return options.replication; + return options.replication.enabled; }; this.shardCollection = function shardCollection() { @@ -390,7 +460,7 @@ var Cluster = function(options) { }; this.isBalancerEnabled = function isBalancerEnabled() { - return this.isSharded() && options.enableBalancer; + return this.isSharded() && options.sharded.enableBalancer; }; this.validateAllCollections = function validateAllCollections(phase) { @@ -457,7 +527,7 @@ var Cluster = function(options) { // Wait for all previous workload operations to complete, with "getLastError". res = primary.getDB('test').runCommand({ getLastError: 1, - w: replSetNodes, + w: options.replication.numNodes, wtimeout: 5 * 60 * 1000, wOpTime: primaryInfo.optime }); @@ -502,5 +572,6 @@ var Cluster = function(options) { * and false otherwise. */ Cluster.isStandalone = function isStandalone(clusterOptions) { - return !clusterOptions.sharded && !clusterOptions.replication && !clusterOptions.masterSlave; + return !clusterOptions.sharded.enabled && !clusterOptions.replication.enabled && + !clusterOptions.masterSlave; }; |