diff options
Diffstat (limited to 'jstests/concurrency/fsm_workloads')
126 files changed, 1943 insertions, 2580 deletions
diff --git a/jstests/concurrency/fsm_workloads/agg_base.js b/jstests/concurrency/fsm_workloads/agg_base.js index 846e6900215..9bc1be04785 100644 --- a/jstests/concurrency/fsm_workloads/agg_base.js +++ b/jstests/concurrency/fsm_workloads/agg_base.js @@ -45,9 +45,7 @@ var $config = (function() { } }; - var transitions = { - query: {query: 1} - }; + var transitions = {query: {query: 1}}; function setup(db, collName, cluster) { // load example data @@ -55,13 +53,12 @@ var $config = (function() { for (var i = 0; i < this.numDocs; ++i) { // note: padDoc caches the large string after allocating it once, so it's ok to call it // in this loop - bulk.insert(padDoc( - { - flag: i % 2 ? true : false, - rand: Random.rand(), - randInt: Random.randInt(this.numDocs) - }, - this.docSize)); + bulk.insert(padDoc({ + flag: i % 2 ? true : false, + rand: Random.rand(), + randInt: Random.randInt(this.numDocs) + }, + this.docSize)); } var res = bulk.execute(); assertWhenOwnColl.writeOK(res); diff --git a/jstests/concurrency/fsm_workloads/agg_graph_lookup.js b/jstests/concurrency/fsm_workloads/agg_graph_lookup.js index 7b675dc1e9c..aacbe632fc2 100644 --- a/jstests/concurrency/fsm_workloads/agg_graph_lookup.js +++ b/jstests/concurrency/fsm_workloads/agg_graph_lookup.js @@ -7,28 +7,28 @@ */ var $config = (function() { - var data = { - numDocs: 1000 - }; + var data = {numDocs: 1000}; var states = { query: function query(db, collName) { var limitAmount = 20; var startingId = Random.randInt(this.numDocs - limitAmount); - var res = db[collName].aggregate([ - {$match: {_id: {$gt: startingId}}}, - { - $graphLookup: { - from: collName, - startWith: "$to", - connectToField: "_id", - connectFromField: "to", - maxDepth: 10, - as: "out", - } - }, - {$limit: limitAmount} - ]).toArray(); + var res = db[collName] + .aggregate([ + {$match: {_id: {$gt: startingId}}}, + { + $graphLookup: { + from: collName, + startWith: "$to", + connectToField: "_id", + connectFromField: "to", + maxDepth: 10, + as: "out", + } + }, + {$limit: limitAmount} + ]) + .toArray(); assertWhenOwnColl.eq(res.length, limitAmount); }, @@ -40,10 +40,7 @@ var $config = (function() { } }; - var transitions = { - query: {query: 0.5, update: 0.5}, - update: {query: 0.5, update: 0.5} - }; + var transitions = {query: {query: 0.5, update: 0.5}, update: {query: 0.5, update: 0.5}}; function setup(db, collName, cluster) { // Load example data. diff --git a/jstests/concurrency/fsm_workloads/agg_group_external.js b/jstests/concurrency/fsm_workloads/agg_group_external.js index 22d71d4564d..e4ca604a99c 100644 --- a/jstests/concurrency/fsm_workloads/agg_group_external.js +++ b/jstests/concurrency/fsm_workloads/agg_group_external.js @@ -12,43 +12,41 @@ load('jstests/concurrency/fsm_libs/extend_workload.js'); // for extendWo load('jstests/concurrency/fsm_workloads/agg_base.js'); // for $config load('jstests/concurrency/fsm_workload_helpers/drop_utils.js'); // for dropCollections -var $config = extendWorkload( - $config, - function($config, $super) { - - // use enough docs to exceed 100MB, the in-memory limit for $sort and $group - $config.data.numDocs = 24 * 1000; - var MB = 1024 * 1024; // bytes - assertAlways.lte(100 * MB, $config.data.numDocs * $config.data.docSize); - - // assume no other workload will manipulate collections with this prefix - $config.data.getOutputCollPrefix = function getOutputCollPrefix(collName) { - return collName + '_out_agg_group_external_'; - }; - - $config.states.query = function query(db, collName) { - var otherCollName = this.getOutputCollPrefix(collName) + this.tid; - var cursor = db[collName].aggregate( - [{$group: {_id: '$randInt', count: {$sum: 1}}}, {$out: otherCollName}], - {allowDiskUse: true}); - assertAlways.eq(0, cursor.itcount()); - assertWhenOwnColl(function() { - // sum the .count fields in the output coll - var sum = db[otherCollName] - .aggregate([{$group: {_id: null, totalCount: {$sum: '$count'}}}]) - .toArray()[0] - .totalCount; - assertWhenOwnColl.eq(this.numDocs, sum); - }.bind(this)); - }; - - $config.teardown = function teardown(db, collName, cluster) { - $super.teardown.apply(this, arguments); - - // drop all collections with this workload's assumed-to-be-unique prefix - // NOTE: assumes the prefix contains no special regex chars - dropCollections(db, new RegExp('^' + this.getOutputCollPrefix(collName))); - }; - - return $config; - }); +var $config = extendWorkload($config, function($config, $super) { + + // use enough docs to exceed 100MB, the in-memory limit for $sort and $group + $config.data.numDocs = 24 * 1000; + var MB = 1024 * 1024; // bytes + assertAlways.lte(100 * MB, $config.data.numDocs * $config.data.docSize); + + // assume no other workload will manipulate collections with this prefix + $config.data.getOutputCollPrefix = function getOutputCollPrefix(collName) { + return collName + '_out_agg_group_external_'; + }; + + $config.states.query = function query(db, collName) { + var otherCollName = this.getOutputCollPrefix(collName) + this.tid; + var cursor = db[collName].aggregate( + [{$group: {_id: '$randInt', count: {$sum: 1}}}, {$out: otherCollName}], + {allowDiskUse: true}); + assertAlways.eq(0, cursor.itcount()); + assertWhenOwnColl(function() { + // sum the .count fields in the output coll + var sum = db[otherCollName] + .aggregate([{$group: {_id: null, totalCount: {$sum: '$count'}}}]) + .toArray()[0] + .totalCount; + assertWhenOwnColl.eq(this.numDocs, sum); + }.bind(this)); + }; + + $config.teardown = function teardown(db, collName, cluster) { + $super.teardown.apply(this, arguments); + + // drop all collections with this workload's assumed-to-be-unique prefix + // NOTE: assumes the prefix contains no special regex chars + dropCollections(db, new RegExp('^' + this.getOutputCollPrefix(collName))); + }; + + return $config; +}); diff --git a/jstests/concurrency/fsm_workloads/agg_match.js b/jstests/concurrency/fsm_workloads/agg_match.js index a685096155b..ca9682e1a58 100644 --- a/jstests/concurrency/fsm_workloads/agg_match.js +++ b/jstests/concurrency/fsm_workloads/agg_match.js @@ -8,31 +8,29 @@ load('jstests/concurrency/fsm_libs/extend_workload.js'); // for extendWorkload load('jstests/concurrency/fsm_workloads/agg_base.js'); // for $config -var $config = extendWorkload( - $config, - function($config, $super) { +var $config = extendWorkload($config, function($config, $super) { - $config.data.getOutCollName = function getOutCollName(collName) { - return collName + '_out_agg_match'; - }; + $config.data.getOutCollName = function getOutCollName(collName) { + return collName + '_out_agg_match'; + }; - $config.states.query = function query(db, collName) { - // note that all threads output to the same collection - var otherCollName = this.getOutCollName(collName); - var cursor = db[collName].aggregate([{$match: {flag: true}}, {$out: otherCollName}]); - assertAlways.eq(0, cursor.itcount(), 'cursor returned by $out should always be empty'); - // NOTE: This relies on the fast-path for .count() with no query being isolated. - // NOTE: There's a bug, SERVER-3645, where .count() is wrong on sharded collections, so - // we - // blacklisted this test for sharded clusters. - assertWhenOwnColl.eq(db[collName].count() / 2, db[otherCollName].count()); - }; + $config.states.query = function query(db, collName) { + // note that all threads output to the same collection + var otherCollName = this.getOutCollName(collName); + var cursor = db[collName].aggregate([{$match: {flag: true}}, {$out: otherCollName}]); + assertAlways.eq(0, cursor.itcount(), 'cursor returned by $out should always be empty'); + // NOTE: This relies on the fast-path for .count() with no query being isolated. + // NOTE: There's a bug, SERVER-3645, where .count() is wrong on sharded collections, so + // we + // blacklisted this test for sharded clusters. + assertWhenOwnColl.eq(db[collName].count() / 2, db[otherCollName].count()); + }; - $config.teardown = function teardown(db, collName, cluster) { - $super.teardown.apply(this, arguments); + $config.teardown = function teardown(db, collName, cluster) { + $super.teardown.apply(this, arguments); - assertWhenOwnColl(db[this.getOutCollName(collName)].drop()); - }; + assertWhenOwnColl(db[this.getOutCollName(collName)].drop()); + }; - return $config; - }); + return $config; +}); diff --git a/jstests/concurrency/fsm_workloads/agg_sort.js b/jstests/concurrency/fsm_workloads/agg_sort.js index 936ae2cf71b..8ab372d87f0 100644 --- a/jstests/concurrency/fsm_workloads/agg_sort.js +++ b/jstests/concurrency/fsm_workloads/agg_sort.js @@ -10,30 +10,27 @@ load('jstests/concurrency/fsm_libs/extend_workload.js'); // for extendWo load('jstests/concurrency/fsm_workloads/agg_base.js'); // for $config load('jstests/concurrency/fsm_workload_helpers/drop_utils.js'); // for dropCollections -var $config = extendWorkload( - $config, - function($config, $super) { +var $config = extendWorkload($config, function($config, $super) { - $config.data.getOutputCollPrefix = function getOutputCollPrefix(collName) { - return collName + '_out_agg_sort_'; - }; + $config.data.getOutputCollPrefix = function getOutputCollPrefix(collName) { + return collName + '_out_agg_sort_'; + }; - $config.states.query = function query(db, collName) { - var otherCollName = this.getOutputCollPrefix(collName) + this.tid; - var cursor = db[collName].aggregate( - [{$match: {flag: true}}, {$sort: {rand: 1}}, {$out: otherCollName}]); - assertAlways.eq(0, cursor.itcount()); - assertWhenOwnColl.eq(db[collName].find().itcount() / 2, - db[otherCollName].find().itcount()); - }; + $config.states.query = function query(db, collName) { + var otherCollName = this.getOutputCollPrefix(collName) + this.tid; + var cursor = db[collName].aggregate( + [{$match: {flag: true}}, {$sort: {rand: 1}}, {$out: otherCollName}]); + assertAlways.eq(0, cursor.itcount()); + assertWhenOwnColl.eq(db[collName].find().itcount() / 2, db[otherCollName].find().itcount()); + }; - $config.teardown = function teardown(db, collName, cluster) { - $super.teardown.apply(this, arguments); + $config.teardown = function teardown(db, collName, cluster) { + $super.teardown.apply(this, arguments); - // drop all collections with this workload's assumed-to-be-unique prefix - // NOTE: assumes the prefix contains no special regex chars - dropCollections(db, new RegExp('^' + this.getOutputCollPrefix(collName))); - }; + // drop all collections with this workload's assumed-to-be-unique prefix + // NOTE: assumes the prefix contains no special regex chars + dropCollections(db, new RegExp('^' + this.getOutputCollPrefix(collName))); + }; - return $config; - }); + return $config; +}); diff --git a/jstests/concurrency/fsm_workloads/agg_sort_external.js b/jstests/concurrency/fsm_workloads/agg_sort_external.js index 8a7b6b22495..785d1a4d150 100644 --- a/jstests/concurrency/fsm_workloads/agg_sort_external.js +++ b/jstests/concurrency/fsm_workloads/agg_sort_external.js @@ -12,40 +12,36 @@ load('jstests/concurrency/fsm_libs/extend_workload.js'); // for extendWo load('jstests/concurrency/fsm_workloads/agg_base.js'); // for $config load('jstests/concurrency/fsm_workload_helpers/drop_utils.js'); // for dropCollections -var $config = extendWorkload( - $config, - function($config, $super) { - - // use enough docs to exceed 100MB, the in-memory limit for $sort and $group - $config.data.numDocs = 24 * 1000; - var MB = 1024 * 1024; // bytes - // assert that *half* the docs exceed the in-memory limit, because the $match stage will - // only - // pass half the docs in the collection on to the $sort stage. - assertAlways.lte(100 * MB, $config.data.numDocs * $config.data.docSize / 2); - - $config.data.getOutputCollPrefix = function getOutputCollPrefix(collName) { - return collName + '_out_agg_sort_external_'; - }; - - $config.states.query = function query(db, collName) { - var otherCollName = this.getOutputCollPrefix(collName) + this.tid; - var cursor = - db[collName] - .aggregate([{$match: {flag: true}}, {$sort: {rand: 1}}, {$out: otherCollName}], - {allowDiskUse: true}); - assertAlways.eq(0, cursor.itcount()); - assertWhenOwnColl.eq(db[collName].find().itcount() / 2, - db[otherCollName].find().itcount()); - }; - - $config.teardown = function teardown(db, collName, cluster) { - $super.teardown.apply(this, arguments); - - // drop all collections with this workload's assumed-to-be-unique prefix - // NOTE: assumes the prefix contains no special regex chars - dropCollections(db, new RegExp('^' + this.getOutputCollPrefix(collName))); - }; - - return $config; - }); +var $config = extendWorkload($config, function($config, $super) { + + // use enough docs to exceed 100MB, the in-memory limit for $sort and $group + $config.data.numDocs = 24 * 1000; + var MB = 1024 * 1024; // bytes + // assert that *half* the docs exceed the in-memory limit, because the $match stage will + // only + // pass half the docs in the collection on to the $sort stage. + assertAlways.lte(100 * MB, $config.data.numDocs * $config.data.docSize / 2); + + $config.data.getOutputCollPrefix = function getOutputCollPrefix(collName) { + return collName + '_out_agg_sort_external_'; + }; + + $config.states.query = function query(db, collName) { + var otherCollName = this.getOutputCollPrefix(collName) + this.tid; + var cursor = db[collName].aggregate( + [{$match: {flag: true}}, {$sort: {rand: 1}}, {$out: otherCollName}], + {allowDiskUse: true}); + assertAlways.eq(0, cursor.itcount()); + assertWhenOwnColl.eq(db[collName].find().itcount() / 2, db[otherCollName].find().itcount()); + }; + + $config.teardown = function teardown(db, collName, cluster) { + $super.teardown.apply(this, arguments); + + // drop all collections with this workload's assumed-to-be-unique prefix + // NOTE: assumes the prefix contains no special regex chars + dropCollections(db, new RegExp('^' + this.getOutputCollPrefix(collName))); + }; + + return $config; +}); diff --git a/jstests/concurrency/fsm_workloads/auth_create_role.js b/jstests/concurrency/fsm_workloads/auth_create_role.js index 8b8d3933c2d..6ad5de17d9a 100644 --- a/jstests/concurrency/fsm_workloads/auth_create_role.js +++ b/jstests/concurrency/fsm_workloads/auth_create_role.js @@ -44,17 +44,11 @@ var $config = (function() { } } - return { - init: init, - createRole: createRole - }; + return {init: init, createRole: createRole}; })(); - var transitions = { - init: {createRole: 1}, - createRole: {createRole: 1} - }; + var transitions = {init: {createRole: 1}, createRole: {createRole: 1}}; function teardown(db, collName, cluster) { var pattern = new RegExp('^' + this.prefix + '\\d+_\\d+$'); diff --git a/jstests/concurrency/fsm_workloads/auth_create_user.js b/jstests/concurrency/fsm_workloads/auth_create_user.js index e49c63bc68e..07fd1135032 100644 --- a/jstests/concurrency/fsm_workloads/auth_create_user.js +++ b/jstests/concurrency/fsm_workloads/auth_create_user.js @@ -39,17 +39,11 @@ var $config = (function() { } } - return { - init: init, - createUser: createUser - }; + return {init: init, createUser: createUser}; })(); - var transitions = { - init: {createUser: 1}, - createUser: {createUser: 1} - }; + var transitions = {init: {createUser: 1}, createUser: {createUser: 1}}; function teardown(db, collName, cluster) { var pattern = new RegExp('^' + this.prefix + '\\d+_\\d+$'); diff --git a/jstests/concurrency/fsm_workloads/auth_drop_role.js b/jstests/concurrency/fsm_workloads/auth_drop_role.js index d41066dbc63..eba694ccd49 100644 --- a/jstests/concurrency/fsm_workloads/auth_drop_role.js +++ b/jstests/concurrency/fsm_workloads/auth_drop_role.js @@ -44,24 +44,12 @@ var $config = (function() { assertAlways.isnull(db.getRole(roleName), "role '" + roleName + "' should not exist"); } - return { - init: init, - createAndDropRole: createAndDropRole - }; + return {init: init, createAndDropRole: createAndDropRole}; })(); - var transitions = { - init: {createAndDropRole: 1}, - createAndDropRole: {createAndDropRole: 1} - }; + var transitions = {init: {createAndDropRole: 1}, createAndDropRole: {createAndDropRole: 1}}; - return { - threadCount: 10, - iterations: 20, - data: data, - states: states, - transitions: transitions - }; + return {threadCount: 10, iterations: 20, data: data, states: states, transitions: transitions}; })(); diff --git a/jstests/concurrency/fsm_workloads/auth_drop_user.js b/jstests/concurrency/fsm_workloads/auth_drop_user.js index 65cb8e41da2..a47d5566874 100644 --- a/jstests/concurrency/fsm_workloads/auth_drop_user.js +++ b/jstests/concurrency/fsm_workloads/auth_drop_user.js @@ -37,24 +37,12 @@ var $config = (function() { assertAlways.isnull(db.getUser(username), "user '" + username + "' should not exist"); } - return { - init: init, - createAndDropUser: createAndDropUser - }; + return {init: init, createAndDropUser: createAndDropUser}; })(); - var transitions = { - init: {createAndDropUser: 1}, - createAndDropUser: {createAndDropUser: 1} - }; + var transitions = {init: {createAndDropUser: 1}, createAndDropUser: {createAndDropUser: 1}}; - return { - threadCount: 10, - iterations: 20, - data: data, - states: states, - transitions: transitions - }; + return {threadCount: 10, iterations: 20, data: data, states: states, transitions: transitions}; })(); diff --git a/jstests/concurrency/fsm_workloads/collmod.js b/jstests/concurrency/fsm_workloads/collmod.js index 7b803cd3284..adfe98c2ff1 100644 --- a/jstests/concurrency/fsm_workloads/collmod.js +++ b/jstests/concurrency/fsm_workloads/collmod.js @@ -33,15 +33,11 @@ var $config = (function() { } } - return { - collMod: collMod - }; + return {collMod: collMod}; })(); - var transitions = { - collMod: {collMod: 1} - }; + var transitions = {collMod: {collMod: 1}}; function setup(db, collName, cluster) { // other workloads that extend this one might have set 'this.threadCollName' diff --git a/jstests/concurrency/fsm_workloads/collmod_separate_collections.js b/jstests/concurrency/fsm_workloads/collmod_separate_collections.js index 5233733eb2d..a033eb200ee 100644 --- a/jstests/concurrency/fsm_workloads/collmod_separate_collections.js +++ b/jstests/concurrency/fsm_workloads/collmod_separate_collections.js @@ -13,32 +13,28 @@ load('jstests/concurrency/fsm_libs/extend_workload.js'); // for extendWo load('jstests/concurrency/fsm_workloads/collmod.js'); // for $config load('jstests/concurrency/fsm_workload_helpers/drop_utils.js'); // for dropCollections -var $config = extendWorkload($config, - function($config, $super) { - $config.data.prefix = 'collmod_separate_collections'; - $config.data.shardKey = { - createdAt: 1 - }; +var $config = extendWorkload($config, function($config, $super) { + $config.data.prefix = 'collmod_separate_collections'; + $config.data.shardKey = {createdAt: 1}; - $config.states.init = function init(db, collName) { - this.threadCollName = this.prefix + '_' + this.tid; - $super.setup.call(this, db, this.threadCollName); - }; + $config.states.init = function init(db, collName) { + this.threadCollName = this.prefix + '_' + this.tid; + $super.setup.call(this, db, this.threadCollName); + }; - $config.transitions = - Object.extend({init: {collMod: 1}}, $super.transitions); + $config.transitions = Object.extend({init: {collMod: 1}}, $super.transitions); - $config.setup = function setup(db, collName, cluster) { - // no-op: since the init state is used to setup - // the separate collections on a per-thread basis. - }; + $config.setup = function setup(db, collName, cluster) { + // no-op: since the init state is used to setup + // the separate collections on a per-thread basis. + }; - $config.teardown = function teardown(db, collName, cluster) { - var pattern = new RegExp('^' + this.prefix + '_\\d+$'); - dropCollections(db, pattern); - $super.teardown.apply(this, arguments); - }; + $config.teardown = function teardown(db, collName, cluster) { + var pattern = new RegExp('^' + this.prefix + '_\\d+$'); + dropCollections(db, pattern); + $super.teardown.apply(this, arguments); + }; - $config.startState = 'init'; - return $config; - }); + $config.startState = 'init'; + return $config; +}); diff --git a/jstests/concurrency/fsm_workloads/compact.js b/jstests/concurrency/fsm_workloads/compact.js index afea3f8a28f..8f91f52bf5e 100644 --- a/jstests/concurrency/fsm_workloads/compact.js +++ b/jstests/concurrency/fsm_workloads/compact.js @@ -72,12 +72,7 @@ var $config = (function() { assertWhenOwnColl.eq(indexesCount, this.nIndexes); } - return { - init: init, - collectionSetup: collectionSetup, - compact: compact, - query: query - }; + return {init: init, collectionSetup: collectionSetup, compact: compact, query: query}; })(); var transitions = { diff --git a/jstests/concurrency/fsm_workloads/compact_simultaneous_padding_bytes.js b/jstests/concurrency/fsm_workloads/compact_simultaneous_padding_bytes.js index 47ad30cedab..b1991cd3b8c 100644 --- a/jstests/concurrency/fsm_workloads/compact_simultaneous_padding_bytes.js +++ b/jstests/concurrency/fsm_workloads/compact_simultaneous_padding_bytes.js @@ -12,26 +12,24 @@ load('jstests/concurrency/fsm_libs/extend_workload.js'); // for extend load('jstests/concurrency/fsm_workloads/compact.js'); // for $config load('jstests/concurrency/fsm_workload_helpers/server_types.js'); // for isEphemeral -var $config = extendWorkload( - $config, - function($config, $super) { - $config.states.init = function init(db, collName) { - this.threadCollName = collName; - }; +var $config = extendWorkload($config, function($config, $super) { + $config.states.init = function init(db, collName) { + this.threadCollName = collName; + }; - $config.states.compact = function compact(db, collName) { - var res = - db.runCommand({compact: this.threadCollName, paddingBytes: 1024 * 5, force: true}); - if (!isEphemeral(db)) { - assertAlways.commandWorked(res); - } else { - assertAlways.commandFailedWithCode(res, ErrorCodes.CommandNotSupported); - } - }; + $config.states.compact = function compact(db, collName) { + var res = + db.runCommand({compact: this.threadCollName, paddingBytes: 1024 * 5, force: true}); + if (!isEphemeral(db)) { + assertAlways.commandWorked(res); + } else { + assertAlways.commandFailedWithCode(res, ErrorCodes.CommandNotSupported); + } + }; - // no-op the query state because querying while compacting can result in closed cursors - // as per SERVER-3964, as well as inaccurate counts, leaving nothing to assert. - $config.states.query = function query(db, collName) {}; + // no-op the query state because querying while compacting can result in closed cursors + // as per SERVER-3964, as well as inaccurate counts, leaving nothing to assert. + $config.states.query = function query(db, collName) {}; - return $config; - }); + return $config; +}); diff --git a/jstests/concurrency/fsm_workloads/convert_to_capped_collection.js b/jstests/concurrency/fsm_workloads/convert_to_capped_collection.js index 79b9934077b..14cd4e98646 100644 --- a/jstests/concurrency/fsm_workloads/convert_to_capped_collection.js +++ b/jstests/concurrency/fsm_workloads/convert_to_capped_collection.js @@ -13,9 +13,7 @@ load('jstests/concurrency/fsm_workload_helpers/drop_utils.js'); var $config = (function() { // TODO: This workload may fail if an iteration multiplier is specified. - var data = { - prefix: 'convert_to_capped_collection' - }; + var data = {prefix: 'convert_to_capped_collection'}; var states = (function() { @@ -62,16 +60,10 @@ var $config = (function() { }); } - return { - init: init, - convertToCapped: convertToCapped - }; + return {init: init, convertToCapped: convertToCapped}; })(); - var transitions = { - init: {convertToCapped: 1}, - convertToCapped: {convertToCapped: 1} - }; + var transitions = {init: {convertToCapped: 1}, convertToCapped: {convertToCapped: 1}}; function setup(db, collName, cluster) { // Initial size should not be a power of 256. diff --git a/jstests/concurrency/fsm_workloads/convert_to_capped_collection_index.js b/jstests/concurrency/fsm_workloads/convert_to_capped_collection_index.js index 01342b9b603..4b410ea7305 100644 --- a/jstests/concurrency/fsm_workloads/convert_to_capped_collection_index.js +++ b/jstests/concurrency/fsm_workloads/convert_to_capped_collection_index.js @@ -16,14 +16,12 @@ load('jstests/concurrency/fsm_libs/extend_workload.js'); // for extendWorkload load('jstests/concurrency/fsm_workloads/convert_to_capped_collection.js'); // for $config -var $config = extendWorkload( - $config, - function($config, $super) { - $config.states.convertToCapped = function convertToCapped(db, collName) { - assertWhenOwnDB.commandWorked(db[this.threadCollName].ensureIndex({i: 1, rand: 1})); - assertWhenOwnDB.eq(2, db[this.threadCollName].getIndexes().length); - $super.states.convertToCapped.apply(this, arguments); - }; +var $config = extendWorkload($config, function($config, $super) { + $config.states.convertToCapped = function convertToCapped(db, collName) { + assertWhenOwnDB.commandWorked(db[this.threadCollName].ensureIndex({i: 1, rand: 1})); + assertWhenOwnDB.eq(2, db[this.threadCollName].getIndexes().length); + $super.states.convertToCapped.apply(this, arguments); + }; - return $config; - }); + return $config; +}); diff --git a/jstests/concurrency/fsm_workloads/count.js b/jstests/concurrency/fsm_workloads/count.js index 61a4c93d3ab..16221b7ad9d 100644 --- a/jstests/concurrency/fsm_workloads/count.js +++ b/jstests/concurrency/fsm_workloads/count.js @@ -53,24 +53,12 @@ var $config = (function() { assertWhenOwnColl.eq(this.getCount(db, {i: num}), this.countPerNum); } - return { - init: init, - count: count - }; + return {init: init, count: count}; })(); - var transitions = { - init: {count: 1}, - count: {count: 1} - }; + var transitions = {init: {count: 1}, count: {count: 1}}; - return { - data: data, - threadCount: 10, - iterations: 20, - states: states, - transitions: transitions - }; + return {data: data, threadCount: 10, iterations: 20, states: states, transitions: transitions}; })(); diff --git a/jstests/concurrency/fsm_workloads/count_indexed.js b/jstests/concurrency/fsm_workloads/count_indexed.js index b9c09020042..77edf8da6ef 100644 --- a/jstests/concurrency/fsm_workloads/count_indexed.js +++ b/jstests/concurrency/fsm_workloads/count_indexed.js @@ -14,31 +14,26 @@ load('jstests/concurrency/fsm_libs/extend_workload.js'); // for extendWo load('jstests/concurrency/fsm_workloads/count.js'); // for $config load('jstests/concurrency/fsm_workload_helpers/drop_utils.js'); // for dropCollections -var $config = extendWorkload( - $config, - function($config, $super) { - $config.data.prefix = 'count_fsm'; - $config.data.shardKey = { - tid: 1, - i: 1 - }; +var $config = extendWorkload($config, function($config, $super) { + $config.data.prefix = 'count_fsm'; + $config.data.shardKey = {tid: 1, i: 1}; - $config.data.getCount = function getCount(db, predicate) { - var query = Object.extend({tid: this.tid}, predicate); - return db[this.threadCollName].find(query).hint({tid: 1, i: 1}).count(); - }; + $config.data.getCount = function getCount(db, predicate) { + var query = Object.extend({tid: this.tid}, predicate); + return db[this.threadCollName].find(query).hint({tid: 1, i: 1}).count(); + }; - $config.states.init = function init(db, collName) { - this.threadCollName = this.prefix + '_' + this.tid; - $super.states.init.apply(this, arguments); - assertAlways.commandWorked(db[this.threadCollName].ensureIndex({tid: 1, i: 1})); - }; + $config.states.init = function init(db, collName) { + this.threadCollName = this.prefix + '_' + this.tid; + $super.states.init.apply(this, arguments); + assertAlways.commandWorked(db[this.threadCollName].ensureIndex({tid: 1, i: 1})); + }; - $config.teardown = function teardown(db, collName) { - var pattern = new RegExp('^' + this.prefix + '_\\d+$'); - dropCollections(db, pattern); - $super.teardown.apply(this, arguments); - }; + $config.teardown = function teardown(db, collName) { + var pattern = new RegExp('^' + this.prefix + '_\\d+$'); + dropCollections(db, pattern); + $super.teardown.apply(this, arguments); + }; - return $config; - }); + return $config; +}); diff --git a/jstests/concurrency/fsm_workloads/count_limit_skip.js b/jstests/concurrency/fsm_workloads/count_limit_skip.js index 59cc5db835f..169094a1c82 100644 --- a/jstests/concurrency/fsm_workloads/count_limit_skip.js +++ b/jstests/concurrency/fsm_workloads/count_limit_skip.js @@ -14,42 +14,36 @@ load('jstests/concurrency/fsm_libs/extend_workload.js'); // for extendWo load('jstests/concurrency/fsm_workloads/count.js'); // for $config load('jstests/concurrency/fsm_workload_helpers/drop_utils.js'); // for dropCollections -var $config = extendWorkload( - $config, - function($config, $super) { - $config.data.prefix = 'count_fsm_q_l_s'; - - $config.data.getCount = function getCount(db, predicate) { - var query = Object.extend({tid: this.tid}, predicate); - return db[this.threadCollName] - .find(query) - .skip(this.countPerNum - 1) - .limit(10) - .count(true); - }; - - $config.states.init = function init(db, collName) { - this.threadCollName = this.prefix + '_' + this.tid; - - $super.states.init.apply(this, arguments); - }; - - $config.states.count = function count(db, collName) { - assertWhenOwnColl.eq(this.getCount(db), - // having done 'skip(this.countPerNum - 1).limit(10)' - 10); - - var num = Random.randInt(this.modulus); - assertWhenOwnColl.eq(this.getCount(db, {i: num}), - // having done 'skip(this.countPerNum - 1).limit(10)' - 1); - }; - - $config.teardown = function teardown(db, collName) { - var pattern = new RegExp('^' + this.prefix + '_\\d+$'); - dropCollections(db, pattern); - $super.teardown.apply(this, arguments); - }; - - return $config; - }); +var $config = extendWorkload($config, function($config, $super) { + $config.data.prefix = 'count_fsm_q_l_s'; + + $config.data.getCount = function getCount(db, predicate) { + var query = Object.extend({tid: this.tid}, predicate); + return db[this.threadCollName].find(query).skip(this.countPerNum - 1).limit(10).count(true); + }; + + $config.states.init = function init(db, collName) { + this.threadCollName = this.prefix + '_' + this.tid; + + $super.states.init.apply(this, arguments); + }; + + $config.states.count = function count(db, collName) { + assertWhenOwnColl.eq(this.getCount(db), + // having done 'skip(this.countPerNum - 1).limit(10)' + 10); + + var num = Random.randInt(this.modulus); + assertWhenOwnColl.eq(this.getCount(db, {i: num}), + // having done 'skip(this.countPerNum - 1).limit(10)' + 1); + }; + + $config.teardown = function teardown(db, collName) { + var pattern = new RegExp('^' + this.prefix + '_\\d+$'); + dropCollections(db, pattern); + $super.teardown.apply(this, arguments); + }; + + return $config; +}); diff --git a/jstests/concurrency/fsm_workloads/create_capped_collection.js b/jstests/concurrency/fsm_workloads/create_capped_collection.js index 96fdda8ebda..c0ec6c0e071 100644 --- a/jstests/concurrency/fsm_workloads/create_capped_collection.js +++ b/jstests/concurrency/fsm_workloads/create_capped_collection.js @@ -14,10 +14,7 @@ var $config = (function() { // Returns a document of the form { _id: ObjectId(...), field: '...' } // with specified BSON size. function makeDocWithSize(targetSize) { - var doc = { - _id: new ObjectId(), - field: '' - }; + var doc = {_id: new ObjectId(), field: ''}; var size = Object.bsonsize(doc); assertAlways.gte(targetSize, size); @@ -45,11 +42,9 @@ var $config = (function() { // Returns an array containing the _id fields of all the documents // in the collection, sorted according to their insertion order. function getObjectIds(db, collName) { - return db[collName] - .find({}, {_id: 1}) - .map(function(doc) { - return doc._id; - }); + return db[collName].find({}, {_id: 1}).map(function(doc) { + return doc._id; + }); } var data = { @@ -148,17 +143,11 @@ var $config = (function() { this.verifySizeTruncation(db, myCollName, options); } - return { - init: init, - create: create - }; + return {init: init, create: create}; })(); - var transitions = { - init: {create: 1}, - create: {create: 1} - }; + var transitions = {init: {create: 1}, create: {create: 1}}; function teardown(db, collName, cluster) { var pattern = new RegExp('^' + this.prefix + '\\d+_\\d+$'); diff --git a/jstests/concurrency/fsm_workloads/create_capped_collection_maxdocs.js b/jstests/concurrency/fsm_workloads/create_capped_collection_maxdocs.js index b3a836b8b0b..e29ed65a274 100644 --- a/jstests/concurrency/fsm_workloads/create_capped_collection_maxdocs.js +++ b/jstests/concurrency/fsm_workloads/create_capped_collection_maxdocs.js @@ -10,57 +10,55 @@ load('jstests/concurrency/fsm_libs/extend_workload.js'); // for extendWorkload load('jstests/concurrency/fsm_workloads/create_capped_collection.js'); // for $config -var $config = extendWorkload( - $config, - function($config, $super) { +var $config = extendWorkload($config, function($config, $super) { - // Use the workload name as a prefix for the collection name, - // since the workload name is assumed to be unique. - $config.data.prefix = 'create_capped_collection_maxdocs'; + // Use the workload name as a prefix for the collection name, + // since the workload name is assumed to be unique. + $config.data.prefix = 'create_capped_collection_maxdocs'; - var options = { - capped: true, - size: 8192, // multiple of 256; larger than 4096 default - max: 3 - }; + var options = { + capped: true, + size: 8192, // multiple of 256; larger than 4096 default + max: 3 + }; - function uniqueCollectionName(prefix, tid, num) { - return prefix + tid + '_' + num; - } + function uniqueCollectionName(prefix, tid, num) { + return prefix + tid + '_' + num; + } - // TODO: how to avoid having too many files open? - function create(db, collName) { - var myCollName = uniqueCollectionName(this.prefix, this.tid, this.num++); - assertAlways.commandWorked(db.createCollection(myCollName, options)); + // TODO: how to avoid having too many files open? + function create(db, collName) { + var myCollName = uniqueCollectionName(this.prefix, this.tid, this.num++); + assertAlways.commandWorked(db.createCollection(myCollName, options)); - // Define a small document to be an eighth the size of the capped collection. - var smallDocSize = Math.floor(options.size / 8) - 1; + // Define a small document to be an eighth the size of the capped collection. + var smallDocSize = Math.floor(options.size / 8) - 1; - // Verify size functionality still works as we expect - this.verifySizeTruncation(db, myCollName, options); + // Verify size functionality still works as we expect + this.verifySizeTruncation(db, myCollName, options); - // Insert multiple small documents and verify that at least one truncation has occurred. - // There should never be more than 3 documents in the collection, regardless of the - // storage - // engine. They should always be the most recently inserted documents. + // Insert multiple small documents and verify that at least one truncation has occurred. + // There should never be more than 3 documents in the collection, regardless of the + // storage + // engine. They should always be the most recently inserted documents. - var ids = []; - var count; + var ids = []; + var count; - ids.push(this.insert(db, myCollName, smallDocSize)); - ids.push(this.insert(db, myCollName, smallDocSize)); + ids.push(this.insert(db, myCollName, smallDocSize)); + ids.push(this.insert(db, myCollName, smallDocSize)); - for (var i = 0; i < 50; i++) { - ids.push(this.insert(db, myCollName, smallDocSize)); - count = db[myCollName].find().itcount(); - assertWhenOwnDB.eq(3, count, 'expected truncation to occur due to number of docs'); - assertWhenOwnDB.eq(ids.slice(ids.length - count), - this.getObjectIds(db, myCollName), - 'expected truncation to remove the oldest documents'); - } + for (var i = 0; i < 50; i++) { + ids.push(this.insert(db, myCollName, smallDocSize)); + count = db[myCollName].find().itcount(); + assertWhenOwnDB.eq(3, count, 'expected truncation to occur due to number of docs'); + assertWhenOwnDB.eq(ids.slice(ids.length - count), + this.getObjectIds(db, myCollName), + 'expected truncation to remove the oldest documents'); } + } - $config.states.create = create; + $config.states.create = create; - return $config; - }); + return $config; +}); diff --git a/jstests/concurrency/fsm_workloads/create_collection.js b/jstests/concurrency/fsm_workloads/create_collection.js index fdc6d8af9fd..023c6811f1f 100644 --- a/jstests/concurrency/fsm_workloads/create_collection.js +++ b/jstests/concurrency/fsm_workloads/create_collection.js @@ -32,17 +32,11 @@ var $config = (function() { assertAlways.commandWorked(db.createCollection(myCollName)); } - return { - init: init, - create: create - }; + return {init: init, create: create}; })(); - var transitions = { - init: {create: 1}, - create: {create: 1} - }; + var transitions = {init: {create: 1}, create: {create: 1}}; function teardown(db, collName, cluster) { var pattern = new RegExp('^' + this.prefix + '\\d+_\\d+$'); diff --git a/jstests/concurrency/fsm_workloads/create_index_background.js b/jstests/concurrency/fsm_workloads/create_index_background.js index 046709ebdd3..cfc47156407 100644 --- a/jstests/concurrency/fsm_workloads/create_index_background.js +++ b/jstests/concurrency/fsm_workloads/create_index_background.js @@ -105,8 +105,8 @@ var $config = (function() { for (var i = 0; i < this.nDocumentsToUpdate; ++i) { // Do randomized updates on index x. A document is not guaranteed // to match the randomized 'x' predicate. - res = coll.update({x: Random.randInt(highest), tid: this.tid}, - {$inc: {crud: 1}}); + res = + coll.update({x: Random.randInt(highest), tid: this.tid}, {$inc: {crud: 1}}); assertAlways.writeOK(res); if (db.getMongo().writeMode() === 'commands') { assertWhenOwnColl.contains(res.nModified, [0, 1], tojson(res)); @@ -207,10 +207,8 @@ var $config = (function() { setParameter: 1, internalQueryExecYieldIterations: internalQueryExecYieldIterations })); - assertAlways.commandWorked(db.adminCommand({ - setParameter: 1, - internalQueryExecYieldPeriodMS: internalQueryExecYieldPeriodMS - })); + assertAlways.commandWorked(db.adminCommand( + {setParameter: 1, internalQueryExecYieldPeriodMS: internalQueryExecYieldPeriodMS})); }); } diff --git a/jstests/concurrency/fsm_workloads/distinct.js b/jstests/concurrency/fsm_workloads/distinct.js index c76b5e972f5..c2f519551ce 100644 --- a/jstests/concurrency/fsm_workloads/distinct.js +++ b/jstests/concurrency/fsm_workloads/distinct.js @@ -11,11 +11,7 @@ load('jstests/concurrency/fsm_workload_helpers/drop_utils.js'); // for dropColl var $config = (function() { - var data = { - numDocs: 1000, - prefix: 'distinct_fsm', - shardKey: {i: 1} - }; + var data = {numDocs: 1000, prefix: 'distinct_fsm', shardKey: {i: 1}}; var states = (function() { @@ -35,17 +31,11 @@ var $config = (function() { assertWhenOwnColl.eq(this.numDocs, db[this.threadCollName].distinct('i').length); } - return { - init: init, - distinct: distinct - }; + return {init: init, distinct: distinct}; })(); - var transitions = { - init: {distinct: 1}, - distinct: {distinct: 1} - }; + var transitions = {init: {distinct: 1}, distinct: {distinct: 1}}; function teardown(db, collName, cluster) { var pattern = new RegExp('^' + this.prefix + '_\\d+$'); diff --git a/jstests/concurrency/fsm_workloads/distinct_noindex.js b/jstests/concurrency/fsm_workloads/distinct_noindex.js index b55d1e58d3b..3727c968a14 100644 --- a/jstests/concurrency/fsm_workloads/distinct_noindex.js +++ b/jstests/concurrency/fsm_workloads/distinct_noindex.js @@ -35,24 +35,12 @@ var $config = (function() { assertWhenOwnColl.eq(this.modulus, db[collName].distinct('i', {tid: this.tid}).length); } - return { - init: init, - distinct: distinct - }; + return {init: init, distinct: distinct}; })(); - var transitions = { - init: {distinct: 1}, - distinct: {distinct: 1} - }; + var transitions = {init: {distinct: 1}, distinct: {distinct: 1}}; - return { - data: data, - threadCount: 10, - iterations: 20, - states: states, - transitions: transitions - }; + return {data: data, threadCount: 10, iterations: 20, states: states, transitions: transitions}; })(); diff --git a/jstests/concurrency/fsm_workloads/distinct_projection.js b/jstests/concurrency/fsm_workloads/distinct_projection.js index 3f9c4c3192d..cf287cdb210 100644 --- a/jstests/concurrency/fsm_workloads/distinct_projection.js +++ b/jstests/concurrency/fsm_workloads/distinct_projection.js @@ -10,18 +10,13 @@ load('jstests/concurrency/fsm_libs/extend_workload.js'); // for extendWorkload load('jstests/concurrency/fsm_workloads/distinct.js'); // for $config -var $config = extendWorkload($config, - function($config, $super) { - $config.data.prefix = 'distinct_projection_fsm'; +var $config = extendWorkload($config, function($config, $super) { + $config.data.prefix = 'distinct_projection_fsm'; - $config.states.distinct = function distinct(db, collName) { - var query = { - i: {$lt: this.numDocs / 2} - }; - assertWhenOwnColl.eq( - this.numDocs / 2, - db[this.threadCollName].distinct('i', query).length); - }; + $config.states.distinct = function distinct(db, collName) { + var query = {i: {$lt: this.numDocs / 2}}; + assertWhenOwnColl.eq(this.numDocs / 2, db[this.threadCollName].distinct('i', query).length); + }; - return $config; - }); + return $config; +}); diff --git a/jstests/concurrency/fsm_workloads/drop_collection.js b/jstests/concurrency/fsm_workloads/drop_collection.js index 64a60ef8e79..89952c0a48e 100644 --- a/jstests/concurrency/fsm_workloads/drop_collection.js +++ b/jstests/concurrency/fsm_workloads/drop_collection.js @@ -30,24 +30,12 @@ var $config = (function() { assertAlways(db[myCollName].drop()); } - return { - init: init, - createAndDrop: createAndDrop - }; + return {init: init, createAndDrop: createAndDrop}; })(); - var transitions = { - init: {createAndDrop: 1}, - createAndDrop: {createAndDrop: 1} - }; + var transitions = {init: {createAndDrop: 1}, createAndDrop: {createAndDrop: 1}}; - return { - threadCount: 10, - iterations: 10, - data: data, - states: states, - transitions: transitions - }; + return {threadCount: 10, iterations: 10, data: data, states: states, transitions: transitions}; })(); diff --git a/jstests/concurrency/fsm_workloads/drop_database.js b/jstests/concurrency/fsm_workloads/drop_database.js index 9a6b9e0fb80..9d372d354f8 100644 --- a/jstests/concurrency/fsm_workloads/drop_database.js +++ b/jstests/concurrency/fsm_workloads/drop_database.js @@ -24,10 +24,7 @@ var $config = (function() { } }; - var transitions = { - init: {createAndDrop: 1}, - createAndDrop: {createAndDrop: 1} - }; + var transitions = {init: {createAndDrop: 1}, createAndDrop: {createAndDrop: 1}}; return { threadCount: 10, diff --git a/jstests/concurrency/fsm_workloads/explain.js b/jstests/concurrency/fsm_workloads/explain.js index 983218a7fbf..89dfa530d76 100644 --- a/jstests/concurrency/fsm_workloads/explain.js +++ b/jstests/concurrency/fsm_workloads/explain.js @@ -61,11 +61,7 @@ var $config = (function() { } } - return { - insert: insert, - explain: explain, - explainNonExistentNS: explainNonExistentNS - }; + return {insert: insert, explain: explain, explainNonExistentNS: explainNonExistentNS}; })(); diff --git a/jstests/concurrency/fsm_workloads/explain_aggregate.js b/jstests/concurrency/fsm_workloads/explain_aggregate.js index e0bbccb7683..883ab11c06e 100644 --- a/jstests/concurrency/fsm_workloads/explain_aggregate.js +++ b/jstests/concurrency/fsm_workloads/explain_aggregate.js @@ -9,43 +9,37 @@ load('jstests/concurrency/fsm_libs/extend_workload.js'); // for extendWorkload load('jstests/concurrency/fsm_workloads/explain.js'); // for $config -var $config = extendWorkload( - $config, - function($config, $super) { - - function assertCursorStages(num, obj) { - assertAlways(obj.stages, tojson(obj)); - assertAlways.eq(num, obj.stages.length, tojson(obj.stages)); - assertAlways(obj.stages[0].$cursor, tojson(obj.stages[0])); - assertAlways(obj.stages[0].$cursor.hasOwnProperty('queryPlanner'), - tojson(obj.stages[0].$cursor)); +var $config = extendWorkload($config, function($config, $super) { + + function assertCursorStages(num, obj) { + assertAlways(obj.stages, tojson(obj)); + assertAlways.eq(num, obj.stages.length, tojson(obj.stages)); + assertAlways(obj.stages[0].$cursor, tojson(obj.stages[0])); + assertAlways(obj.stages[0].$cursor.hasOwnProperty('queryPlanner'), + tojson(obj.stages[0].$cursor)); + } + + $config.states = Object.extend({ + explainMatch: function explainMatch(db, collName) { + var res = db[collName].explain().aggregate([{$match: {i: this.nInserted / 2}}]); + assertAlways.commandWorked(res); + + // stages reported: $cursor + assertCursorStages(1, res); + }, + explainMatchProject: function explainMatchProject(db, collName) { + var res = db[collName].explain().aggregate( + [{$match: {i: this.nInserted / 3}}, {$project: {i: 1}}]); + assertAlways.commandWorked(res); + + // stages reported: $cursor, $project + assertCursorStages(2, res); } + }, + $super.states); - $config.states = Object.extend( - { - explainMatch: function explainMatch(db, collName) { - var res = db[collName].explain().aggregate([{$match: {i: this.nInserted / 2}}]); - assertAlways.commandWorked(res); - - // stages reported: $cursor - assertCursorStages(1, res); - }, - explainMatchProject: function explainMatchProject(db, collName) { - var res = - db[collName] - .explain() - .aggregate([{$match: {i: this.nInserted / 3}}, {$project: {i: 1}}]); - assertAlways.commandWorked(res); - - // stages reported: $cursor, $project - assertCursorStages(2, res); - } - }, - $super.states); - - $config.transitions = - Object.extend({explain: $config.data.assignEqualProbsToTransitions($config.states)}, - $super.transitions); - - return $config; - }); + $config.transitions = Object.extend( + {explain: $config.data.assignEqualProbsToTransitions($config.states)}, $super.transitions); + + return $config; +}); diff --git a/jstests/concurrency/fsm_workloads/explain_count.js b/jstests/concurrency/fsm_workloads/explain_count.js index b6a9f0fa8b8..948a108ca10 100644 --- a/jstests/concurrency/fsm_workloads/explain_count.js +++ b/jstests/concurrency/fsm_workloads/explain_count.js @@ -10,59 +10,54 @@ load('jstests/concurrency/fsm_workloads/explain.js'); // for $confi load('jstests/concurrency/fsm_workload_helpers/server_types.js'); // for isMongos load('jstests/libs/analyze_plan.js'); // for planHasStage -var $config = extendWorkload( - $config, - function($config, $super) { +var $config = extendWorkload($config, function($config, $super) { - function assertNCounted(num, obj, db) { - var stage = obj.executionStats.executionStages; - // get sharded stage(s) if counting on mongos - if (isMongos(db)) { - stage = stage.shards[0].executionStages; - } - assertWhenOwnColl.eq(num, stage.nCounted); + function assertNCounted(num, obj, db) { + var stage = obj.executionStats.executionStages; + // get sharded stage(s) if counting on mongos + if (isMongos(db)) { + stage = stage.shards[0].executionStages; } + assertWhenOwnColl.eq(num, stage.nCounted); + } - $config.states = Object.extend( - { - explainBasicCount: function explainBasicCount(db, collName) { - var res = db[collName].explain().count(); - assertAlways.commandWorked(res); - assertAlways(planHasStage(res.queryPlanner.winningPlan, 'COUNT')); - }, - explainCountHint: function explainCountHint(db, collName) { - assertWhenOwnColl(function() { - var res = - db[collName].explain().find({i: this.nInserted / 2}).hint({i: 1}).count(); - assertWhenOwnColl.commandWorked(res); - assertWhenOwnColl(planHasStage(res.queryPlanner.winningPlan, 'COUNT')); - assertWhenOwnColl(planHasStage(res.queryPlanner.winningPlan, 'COUNT_SCAN')); - }); - }, - explainCountNoSkipLimit: function explainCountNoSkipLimit(db, collName) { - var res = db[collName] - .explain('executionStats') - .find({i: this.nInserted}) - .skip(1) - .count(false); - assertAlways.commandWorked(res); - assertNCounted(1, res, db); - }, - explainCountSkipLimit: function explainCountSkipLimit(db, collName) { - var res = db[collName] - .explain('executionStats') - .find({i: this.nInserted}) - .skip(1) - .count(true); - assertAlways.commandWorked(res); - assertNCounted(0, res, db); - } - }, - $super.states); + $config.states = Object.extend({ + explainBasicCount: function explainBasicCount(db, collName) { + var res = db[collName].explain().count(); + assertAlways.commandWorked(res); + assertAlways(planHasStage(res.queryPlanner.winningPlan, 'COUNT')); + }, + explainCountHint: function explainCountHint(db, collName) { + assertWhenOwnColl(function() { + var res = db[collName].explain().find({i: this.nInserted / 2}).hint({i: 1}).count(); + assertWhenOwnColl.commandWorked(res); + assertWhenOwnColl(planHasStage(res.queryPlanner.winningPlan, 'COUNT')); + assertWhenOwnColl(planHasStage(res.queryPlanner.winningPlan, 'COUNT_SCAN')); + }); + }, + explainCountNoSkipLimit: function explainCountNoSkipLimit(db, collName) { + var res = db[collName] + .explain('executionStats') + .find({i: this.nInserted}) + .skip(1) + .count(false); + assertAlways.commandWorked(res); + assertNCounted(1, res, db); + }, + explainCountSkipLimit: function explainCountSkipLimit(db, collName) { + var res = db[collName] + .explain('executionStats') + .find({i: this.nInserted}) + .skip(1) + .count(true); + assertAlways.commandWorked(res); + assertNCounted(0, res, db); + } + }, + $super.states); - $config.transitions = - Object.extend({explain: $config.data.assignEqualProbsToTransitions($config.states)}, - $super.transitions); + $config.transitions = Object.extend( + {explain: $config.data.assignEqualProbsToTransitions($config.states)}, $super.transitions); - return $config; - }); + return $config; +}); diff --git a/jstests/concurrency/fsm_workloads/explain_distinct.js b/jstests/concurrency/fsm_workloads/explain_distinct.js index 86c30f3aca9..1c14254daed 100644 --- a/jstests/concurrency/fsm_workloads/explain_distinct.js +++ b/jstests/concurrency/fsm_workloads/explain_distinct.js @@ -9,28 +9,24 @@ load('jstests/concurrency/fsm_libs/extend_workload.js'); // for extendWorkload load('jstests/concurrency/fsm_workloads/explain.js'); // for $config load('jstests/libs/analyze_plan.js'); // for planHasStage -var $config = extendWorkload( - $config, - function($config, $super) { - $config.states = Object.extend( - { - explainBasicDistinct: function(db, collName) { - var res = db[collName].explain().distinct('i'); - assertAlways.commandWorked(res); - assertAlways(planHasStage(res.queryPlanner.winningPlan, 'COLLSCAN')); - }, - explainDistinctIndex: function(db, collName) { - var res = db[collName].explain().distinct('_id'); - assertAlways.commandWorked(res); - assertAlways(planHasStage(res.queryPlanner.winningPlan, 'PROJECTION')); - assertAlways(planHasStage(res.queryPlanner.winningPlan, 'DISTINCT_SCAN')); - } - }, - $super.states); +var $config = extendWorkload($config, function($config, $super) { + $config.states = Object.extend({ + explainBasicDistinct: function(db, collName) { + var res = db[collName].explain().distinct('i'); + assertAlways.commandWorked(res); + assertAlways(planHasStage(res.queryPlanner.winningPlan, 'COLLSCAN')); + }, + explainDistinctIndex: function(db, collName) { + var res = db[collName].explain().distinct('_id'); + assertAlways.commandWorked(res); + assertAlways(planHasStage(res.queryPlanner.winningPlan, 'PROJECTION')); + assertAlways(planHasStage(res.queryPlanner.winningPlan, 'DISTINCT_SCAN')); + } + }, + $super.states); - $config.transitions = - Object.extend({explain: $config.data.assignEqualProbsToTransitions($config.states)}, - $super.transitions); + $config.transitions = Object.extend( + {explain: $config.data.assignEqualProbsToTransitions($config.states)}, $super.transitions); - return $config; - }); + return $config; +}); diff --git a/jstests/concurrency/fsm_workloads/explain_find.js b/jstests/concurrency/fsm_workloads/explain_find.js index f0b6f099c63..e338b00e516 100644 --- a/jstests/concurrency/fsm_workloads/explain_find.js +++ b/jstests/concurrency/fsm_workloads/explain_find.js @@ -10,62 +10,57 @@ load('jstests/concurrency/fsm_libs/extend_workload.js'); // for extendWorkload load('jstests/concurrency/fsm_workloads/explain.js'); // for $config load('jstests/libs/analyze_plan.js'); // for planHasStage and isIxscan -var $config = extendWorkload( - $config, - function($config, $super) { +var $config = extendWorkload($config, function($config, $super) { - $config.states = Object.extend( - { - explainLimit: function explainLimit(db, collName) { - var res = db[collName].find().limit(3).explain(); - assertAlways.commandWorked(res); - assertAlways(planHasStage(res.queryPlanner.winningPlan, 'LIMIT')); - }, - explainBatchSize: function explainBatchSize(db, collName) { - var res = db[collName].find().batchSize(3).explain(); - assertAlways.commandWorked(res); - }, - explainAddOption: function explainAddOption(db, collName) { - var res = - db[collName].explain().find().addOption(DBQuery.Option.exhaust).finish(); - assertAlways.commandWorked(res); - }, - explainSkip: function explainSkip(db, collName) { - var res = db[collName].explain().find().skip(3).finish(); - assertAlways.commandWorked(res); - assertAlways(planHasStage(res.queryPlanner.winningPlan, 'SKIP')); - }, - explainSort: function explainSort(db, collName) { - var res = db[collName].find().sort({i: -1}).explain(); - assertAlways.commandWorked(res); - assertAlways(planHasStage(res.queryPlanner.winningPlan, 'SORT')); - }, - explainHint: function explainHint(db, collName) { - assertWhenOwnColl(function() { - var res = db[collName].find().hint({j: 1}).explain(); - assertWhenOwnColl.commandWorked(res); - assertWhenOwnColl(isIxscan(res.queryPlanner.winningPlan)); - }); - }, - explainMaxTimeMS: function explainMaxTimeMS(db, collName) { - var res = db[collName].find().maxTimeMS(2000).explain(); - assertAlways.commandWorked(res); - }, - explainSnapshot: function explainSnapshot(db, collName) { - var res = db[collName].find().snapshot().explain(); - assertAlways.commandWorked(res); - assertWhenOwnColl(isIxscan(res.queryPlanner.winningPlan)); - } - }, - $super.states); + $config.states = Object.extend({ + explainLimit: function explainLimit(db, collName) { + var res = db[collName].find().limit(3).explain(); + assertAlways.commandWorked(res); + assertAlways(planHasStage(res.queryPlanner.winningPlan, 'LIMIT')); + }, + explainBatchSize: function explainBatchSize(db, collName) { + var res = db[collName].find().batchSize(3).explain(); + assertAlways.commandWorked(res); + }, + explainAddOption: function explainAddOption(db, collName) { + var res = db[collName].explain().find().addOption(DBQuery.Option.exhaust).finish(); + assertAlways.commandWorked(res); + }, + explainSkip: function explainSkip(db, collName) { + var res = db[collName].explain().find().skip(3).finish(); + assertAlways.commandWorked(res); + assertAlways(planHasStage(res.queryPlanner.winningPlan, 'SKIP')); + }, + explainSort: function explainSort(db, collName) { + var res = db[collName].find().sort({i: -1}).explain(); + assertAlways.commandWorked(res); + assertAlways(planHasStage(res.queryPlanner.winningPlan, 'SORT')); + }, + explainHint: function explainHint(db, collName) { + assertWhenOwnColl(function() { + var res = db[collName].find().hint({j: 1}).explain(); + assertWhenOwnColl.commandWorked(res); + assertWhenOwnColl(isIxscan(res.queryPlanner.winningPlan)); + }); + }, + explainMaxTimeMS: function explainMaxTimeMS(db, collName) { + var res = db[collName].find().maxTimeMS(2000).explain(); + assertAlways.commandWorked(res); + }, + explainSnapshot: function explainSnapshot(db, collName) { + var res = db[collName].find().snapshot().explain(); + assertAlways.commandWorked(res); + assertWhenOwnColl(isIxscan(res.queryPlanner.winningPlan)); + } + }, + $super.states); - $config.transitions = - Object.extend({explain: $config.data.assignEqualProbsToTransitions($config.states)}, - $super.transitions); + $config.transitions = Object.extend( + {explain: $config.data.assignEqualProbsToTransitions($config.states)}, $super.transitions); - // doubling number of iterations so there is a higher chance we will - // transition to each of the 8 new states at least once - $config.iterations = $super.iterations * 2; + // doubling number of iterations so there is a higher chance we will + // transition to each of the 8 new states at least once + $config.iterations = $super.iterations * 2; - return $config; - }); + return $config; +}); diff --git a/jstests/concurrency/fsm_workloads/explain_group.js b/jstests/concurrency/fsm_workloads/explain_group.js index f379bf4e608..99e0a0c1266 100644 --- a/jstests/concurrency/fsm_workloads/explain_group.js +++ b/jstests/concurrency/fsm_workloads/explain_group.js @@ -10,23 +10,19 @@ load('jstests/concurrency/fsm_libs/extend_workload.js'); // for extendWorkload load('jstests/concurrency/fsm_workloads/explain.js'); // for $config load('jstests/libs/analyze_plan.js'); // for planHasStage -var $config = - extendWorkload($config, - function($config, $super) { +var $config = extendWorkload($config, function($config, $super) { - $config.states = Object.extend( - { - explainBasicGroup: function explainBasicGroup(db, collName) { - var res = db[collName].explain().group( - {key: {i: 1}, initial: {}, reduce: function() {}}); - assertAlways.commandWorked(res); - } - }, - $super.states); + $config.states = Object.extend({ + explainBasicGroup: function explainBasicGroup(db, collName) { + var res = + db[collName].explain().group({key: {i: 1}, initial: {}, reduce: function() {}}); + assertAlways.commandWorked(res); + } + }, + $super.states); - $config.transitions = Object.extend( - {explain: $config.data.assignEqualProbsToTransitions($config.states)}, - $super.transitions); + $config.transitions = Object.extend( + {explain: $config.data.assignEqualProbsToTransitions($config.states)}, $super.transitions); - return $config; - }); + return $config; +}); diff --git a/jstests/concurrency/fsm_workloads/explain_remove.js b/jstests/concurrency/fsm_workloads/explain_remove.js index c5c05a9af69..173f9b44623 100644 --- a/jstests/concurrency/fsm_workloads/explain_remove.js +++ b/jstests/concurrency/fsm_workloads/explain_remove.js @@ -8,42 +8,37 @@ load('jstests/concurrency/fsm_libs/extend_workload.js'); // for extendWorkload load('jstests/concurrency/fsm_workloads/explain.js'); // for $config -var $config = extendWorkload( - $config, - function($config, $super) { +var $config = extendWorkload($config, function($config, $super) { - $config.states = Object.extend( - { - explainSingleRemove: function explainSingleRemove(db, collName) { - var res = db[collName] - .explain('executionStats') - .remove({i: this.nInserted}, /* justOne */ true); - assertAlways.commandWorked(res); - assertWhenOwnColl(function() { - assertWhenOwnColl.eq(1, res.executionStats.totalDocsExamined); + $config.states = Object.extend({ + explainSingleRemove: function explainSingleRemove(db, collName) { + var res = db[collName] + .explain('executionStats') + .remove({i: this.nInserted}, /* justOne */ true); + assertAlways.commandWorked(res); + assertWhenOwnColl(function() { + assertWhenOwnColl.eq(1, res.executionStats.totalDocsExamined); - // the document should not have been deleted. - assertWhenOwnColl.eq(1, db[collName].find({i: this.nInserted}).itcount()); - }.bind(this)); - }, - explainMultiRemove: function explainMultiRemove(db, collName) { - var res = db[collName] - .explain('executionStats') - .remove({i: {$lte: this.nInserted / 2}}); - assertAlways.commandWorked(res); - assertWhenOwnColl(function() { - assertWhenOwnColl.eq(this.nInserted / 2 + 1, - explain.executionStats.totalDocsExamined); - // no documents should have been deleted - assertWhenOwnColl.eq(this.nInserted, db[collName].itcount()); - }.bind(this)); - } - }, - $super.states); + // the document should not have been deleted. + assertWhenOwnColl.eq(1, db[collName].find({i: this.nInserted}).itcount()); + }.bind(this)); + }, + explainMultiRemove: function explainMultiRemove(db, collName) { + var res = + db[collName].explain('executionStats').remove({i: {$lte: this.nInserted / 2}}); + assertAlways.commandWorked(res); + assertWhenOwnColl(function() { + assertWhenOwnColl.eq(this.nInserted / 2 + 1, + explain.executionStats.totalDocsExamined); + // no documents should have been deleted + assertWhenOwnColl.eq(this.nInserted, db[collName].itcount()); + }.bind(this)); + } + }, + $super.states); - $config.transitions = - Object.extend({explain: $config.data.assignEqualProbsToTransitions($config.states)}, - $super.transitions); + $config.transitions = Object.extend( + {explain: $config.data.assignEqualProbsToTransitions($config.states)}, $super.transitions); - return $config; - }); + return $config; +}); diff --git a/jstests/concurrency/fsm_workloads/explain_update.js b/jstests/concurrency/fsm_workloads/explain_update.js index e63f5948fef..787ccdf7e4b 100644 --- a/jstests/concurrency/fsm_workloads/explain_update.js +++ b/jstests/concurrency/fsm_workloads/explain_update.js @@ -9,69 +9,64 @@ load('jstests/concurrency/fsm_libs/extend_workload.js'); // for extend load('jstests/concurrency/fsm_workloads/explain.js'); // for $config load('jstests/concurrency/fsm_workload_helpers/server_types.js'); // for isMongos -var $config = extendWorkload( - $config, - function($config, $super) { +var $config = extendWorkload($config, function($config, $super) { - $config.states = Object.extend( - { - explainBasicUpdate: function explainBasicUpdate(db, collName) { - var res = db[collName] - .explain('executionStats') - .update({i: this.nInserted}, {$set: {j: 49}}); - assertAlways.commandWorked(res); - assertWhenOwnColl(function() { - assertWhenOwnColl.eq(1, explain.executionStats.totalDocsExamined); + $config.states = Object.extend({ + explainBasicUpdate: function explainBasicUpdate(db, collName) { + var res = + db[collName].explain('executionStats').update({i: this.nInserted}, {$set: {j: 49}}); + assertAlways.commandWorked(res); + assertWhenOwnColl(function() { + assertWhenOwnColl.eq(1, explain.executionStats.totalDocsExamined); - // document should not have been updated. - var doc = db[collName].findOne({i: this.nInserted}); - assertWhenOwnColl.eq(2 * this.nInserted, doc.j); - }.bind(this)); - }, - explainUpdateUpsert: function explainUpdateUpsert(db, collName) { - var res = db[collName] - .explain('executionStats') - .update({i: 2 * this.nInserted + 1}, - {$set: {j: 81}}, - /* upsert */ true); - assertAlways.commandWorked(res); - var stage = res.executionStats.executionStages; + // document should not have been updated. + var doc = db[collName].findOne({i: this.nInserted}); + assertWhenOwnColl.eq(2 * this.nInserted, doc.j); + }.bind(this)); + }, + explainUpdateUpsert: function explainUpdateUpsert(db, collName) { + var res = db[collName] + .explain('executionStats') + .update({i: 2 * this.nInserted + 1}, + {$set: {j: 81}}, + /* upsert */ true); + assertAlways.commandWorked(res); + var stage = res.executionStats.executionStages; - // if explaining a write command through mongos - if (isMongos(db)) { - stage = stage.shards[0].executionStages; - } - assertAlways.eq(stage.stage, 'UPDATE'); - assertWhenOwnColl(stage.wouldInsert); + // if explaining a write command through mongos + if (isMongos(db)) { + stage = stage.shards[0].executionStages; + } + assertAlways.eq(stage.stage, 'UPDATE'); + assertWhenOwnColl(stage.wouldInsert); - // make sure that the insert didn't actually happen. - assertWhenOwnColl.eq(this.nInserted, db[collName].find().itcount()); - }, - explainUpdateMulti: function explainUpdateMulti(db, collName) { - var res = db[collName] - .explain('executionStats') - .update({i: {$lte: 2}}, - {$set: {b: 3}}, - /* upsert */ false, - /* multi */ true); - assertAlways.commandWorked(res); - var stage = res.executionStats.executionStages; + // make sure that the insert didn't actually happen. + assertWhenOwnColl.eq(this.nInserted, db[collName].find().itcount()); + }, + explainUpdateMulti: function explainUpdateMulti(db, collName) { + var res = db[collName] + .explain('executionStats') + .update({i: {$lte: 2}}, + {$set: {b: 3}}, + /* upsert */ false, + /* multi */ true); + assertAlways.commandWorked(res); + var stage = res.executionStats.executionStages; - // if explaining a write command through mongos - if (isMongos(db)) { - stage = stage.shards[0].executionStages; - } - assertAlways.eq(stage.stage, 'UPDATE'); - assertWhenOwnColl(!stage.wouldInsert); - assertWhenOwnColl.eq(3, stage.nMatched); - assertWhenOwnColl.eq(3, stage.nWouldModify); - } - }, - $super.states); + // if explaining a write command through mongos + if (isMongos(db)) { + stage = stage.shards[0].executionStages; + } + assertAlways.eq(stage.stage, 'UPDATE'); + assertWhenOwnColl(!stage.wouldInsert); + assertWhenOwnColl.eq(3, stage.nMatched); + assertWhenOwnColl.eq(3, stage.nWouldModify); + } + }, + $super.states); - $config.transitions = - Object.extend({explain: $config.data.assignEqualProbsToTransitions($config.states)}, - $super.transitions); + $config.transitions = Object.extend( + {explain: $config.data.assignEqualProbsToTransitions($config.states)}, $super.transitions); - return $config; - }); + return $config; +}); diff --git a/jstests/concurrency/fsm_workloads/findAndModify_inc.js b/jstests/concurrency/fsm_workloads/findAndModify_inc.js index 5c5d55b55b8..5a8b63392a8 100644 --- a/jstests/concurrency/fsm_workloads/findAndModify_inc.js +++ b/jstests/concurrency/fsm_workloads/findAndModify_inc.js @@ -24,9 +24,7 @@ var $config = (function() { }, update: function update(db, collName) { - var updateDoc = { - $inc: {} - }; + var updateDoc = {$inc: {}}; updateDoc.$inc[this.fieldName] = 1; var res = db.runCommand( @@ -64,11 +62,7 @@ var $config = (function() { }; - var transitions = { - init: {update: 1}, - update: {find: 1}, - find: {update: 1} - }; + var transitions = {init: {update: 1}, update: {find: 1}, find: {update: 1}}; function setup(db, collName, cluster) { db[collName].insert({_id: 'findAndModify_inc'}); diff --git a/jstests/concurrency/fsm_workloads/findAndModify_mixed_queue_unindexed.js b/jstests/concurrency/fsm_workloads/findAndModify_mixed_queue_unindexed.js index 11ac81d63fd..19cd191b1aa 100644 --- a/jstests/concurrency/fsm_workloads/findAndModify_mixed_queue_unindexed.js +++ b/jstests/concurrency/fsm_workloads/findAndModify_mixed_queue_unindexed.js @@ -21,79 +21,73 @@ load('jstests/concurrency/fsm_workloads/findAndModify_remove_queue.js'); // for // For isMongod and supportsDocumentLevelConcurrency. load('jstests/concurrency/fsm_workload_helpers/server_types.js'); -var $config = extendWorkload( - $config, - function($config, $super) { +var $config = extendWorkload($config, function($config, $super) { - // Use the workload name as the database name, since the workload name is assumed to be - // unique. - $config.data.uniqueDBName = 'findAndModify_mixed_queue_unindexed'; + // Use the workload name as the database name, since the workload name is assumed to be + // unique. + $config.data.uniqueDBName = 'findAndModify_mixed_queue_unindexed'; - $config.data.newDocForInsert = function newDocForInsert(i) { - return { - _id: i, - rand: Random.rand(), - counter: 0 - }; - }; + $config.data.newDocForInsert = function newDocForInsert(i) { + return {_id: i, rand: Random.rand(), counter: 0}; + }; - $config.data.getIndexSpecs = function getIndexSpecs() { - return []; - }; + $config.data.getIndexSpecs = function getIndexSpecs() { + return []; + }; - $config.data.opName = 'modified'; + $config.data.opName = 'modified'; - $config.data.validateResult = function validateResult(db, collName, res) { - assertAlways.commandWorked(res); + $config.data.validateResult = function validateResult(db, collName, res) { + assertAlways.commandWorked(res); - var doc = res.value; - if (isMongod(db) && supportsDocumentLevelConcurrency(db)) { - // Storage engines which do not support document-level concurrency will not - // automatically retry if there was a conflict, so it is expected that it may return - // null in the case of a conflict. All other storage engines should automatically - // retry the operation, and thus should never return null. - assertWhenOwnColl.neq( - doc, null, 'findAndModify should have found a matching document'); - } - if (doc !== null) { - this.saveDocId(db, collName, doc._id); - } - }; + var doc = res.value; + if (isMongod(db) && supportsDocumentLevelConcurrency(db)) { + // Storage engines which do not support document-level concurrency will not + // automatically retry if there was a conflict, so it is expected that it may return + // null in the case of a conflict. All other storage engines should automatically + // retry the operation, and thus should never return null. + assertWhenOwnColl.neq(doc, null, 'findAndModify should have found a matching document'); + } + if (doc !== null) { + this.saveDocId(db, collName, doc._id); + } + }; - $config.states = (function() { - // Avoid removing documents that were already updated. - function remove(db, collName) { - var res = db.runCommand({ - findAndModify: db[collName].getName(), - query: {counter: 0}, - sort: {rand: -1}, - remove: true - }); - this.validateResult(db, collName, res); - } + $config.states = (function() { + // Avoid removing documents that were already updated. + function remove(db, collName) { + var res = db.runCommand({ + findAndModify: db[collName].getName(), + query: {counter: 0}, + sort: {rand: -1}, + remove: true + }); + this.validateResult(db, collName, res); + } - function update(db, collName) { - // Update the counter field to avoid matching the same document again. - var res = db.runCommand({ - findAndModify: db[collName].getName(), - query: {counter: 0}, - sort: {rand: -1}, - update: {$inc: {counter: 1}}, new: false - }); - this.validateResult(db, collName, res); - } + function update(db, collName) { + // Update the counter field to avoid matching the same document again. + var res = db.runCommand({ + findAndModify: db[collName].getName(), + query: {counter: 0}, + sort: {rand: -1}, + update: {$inc: {counter: 1}}, + new: false + }); + this.validateResult(db, collName, res); + } - return { - remove: remove, - update: update, - }; + return { + remove: remove, + update: update, + }; - })(); + })(); - $config.transitions = { - remove: {remove: 0.5, update: 0.5}, - update: {remove: 0.5, update: 0.5}, - }; + $config.transitions = { + remove: {remove: 0.5, update: 0.5}, + update: {remove: 0.5, update: 0.5}, + }; - return $config; - }); + return $config; +}); diff --git a/jstests/concurrency/fsm_workloads/findAndModify_remove.js b/jstests/concurrency/fsm_workloads/findAndModify_remove.js index b33e67b2e01..b4a32a3cc74 100644 --- a/jstests/concurrency/fsm_workloads/findAndModify_remove.js +++ b/jstests/concurrency/fsm_workloads/findAndModify_remove.js @@ -8,9 +8,7 @@ */ var $config = (function() { - var data = { - shardKey: {tid: 1} - }; + var data = {shardKey: {tid: 1}}; var states = (function() { @@ -42,24 +40,12 @@ var $config = (function() { this.iter++; } - return { - init: init, - insertAndRemove: insertAndRemove - }; + return {init: init, insertAndRemove: insertAndRemove}; })(); - var transitions = { - init: {insertAndRemove: 1}, - insertAndRemove: {insertAndRemove: 1} - }; + var transitions = {init: {insertAndRemove: 1}, insertAndRemove: {insertAndRemove: 1}}; - return { - threadCount: 20, - iterations: 20, - data: data, - states: states, - transitions: transitions - }; + return {threadCount: 20, iterations: 20, data: data, states: states, transitions: transitions}; })(); diff --git a/jstests/concurrency/fsm_workloads/findAndModify_remove_queue.js b/jstests/concurrency/fsm_workloads/findAndModify_remove_queue.js index 3a330529e0c..9b945468cf5 100644 --- a/jstests/concurrency/fsm_workloads/findAndModify_remove_queue.js +++ b/jstests/concurrency/fsm_workloads/findAndModify_remove_queue.js @@ -22,10 +22,7 @@ var $config = (function() { uniqueDBName: 'findAndModify_remove_queue', newDocForInsert: function newDocForInsert(i) { - return { - _id: i, - rand: Random.rand() - }; + return {_id: i, rand: Random.rand()}; }, getIndexSpecs: function getIndexSpecs() { @@ -38,9 +35,7 @@ var $config = (function() { // Use a separate database to avoid conflicts with other FSM workloads. var ownedDB = db.getSiblingDB(db.getName() + this.uniqueDBName); - var updateDoc = { - $push: {} - }; + var updateDoc = {$push: {}}; updateDoc.$push[this.opName] = id; var res = ownedDB[collName].update({_id: this.tid}, updateDoc, {upsert: true}); @@ -64,12 +59,8 @@ var $config = (function() { var states = (function() { function remove(db, collName) { - var res = db.runCommand({ - findAndModify: db[collName].getName(), - query: {}, - sort: {rand: -1}, - remove: true - }); + var res = db.runCommand( + {findAndModify: db[collName].getName(), query: {}, sort: {rand: -1}, remove: true}); assertAlways.commandWorked(res); var doc = res.value; @@ -86,15 +77,11 @@ var $config = (function() { } } - return { - remove: remove - }; + return {remove: remove}; })(); - var transitions = { - remove: {remove: 1} - }; + var transitions = {remove: {remove: 1}}; function setup(db, collName, cluster) { // Each thread should remove exactly one document per iteration. @@ -193,10 +180,7 @@ var $config = (function() { if (!smallestValueIsSet) { return null; } - return { - value: smallestValue, - indices: smallestIndices - }; + return {value: smallestValue, indices: smallestIndices}; } } diff --git a/jstests/concurrency/fsm_workloads/findAndModify_remove_queue_unindexed.js b/jstests/concurrency/fsm_workloads/findAndModify_remove_queue_unindexed.js index 80ce7567a7d..387c5467f04 100644 --- a/jstests/concurrency/fsm_workloads/findAndModify_remove_queue_unindexed.js +++ b/jstests/concurrency/fsm_workloads/findAndModify_remove_queue_unindexed.js @@ -16,16 +16,15 @@ load('jstests/concurrency/fsm_libs/extend_workload.js'); // for extendWorkload load('jstests/concurrency/fsm_workloads/findAndModify_remove_queue.js'); // for $config -var $config = extendWorkload($config, - function($config, $super) { +var $config = extendWorkload($config, function($config, $super) { - // Use the workload name as the database name, since the workload - // name is assumed to be unique. - $config.data.uniqueDBName = 'findAndModify_remove_queue_unindexed'; + // Use the workload name as the database name, since the workload + // name is assumed to be unique. + $config.data.uniqueDBName = 'findAndModify_remove_queue_unindexed'; - $config.data.getIndexSpecs = function getIndexSpecs() { - return []; - }; + $config.data.getIndexSpecs = function getIndexSpecs() { + return []; + }; - return $config; - }); + return $config; +}); diff --git a/jstests/concurrency/fsm_workloads/findAndModify_update.js b/jstests/concurrency/fsm_workloads/findAndModify_update.js index c794c755ed9..16aa80b8a33 100644 --- a/jstests/concurrency/fsm_workloads/findAndModify_update.js +++ b/jstests/concurrency/fsm_workloads/findAndModify_update.js @@ -18,11 +18,7 @@ var $config = (function() { var states = (function() { function makeDoc(tid) { - return { - _id: new ObjectId(), - tid: tid, - value: 0 - }; + return {_id: new ObjectId(), tid: tid, value: 0}; } function init(db, collName) { @@ -40,7 +36,8 @@ var $config = (function() { findandmodify: db[collName].getName(), query: {tid: this.tid}, sort: {value: 1}, - update: {$max: {value: updatedValue}}, new: true + update: {$max: {value: updatedValue}}, + new: true }); assertAlways.commandWorked(res); @@ -60,7 +57,8 @@ var $config = (function() { findandmodify: db[collName].getName(), query: {tid: this.tid}, sort: {value: -1}, - update: {$min: {value: updatedValue}}, new: true + update: {$min: {value: updatedValue}}, + new: true }); assertAlways.commandWorked(res); diff --git a/jstests/concurrency/fsm_workloads/findAndModify_update_collscan.js b/jstests/concurrency/fsm_workloads/findAndModify_update_collscan.js index f9e40b6b467..d1c8134bd39 100644 --- a/jstests/concurrency/fsm_workloads/findAndModify_update_collscan.js +++ b/jstests/concurrency/fsm_workloads/findAndModify_update_collscan.js @@ -13,16 +13,15 @@ load('jstests/concurrency/fsm_libs/extend_workload.js'); // for extendWorkload load('jstests/concurrency/fsm_workloads/findAndModify_update.js'); // for $config -var $config = extendWorkload($config, - function($config, $super) { +var $config = extendWorkload($config, function($config, $super) { - // Do not create the { tid: 1, value: 1 } index so that a - // collection - // scan is performed for the query and sort operations. - $config.setup = function setup(db, collName, cluster) {}; + // Do not create the { tid: 1, value: 1 } index so that a + // collection + // scan is performed for the query and sort operations. + $config.setup = function setup(db, collName, cluster) {}; - // Remove the shardKey so that a collection scan is performed - delete $config.data.shardKey; + // Remove the shardKey so that a collection scan is performed + delete $config.data.shardKey; - return $config; - }); + return $config; +}); diff --git a/jstests/concurrency/fsm_workloads/findAndModify_update_grow.js b/jstests/concurrency/fsm_workloads/findAndModify_update_grow.js index 277b2882700..7c32f6aefec 100644 --- a/jstests/concurrency/fsm_workloads/findAndModify_update_grow.js +++ b/jstests/concurrency/fsm_workloads/findAndModify_update_grow.js @@ -30,11 +30,7 @@ var $config = (function() { function makeDoc(tid) { // Use 32-bit integer for representing 'length' property // to ensure $mul does integer multiplication - var doc = { - _id: new ObjectId(), - tid: tid, - length: new NumberInt(1) - }; + var doc = {_id: new ObjectId(), tid: tid, length: new NumberInt(1)}; doc[uniqueFieldName] = makeStringOfLength(doc.length); return doc; } @@ -70,17 +66,15 @@ var $config = (function() { var updatedLength = factor * this.length; var updatedValue = makeStringOfLength(updatedLength); - var update = { - $set: {}, - $mul: {length: factor} - }; + var update = {$set: {}, $mul: {length: factor}}; update.$set[uniqueFieldName] = updatedValue; var res = db.runCommand({ findandmodify: db[collName].getName(), query: {tid: this.tid}, sort: {length: 1}, // fetch document of smallest size - update: update, new: true + update: update, + new: true }); assertAlways.commandWorked(res); @@ -117,10 +111,7 @@ var $config = (function() { })(); - var transitions = { - insert: {findAndModify: 1}, - findAndModify: {findAndModify: 1} - }; + var transitions = {insert: {findAndModify: 1}, findAndModify: {findAndModify: 1}}; return { threadCount: 20, diff --git a/jstests/concurrency/fsm_workloads/findAndModify_update_queue.js b/jstests/concurrency/fsm_workloads/findAndModify_update_queue.js index 104b299b317..1d82f4b7eb2 100644 --- a/jstests/concurrency/fsm_workloads/findAndModify_update_queue.js +++ b/jstests/concurrency/fsm_workloads/findAndModify_update_queue.js @@ -17,69 +17,58 @@ load('jstests/concurrency/fsm_workloads/findAndModify_remove_queue.js'); // for // For isMongod and supportsDocumentLevelConcurrency. load('jstests/concurrency/fsm_workload_helpers/server_types.js'); -var $config = extendWorkload( - $config, - function($config, $super) { +var $config = extendWorkload($config, function($config, $super) { - // Use the workload name as the database name, since the workload name is assumed to be - // unique. - $config.data.uniqueDBName = 'findAndModify_update_queue'; + // Use the workload name as the database name, since the workload name is assumed to be + // unique. + $config.data.uniqueDBName = 'findAndModify_update_queue'; - $config.data.newDocForInsert = function newDocForInsert(i) { - return { - _id: i, - rand: Random.rand(), - counter: 0 - }; - }; + $config.data.newDocForInsert = function newDocForInsert(i) { + return {_id: i, rand: Random.rand(), counter: 0}; + }; - $config.data.getIndexSpecs = function getIndexSpecs() { - return [{counter: 1, rand: -1}]; - }; + $config.data.getIndexSpecs = function getIndexSpecs() { + return [{counter: 1, rand: -1}]; + }; - $config.data.opName = 'updated'; + $config.data.opName = 'updated'; - var states = (function() { + var states = (function() { - function update(db, collName) { - // Update the counter field to avoid matching the same document again. - var res = db.runCommand({ - findAndModify: db[collName].getName(), - query: {counter: 0}, - sort: {rand: -1}, - update: {$inc: {counter: 1}}, new: false - }); - assertAlways.commandWorked(res); + function update(db, collName) { + // Update the counter field to avoid matching the same document again. + var res = db.runCommand({ + findAndModify: db[collName].getName(), + query: {counter: 0}, + sort: {rand: -1}, + update: {$inc: {counter: 1}}, + new: false + }); + assertAlways.commandWorked(res); - var doc = res.value; - if (isMongod(db) && supportsDocumentLevelConcurrency(db)) { - // Storage engines which do not support document-level concurrency will not - // automatically retry if there was a conflict, so it is expected that it may - // return null in the case of a conflict. All other storage engines should - // automatically retry the operation, and thus should never return null. - assertWhenOwnColl.neq( - doc, - null, - 'findAndModify should have found and updated a matching document'); - } - if (doc !== null) { - this.saveDocId(db, collName, doc._id); - } + var doc = res.value; + if (isMongod(db) && supportsDocumentLevelConcurrency(db)) { + // Storage engines which do not support document-level concurrency will not + // automatically retry if there was a conflict, so it is expected that it may + // return null in the case of a conflict. All other storage engines should + // automatically retry the operation, and thus should never return null. + assertWhenOwnColl.neq( + doc, null, 'findAndModify should have found and updated a matching document'); } + if (doc !== null) { + this.saveDocId(db, collName, doc._id); + } + } - return { - update: update - }; + return {update: update}; - })(); + })(); - var transitions = { - update: {update: 1} - }; + var transitions = {update: {update: 1}}; - $config.startState = 'update'; - $config.states = states; - $config.transitions = transitions; + $config.startState = 'update'; + $config.states = states; + $config.transitions = transitions; - return $config; - }); + return $config; +}); diff --git a/jstests/concurrency/fsm_workloads/findAndModify_update_queue_unindexed.js b/jstests/concurrency/fsm_workloads/findAndModify_update_queue_unindexed.js index c6561829b26..cda9a494a61 100644 --- a/jstests/concurrency/fsm_workloads/findAndModify_update_queue_unindexed.js +++ b/jstests/concurrency/fsm_workloads/findAndModify_update_queue_unindexed.js @@ -16,16 +16,15 @@ load('jstests/concurrency/fsm_libs/extend_workload.js'); // for extendWorkload load('jstests/concurrency/fsm_workloads/findAndModify_update_queue.js'); // for $config -var $config = extendWorkload($config, - function($config, $super) { +var $config = extendWorkload($config, function($config, $super) { - // Use the workload name as the database name, since the workload - // name is assumed to be unique. - $config.data.uniqueDBName = 'findAndModify_update_queue_unindexed'; + // Use the workload name as the database name, since the workload + // name is assumed to be unique. + $config.data.uniqueDBName = 'findAndModify_update_queue_unindexed'; - $config.data.getIndexSpecs = function getIndexSpecs() { - return []; - }; + $config.data.getIndexSpecs = function getIndexSpecs() { + return []; + }; - return $config; - }); + return $config; +}); diff --git a/jstests/concurrency/fsm_workloads/findAndModify_upsert.js b/jstests/concurrency/fsm_workloads/findAndModify_upsert.js index 499e8324cae..e79b5322bc4 100644 --- a/jstests/concurrency/fsm_workloads/findAndModify_upsert.js +++ b/jstests/concurrency/fsm_workloads/findAndModify_upsert.js @@ -10,10 +10,7 @@ */ var $config = (function() { - var data = { - sort: false, - shardKey: {tid: 1} - }; + var data = {sort: false, shardKey: {tid: 1}}; var states = (function() { @@ -41,15 +38,13 @@ var $config = (function() { var updatedValue = this.iter++; // Use a query specification that does not match any existing documents - var query = { - _id: new ObjectId(), - tid: this.tid - }; + var query = {_id: new ObjectId(), tid: this.tid}; var cmdObj = { findandmodify: db[collName].getName(), query: query, - update: {$setOnInsert: {values: [updatedValue]}}, new: true, + update: {$setOnInsert: {values: [updatedValue]}}, + new: true, upsert: true }; @@ -64,11 +59,12 @@ var $config = (function() { assertAlways(doc !== null, 'a document should have been inserted'); assertAlways((function() { - assertAlways.eq(this.tid, doc.tid); - assertAlways(Array.isArray(doc.values), 'expected values to be an array'); - assertAlways.eq(1, doc.values.length); - assertAlways.eq(updatedValue, doc.values[0]); - }).bind(this)); + assertAlways.eq(this.tid, doc.tid); + assertAlways(Array.isArray(doc.values), + 'expected values to be an array'); + assertAlways.eq(1, doc.values.length); + assertAlways.eq(updatedValue, doc.values[0]); + }).bind(this)); } function update(db, collName) { @@ -77,7 +73,8 @@ var $config = (function() { var cmdObj = { findandmodify: db[collName].getName(), query: {tid: this.tid}, - update: {$push: {values: updatedValue}}, new: true, + update: {$push: {values: updatedValue}}, + new: true, upsert: false }; @@ -103,11 +100,7 @@ var $config = (function() { } } - return { - init: init, - upsert: upsert, - update: update - }; + return {init: init, upsert: upsert, update: update}; })(); @@ -117,12 +110,6 @@ var $config = (function() { update: {upsert: 0.1, update: 0.9} }; - return { - threadCount: 20, - iterations: 20, - data: data, - states: states, - transitions: transitions - }; + return {threadCount: 20, iterations: 20, data: data, states: states, transitions: transitions}; })(); diff --git a/jstests/concurrency/fsm_workloads/findAndModify_upsert_collscan.js b/jstests/concurrency/fsm_workloads/findAndModify_upsert_collscan.js index aad1fbc644c..8751e99fd21 100644 --- a/jstests/concurrency/fsm_workloads/findAndModify_upsert_collscan.js +++ b/jstests/concurrency/fsm_workloads/findAndModify_upsert_collscan.js @@ -13,12 +13,9 @@ load('jstests/concurrency/fsm_libs/extend_workload.js'); // for extendWorkload load('jstests/concurrency/fsm_workloads/findAndModify_upsert.js'); // for $config -var $config = extendWorkload($config, - function($config, $super) { +var $config = extendWorkload($config, function($config, $super) { - $config.data.sort = { - $natural: 1 - }; + $config.data.sort = {$natural: 1}; - return $config; - }); + return $config; +}); diff --git a/jstests/concurrency/fsm_workloads/group.js b/jstests/concurrency/fsm_workloads/group.js index 3ccc909e0c9..a02d175f202 100644 --- a/jstests/concurrency/fsm_workloads/group.js +++ b/jstests/concurrency/fsm_workloads/group.js @@ -21,9 +21,7 @@ var $config = (function() { initial: {bucketCount: 0, bucketSum: 0}, $keyf: function $keyf(doc) { // place doc.rand into appropriate bucket - return { - bucket: Math.floor(doc.rand * 10) + 1 - }; + return {bucket: Math.floor(doc.rand * 10) + 1}; }, $reduce: function $reduce(curr, result) { result.bucketCount++; @@ -63,15 +61,11 @@ var $config = (function() { }.bind(this)); } - return { - group: group - }; + return {group: group}; })(); - var transitions = { - group: {group: 1} - }; + var transitions = {group: {group: 1}}; function setup(db, collName, cluster) { var bulk = db[collName].initializeUnorderedBulkOp(); diff --git a/jstests/concurrency/fsm_workloads/group_cond.js b/jstests/concurrency/fsm_workloads/group_cond.js index 1ab6aa827c6..03a77993578 100644 --- a/jstests/concurrency/fsm_workloads/group_cond.js +++ b/jstests/concurrency/fsm_workloads/group_cond.js @@ -16,29 +16,25 @@ load('jstests/concurrency/fsm_libs/extend_workload.js'); // for extendWorkload load('jstests/concurrency/fsm_workloads/group.js'); // for $config -var $config = - extendWorkload($config, - function($config, $super) { - $config.setup = function setup(db, collName, cluster) { - $super.setup.apply(this, arguments); - assertAlways.commandWorked(db[collName].ensureIndex({rand: 1})); - }; +var $config = extendWorkload($config, function($config, $super) { + $config.setup = function setup(db, collName, cluster) { + $super.setup.apply(this, arguments); + assertAlways.commandWorked(db[collName].ensureIndex({rand: 1})); + }; - $config.states.group = function group(db, collName) { - var cmdObj = this.generateGroupCmdObj(collName); - cmdObj.group.cond = { - rand: {$gte: 0.5} - }; - var res = db.runCommand(cmdObj); - assertWhenOwnColl.commandWorked(res); + $config.states.group = function group(db, collName) { + var cmdObj = this.generateGroupCmdObj(collName); + cmdObj.group.cond = {rand: {$gte: 0.5}}; + var res = db.runCommand(cmdObj); + assertWhenOwnColl.commandWorked(res); - assertWhenOwnColl.lte(res.count, this.numDocs); - assertWhenOwnColl.lte(res.keys, 5); - assertWhenOwnColl(function() { - assertWhenOwnColl.lte(res.retval.length, 5); - assertWhenOwnColl.eq(this.sumBucketCount(res.retval), res.count); - }.bind(this)); - }; + assertWhenOwnColl.lte(res.count, this.numDocs); + assertWhenOwnColl.lte(res.keys, 5); + assertWhenOwnColl(function() { + assertWhenOwnColl.lte(res.retval.length, 5); + assertWhenOwnColl.eq(this.sumBucketCount(res.retval), res.count); + }.bind(this)); + }; - return $config; - }); + return $config; +}); diff --git a/jstests/concurrency/fsm_workloads/indexed_insert_1char.js b/jstests/concurrency/fsm_workloads/indexed_insert_1char.js index 5330bd9191e..54fe0662cb4 100644 --- a/jstests/concurrency/fsm_workloads/indexed_insert_1char.js +++ b/jstests/concurrency/fsm_workloads/indexed_insert_1char.js @@ -10,18 +10,17 @@ load('jstests/concurrency/fsm_libs/extend_workload.js'); // for extendWorkload load('jstests/concurrency/fsm_workloads/indexed_insert_base.js'); // for $config -var $config = extendWorkload($config, - function($config, $super) { +var $config = extendWorkload($config, function($config, $super) { - $config.data.indexedField = 'indexed_insert_1char'; - $config.data.shardKey = {}; - $config.data.shardKey[$config.data.indexedField] = 1; + $config.data.indexedField = 'indexed_insert_1char'; + $config.data.shardKey = {}; + $config.data.shardKey[$config.data.indexedField] = 1; - $config.states.init = function init(db, collName) { - $super.states.init.apply(this, arguments); + $config.states.init = function init(db, collName) { + $super.states.init.apply(this, arguments); - this.indexedValue = String.fromCharCode(33 + this.tid); - }; + this.indexedValue = String.fromCharCode(33 + this.tid); + }; - return $config; - }); + return $config; +}); diff --git a/jstests/concurrency/fsm_workloads/indexed_insert_2d.js b/jstests/concurrency/fsm_workloads/indexed_insert_2d.js index 674f229f53b..a461f9cb310 100644 --- a/jstests/concurrency/fsm_workloads/indexed_insert_2d.js +++ b/jstests/concurrency/fsm_workloads/indexed_insert_2d.js @@ -10,48 +10,46 @@ load('jstests/concurrency/fsm_libs/extend_workload.js'); // for extendWorkload load('jstests/concurrency/fsm_workloads/indexed_insert_base.js'); // for $config -var $config = extendWorkload( - $config, - function($config, $super) { +var $config = extendWorkload($config, function($config, $super) { - $config.data.indexedField = 'indexed_insert_2d'; - // Remove the shard key for 2d indexes, as they are not supported - delete $config.data.shardKey; + $config.data.indexedField = 'indexed_insert_2d'; + // Remove the shard key for 2d indexes, as they are not supported + delete $config.data.shardKey; - $config.states.init = function init(db, collName) { - $super.states.init.apply(this, arguments); + $config.states.init = function init(db, collName) { + $super.states.init.apply(this, arguments); - assertAlways.lt(this.tid, 1 << 16); // assume tid is a 16 bit nonnegative int - // split the tid into the odd bits and the even bits - // for example: - // tid: 57 = 00111001 - // even: 0 1 0 1 = 5 - // odd: 0 1 1 0 = 6 - // This lets us turn every tid into a unique pair of numbers within the range [0, 255]. - // The pairs are then normalized to have valid longitude and latitude values. - var oddBits = 0; - var evenBits = 0; - for (var i = 0; i < 16; ++i) { - if (this.tid & 1 << i) { - if (i % 2 === 0) { - // i is even - evenBits |= 1 << (i / 2); - } else { - // i is odd - oddBits |= 1 << (i / 2); - } + assertAlways.lt(this.tid, 1 << 16); // assume tid is a 16 bit nonnegative int + // split the tid into the odd bits and the even bits + // for example: + // tid: 57 = 00111001 + // even: 0 1 0 1 = 5 + // odd: 0 1 1 0 = 6 + // This lets us turn every tid into a unique pair of numbers within the range [0, 255]. + // The pairs are then normalized to have valid longitude and latitude values. + var oddBits = 0; + var evenBits = 0; + for (var i = 0; i < 16; ++i) { + if (this.tid & 1 << i) { + if (i % 2 === 0) { + // i is even + evenBits |= 1 << (i / 2); + } else { + // i is odd + oddBits |= 1 << (i / 2); } } - assertAlways.lt(oddBits, 256); - assertAlways.lt(evenBits, 256); - this.indexedValue = [(evenBits - 128) / 2, (oddBits - 128) / 2]; - }; + } + assertAlways.lt(oddBits, 256); + assertAlways.lt(evenBits, 256); + this.indexedValue = [(evenBits - 128) / 2, (oddBits - 128) / 2]; + }; - $config.data.getIndexSpec = function getIndexSpec() { - var ixSpec = {}; - ixSpec[this.indexedField] = '2d'; - return ixSpec; - }; + $config.data.getIndexSpec = function getIndexSpec() { + var ixSpec = {}; + ixSpec[this.indexedField] = '2d'; + return ixSpec; + }; - return $config; - }); + return $config; +}); diff --git a/jstests/concurrency/fsm_workloads/indexed_insert_2dsphere.js b/jstests/concurrency/fsm_workloads/indexed_insert_2dsphere.js index a0fb5613ef6..40134e97840 100644 --- a/jstests/concurrency/fsm_workloads/indexed_insert_2dsphere.js +++ b/jstests/concurrency/fsm_workloads/indexed_insert_2dsphere.js @@ -10,16 +10,15 @@ load('jstests/concurrency/fsm_libs/extend_workload.js'); // for extendWorkload load('jstests/concurrency/fsm_workloads/indexed_insert_2d.js'); // for $config -var $config = extendWorkload($config, - function($config, $super) { +var $config = extendWorkload($config, function($config, $super) { - $config.data.indexedField = 'indexed_insert_2dsphere'; + $config.data.indexedField = 'indexed_insert_2dsphere'; - $config.data.getIndexSpec = function getIndexSpec() { - var ixSpec = {}; - ixSpec[this.indexedField] = '2dsphere'; - return ixSpec; - }; + $config.data.getIndexSpec = function getIndexSpec() { + var ixSpec = {}; + ixSpec[this.indexedField] = '2dsphere'; + return ixSpec; + }; - return $config; - }); + return $config; +}); diff --git a/jstests/concurrency/fsm_workloads/indexed_insert_base.js b/jstests/concurrency/fsm_workloads/indexed_insert_base.js index 59dcab4f0a0..b7a52aae08a 100644 --- a/jstests/concurrency/fsm_workloads/indexed_insert_base.js +++ b/jstests/concurrency/fsm_workloads/indexed_insert_base.js @@ -69,11 +69,7 @@ var $config = (function() { } }; - var transitions = { - init: {insert: 1}, - insert: {find: 1}, - find: {insert: 1} - }; + var transitions = {init: {insert: 1}, insert: {find: 1}, find: {insert: 1}}; function setup(db, collName, cluster) { var res = db[collName].ensureIndex(this.getIndexSpec()); diff --git a/jstests/concurrency/fsm_workloads/indexed_insert_compound.js b/jstests/concurrency/fsm_workloads/indexed_insert_compound.js index a32fc084215..c704b6dd0bc 100644 --- a/jstests/concurrency/fsm_workloads/indexed_insert_compound.js +++ b/jstests/concurrency/fsm_workloads/indexed_insert_compound.js @@ -10,31 +10,29 @@ load('jstests/concurrency/fsm_libs/extend_workload.js'); // for extendWorkload load('jstests/concurrency/fsm_workloads/indexed_insert_base.js'); // for $config -var $config = - extendWorkload($config, - function($config, $super) { +var $config = extendWorkload($config, function($config, $super) { - $config.states.init = function init(db, collName) { - $super.states.init.apply(this, arguments); - }; + $config.states.init = function init(db, collName) { + $super.states.init.apply(this, arguments); + }; - $config.data.getDoc = function getDoc() { - return { - indexed_insert_compound_x: this.tid & 0x0f, // lowest 4 bits - indexed_insert_compound_y: this.tid >> 4, // high bits - indexed_insert_compound_z: String.fromCharCode(33 + this.tid) - }; - }; + $config.data.getDoc = function getDoc() { + return { + indexed_insert_compound_x: this.tid & 0x0f, // lowest 4 bits + indexed_insert_compound_y: this.tid >> 4, // high bits + indexed_insert_compound_z: String.fromCharCode(33 + this.tid) + }; + }; - $config.data.getIndexSpec = function getIndexSpec() { - return { - indexed_insert_compound_x: 1, - indexed_insert_compound_y: 1, - indexed_insert_compound_z: 1 - }; - }; + $config.data.getIndexSpec = function getIndexSpec() { + return { + indexed_insert_compound_x: 1, + indexed_insert_compound_y: 1, + indexed_insert_compound_z: 1 + }; + }; - $config.data.shardKey = $config.data.getIndexSpec(); + $config.data.shardKey = $config.data.getIndexSpec(); - return $config; - }); + return $config; +}); diff --git a/jstests/concurrency/fsm_workloads/indexed_insert_eval.js b/jstests/concurrency/fsm_workloads/indexed_insert_eval.js index ccb3696ffeb..f35d4565e3b 100644 --- a/jstests/concurrency/fsm_workloads/indexed_insert_eval.js +++ b/jstests/concurrency/fsm_workloads/indexed_insert_eval.js @@ -10,26 +10,24 @@ load('jstests/concurrency/fsm_libs/extend_workload.js'); // for extendWorkload load('jstests/concurrency/fsm_workloads/indexed_insert_base.js'); // for $config -var $config = - extendWorkload($config, - function($config, $super) { +var $config = extendWorkload($config, function($config, $super) { - $config.data.nolock = false; + $config.data.nolock = false; - $config.states.insert = function insert(db, collName) { - var evalResult = db.runCommand({ - eval: function(collName, doc) { - var insertResult = db[collName].insert(doc); - return tojson(insertResult); - }, - args: [collName, this.getDoc()], - nolock: this.nolock - }); - assertAlways.commandWorked(evalResult); - var insertResult = JSON.parse(evalResult.retval); - assertAlways.eq(1, insertResult.nInserted, tojson(insertResult)); - this.nInserted += this.docsPerInsert; - }; + $config.states.insert = function insert(db, collName) { + var evalResult = db.runCommand({ + eval: function(collName, doc) { + var insertResult = db[collName].insert(doc); + return tojson(insertResult); + }, + args: [collName, this.getDoc()], + nolock: this.nolock + }); + assertAlways.commandWorked(evalResult); + var insertResult = JSON.parse(evalResult.retval); + assertAlways.eq(1, insertResult.nInserted, tojson(insertResult)); + this.nInserted += this.docsPerInsert; + }; - return $config; - }); + return $config; +}); diff --git a/jstests/concurrency/fsm_workloads/indexed_insert_eval_nolock.js b/jstests/concurrency/fsm_workloads/indexed_insert_eval_nolock.js index 33e8ef41d56..f87ba5da790 100644 --- a/jstests/concurrency/fsm_workloads/indexed_insert_eval_nolock.js +++ b/jstests/concurrency/fsm_workloads/indexed_insert_eval_nolock.js @@ -10,10 +10,9 @@ load('jstests/concurrency/fsm_libs/extend_workload.js'); // for extendWorkload load('jstests/concurrency/fsm_workloads/indexed_insert_eval.js'); // for $config -var $config = extendWorkload($config, - function($config, $super) { +var $config = extendWorkload($config, function($config, $super) { - $config.data.nolock = true; + $config.data.nolock = true; - return $config; - }); + return $config; +}); diff --git a/jstests/concurrency/fsm_workloads/indexed_insert_heterogeneous.js b/jstests/concurrency/fsm_workloads/indexed_insert_heterogeneous.js index ddf2a0c0ead..b486120185d 100644 --- a/jstests/concurrency/fsm_workloads/indexed_insert_heterogeneous.js +++ b/jstests/concurrency/fsm_workloads/indexed_insert_heterogeneous.js @@ -10,48 +10,47 @@ load('jstests/concurrency/fsm_libs/extend_workload.js'); // for extendWorkload load('jstests/concurrency/fsm_workloads/indexed_insert_base.js'); // for $config -var $config = extendWorkload($config, - function($config, $super) { - - $config.data.indexedField = 'indexed_insert_heterogeneous'; - $config.data.shardKey = {}; - $config.data.shardKey[$config.data.indexedField] = 1; - - $config.states.init = function init(db, collName) { - $super.states.init.apply(this, arguments); - - // prefix str with zeroes to make it have length len - function pad(len, str) { - var padding = new Array(len + 1).join('0'); - return (padding + str).slice(-len); - } - - function makeOID(tid) { - var str = pad(24, tid.toString(16)); - return new ObjectId(str); - } - - function makeDate(tid) { - var d = new ISODate('2000-01-01T00:00:00.000Z'); - // setSeconds(n) where n >= 60 will just cause the minutes, - // hours, etc to increase, - // so this produces a unique date for each tid - d.setSeconds(tid); - return d; - } - - var choices = [ - this.tid, // int - this.tid.toString(), // string - this.tid * 0.0001, // float - {tid: this.tid}, // subdocument - makeOID(this.tid), // objectid - makeDate(this.tid), // date - new Function('', 'return ' + this.tid + ';') // function - ]; - - this.indexedValue = choices[this.tid % choices.length]; - }; - - return $config; - }); +var $config = extendWorkload($config, function($config, $super) { + + $config.data.indexedField = 'indexed_insert_heterogeneous'; + $config.data.shardKey = {}; + $config.data.shardKey[$config.data.indexedField] = 1; + + $config.states.init = function init(db, collName) { + $super.states.init.apply(this, arguments); + + // prefix str with zeroes to make it have length len + function pad(len, str) { + var padding = new Array(len + 1).join('0'); + return (padding + str).slice(-len); + } + + function makeOID(tid) { + var str = pad(24, tid.toString(16)); + return new ObjectId(str); + } + + function makeDate(tid) { + var d = new ISODate('2000-01-01T00:00:00.000Z'); + // setSeconds(n) where n >= 60 will just cause the minutes, + // hours, etc to increase, + // so this produces a unique date for each tid + d.setSeconds(tid); + return d; + } + + var choices = [ + this.tid, // int + this.tid.toString(), // string + this.tid * 0.0001, // float + {tid: this.tid}, // subdocument + makeOID(this.tid), // objectid + makeDate(this.tid), // date + new Function('', 'return ' + this.tid + ';') // function + ]; + + this.indexedValue = choices[this.tid % choices.length]; + }; + + return $config; +}); diff --git a/jstests/concurrency/fsm_workloads/indexed_insert_large.js b/jstests/concurrency/fsm_workloads/indexed_insert_large.js index d7bedb22ade..cb2dbf58b21 100644 --- a/jstests/concurrency/fsm_workloads/indexed_insert_large.js +++ b/jstests/concurrency/fsm_workloads/indexed_insert_large.js @@ -11,38 +11,35 @@ load('jstests/concurrency/fsm_libs/extend_workload.js'); // for extendWorkload load('jstests/concurrency/fsm_workloads/indexed_insert_base.js'); // for $config -var $config = extendWorkload( - $config, - function($config, $super) { +var $config = extendWorkload($config, function($config, $super) { - $config.data.indexedField = 'indexed_insert_large'; + $config.data.indexedField = 'indexed_insert_large'; - // Remove the shard key, since it cannot be greater than 512 bytes - delete $config.data.shardKey; + // Remove the shard key, since it cannot be greater than 512 bytes + delete $config.data.shardKey; - $config.states.init = function init(db, collName) { - $super.states.init.apply(this, arguments); + $config.states.init = function init(db, collName) { + $super.states.init.apply(this, arguments); - // "The total size of an index entry, which can include structural overhead depending on - // the - // BSON type, must be less than 1024 bytes." - // http://docs.mongodb.org/manual/reference/limits/ - var maxIndexedSize = 1023; + // "The total size of an index entry, which can include structural overhead depending on + // the + // BSON type, must be less than 1024 bytes." + // http://docs.mongodb.org/manual/reference/limits/ + var maxIndexedSize = 1023; - var bsonOverhead = Object.bsonsize({'': ''}); + var bsonOverhead = Object.bsonsize({'': ''}); - var bigstr = new Array(maxIndexedSize + 1).join('x'); + var bigstr = new Array(maxIndexedSize + 1).join('x'); - // prefix the big string with tid to make it unique, - // then trim it down so that it plus bson overhead is maxIndexedSize + // prefix the big string with tid to make it unique, + // then trim it down so that it plus bson overhead is maxIndexedSize - this.indexedValue = (this.tid + bigstr).slice(0, maxIndexedSize - bsonOverhead); + this.indexedValue = (this.tid + bigstr).slice(0, maxIndexedSize - bsonOverhead); - assertAlways.eq( - maxIndexedSize, - Object.bsonsize({'': this.indexedValue}), - 'buggy test: the inserted docs will not have the expected index-key size'); - }; + assertAlways.eq(maxIndexedSize, + Object.bsonsize({'': this.indexedValue}), + 'buggy test: the inserted docs will not have the expected index-key size'); + }; - return $config; - }); + return $config; +}); diff --git a/jstests/concurrency/fsm_workloads/indexed_insert_long_fieldname.js b/jstests/concurrency/fsm_workloads/indexed_insert_long_fieldname.js index 3c8c2f70223..143f548619a 100644 --- a/jstests/concurrency/fsm_workloads/indexed_insert_long_fieldname.js +++ b/jstests/concurrency/fsm_workloads/indexed_insert_long_fieldname.js @@ -10,16 +10,14 @@ load('jstests/concurrency/fsm_libs/extend_workload.js'); // for extendWorkload load('jstests/concurrency/fsm_workloads/indexed_insert_base.js'); // for $config -var $config = extendWorkload($config, - function($config, $super) { +var $config = extendWorkload($config, function($config, $super) { - // TODO: make this field name even longer? - var length = 100; - var prefix = 'indexed_insert_long_fieldname_'; - $config.data.indexedField = - prefix + new Array(length - prefix.length + 1).join('x'); - $config.data.shardKey = {}; - $config.data.shardKey[$config.data.indexedField] = 1; + // TODO: make this field name even longer? + var length = 100; + var prefix = 'indexed_insert_long_fieldname_'; + $config.data.indexedField = prefix + new Array(length - prefix.length + 1).join('x'); + $config.data.shardKey = {}; + $config.data.shardKey[$config.data.indexedField] = 1; - return $config; - }); + return $config; +}); diff --git a/jstests/concurrency/fsm_workloads/indexed_insert_multikey.js b/jstests/concurrency/fsm_workloads/indexed_insert_multikey.js index e49b5356760..34c28db22eb 100644 --- a/jstests/concurrency/fsm_workloads/indexed_insert_multikey.js +++ b/jstests/concurrency/fsm_workloads/indexed_insert_multikey.js @@ -10,21 +10,19 @@ load('jstests/concurrency/fsm_libs/extend_workload.js'); // for extendWorkload load('jstests/concurrency/fsm_workloads/indexed_insert_base.js'); // for $config -var $config = - extendWorkload($config, - function($config, $super) { +var $config = extendWorkload($config, function($config, $super) { - $config.data.indexedField = 'indexed_insert_multikey'; - // Remove the shard key, since it cannot be a multikey index - delete $config.data.shardKey; + $config.data.indexedField = 'indexed_insert_multikey'; + // Remove the shard key, since it cannot be a multikey index + delete $config.data.shardKey; - $config.states.init = function init(db, collName) { - $super.states.init.apply(this, arguments); + $config.states.init = function init(db, collName) { + $super.states.init.apply(this, arguments); - this.indexedValue = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9].map(function(n) { - return this.tid * 10 + n; - }.bind(this)); - }; + this.indexedValue = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9].map(function(n) { + return this.tid * 10 + n; + }.bind(this)); + }; - return $config; - }); + return $config; +}); diff --git a/jstests/concurrency/fsm_workloads/indexed_insert_ordered_bulk.js b/jstests/concurrency/fsm_workloads/indexed_insert_ordered_bulk.js index eb70c850488..38998cd9f59 100644 --- a/jstests/concurrency/fsm_workloads/indexed_insert_ordered_bulk.js +++ b/jstests/concurrency/fsm_workloads/indexed_insert_ordered_bulk.js @@ -11,30 +11,28 @@ load('jstests/concurrency/fsm_libs/extend_workload.js'); // for extendWorkload load('jstests/concurrency/fsm_workloads/indexed_insert_base.js'); // for $config -var $config = - extendWorkload($config, - function($config, $super) { +var $config = extendWorkload($config, function($config, $super) { - $config.data.indexedField = 'indexed_insert_ordered_bulk'; - $config.data.shardKey = {}; - $config.data.shardKey[$config.data.indexedField] = 1; + $config.data.indexedField = 'indexed_insert_ordered_bulk'; + $config.data.shardKey = {}; + $config.data.shardKey[$config.data.indexedField] = 1; - $config.states.insert = function insert(db, collName) { - var doc = {}; - doc[this.indexedField] = this.indexedValue; + $config.states.insert = function insert(db, collName) { + var doc = {}; + doc[this.indexedField] = this.indexedValue; - var bulk = db[collName].initializeOrderedBulkOp(); - for (var i = 0; i < this.docsPerInsert; ++i) { - bulk.insert(doc); - } - var res = bulk.execute(); - assertAlways.writeOK(res); - assertAlways.eq(this.docsPerInsert, res.nInserted, tojson(res)); + var bulk = db[collName].initializeOrderedBulkOp(); + for (var i = 0; i < this.docsPerInsert; ++i) { + bulk.insert(doc); + } + var res = bulk.execute(); + assertAlways.writeOK(res); + assertAlways.eq(this.docsPerInsert, res.nInserted, tojson(res)); - this.nInserted += this.docsPerInsert; - }; + this.nInserted += this.docsPerInsert; + }; - $config.data.docsPerInsert = 15; + $config.data.docsPerInsert = 15; - return $config; - }); + return $config; +}); diff --git a/jstests/concurrency/fsm_workloads/indexed_insert_text.js b/jstests/concurrency/fsm_workloads/indexed_insert_text.js index ab38d07098f..82e0feb09a8 100644 --- a/jstests/concurrency/fsm_workloads/indexed_insert_text.js +++ b/jstests/concurrency/fsm_workloads/indexed_insert_text.js @@ -32,10 +32,7 @@ var $config = (function() { } }; - var transitions = { - init: {insert: 1}, - insert: {insert: 1} - }; + var transitions = {init: {insert: 1}, insert: {insert: 1}}; function setup(db, collName, cluster) { var ixSpec = {}; diff --git a/jstests/concurrency/fsm_workloads/indexed_insert_text_multikey.js b/jstests/concurrency/fsm_workloads/indexed_insert_text_multikey.js index 0cc7b590684..b527ef016f8 100644 --- a/jstests/concurrency/fsm_workloads/indexed_insert_text_multikey.js +++ b/jstests/concurrency/fsm_workloads/indexed_insert_text_multikey.js @@ -8,30 +8,27 @@ load('jstests/concurrency/fsm_libs/extend_workload.js'); // for extendWorkload load('jstests/concurrency/fsm_workloads/indexed_insert_text.js'); // for $config -var $config = - extendWorkload($config, - function($config, $super) { +var $config = extendWorkload($config, function($config, $super) { - $config.states.init = function init(db, collName) { - $super.states.init.apply(this, arguments); - }; + $config.states.init = function init(db, collName) { + $super.states.init.apply(this, arguments); + }; - $config.data.getRandomTextSnippet = function getRandomTextSnippet() { - var len = Random.randInt(5) + - 1; // ensure we always add some text, not just empty array - var textArr = []; - for (var i = 0; i < len; ++i) { - textArr.push($super.data.getRandomTextSnippet.call(this, arguments)); - } - return textArr; - }; + $config.data.getRandomTextSnippet = function getRandomTextSnippet() { + var len = Random.randInt(5) + 1; // ensure we always add some text, not just empty array + var textArr = []; + for (var i = 0; i < len; ++i) { + textArr.push($super.data.getRandomTextSnippet.call(this, arguments)); + } + return textArr; + }; - // SERVER-21291: Reduce the thread count to alleviate PV1 failovers on - // Windows DEBUG hosts. - $config.threadCount = 5; + // SERVER-21291: Reduce the thread count to alleviate PV1 failovers on + // Windows DEBUG hosts. + $config.threadCount = 5; - // Remove the shard key, since it cannot be a multikey index - delete $config.data.shardKey; + // Remove the shard key, since it cannot be a multikey index + delete $config.data.shardKey; - return $config; - }); + return $config; +}); diff --git a/jstests/concurrency/fsm_workloads/indexed_insert_ttl.js b/jstests/concurrency/fsm_workloads/indexed_insert_ttl.js index 90aa6d3baf7..ba95fa6e778 100644 --- a/jstests/concurrency/fsm_workloads/indexed_insert_ttl.js +++ b/jstests/concurrency/fsm_workloads/indexed_insert_ttl.js @@ -24,10 +24,7 @@ var $config = (function() { } }; - var transitions = { - init: {insert: 1}, - insert: {insert: 1} - }; + var transitions = {init: {insert: 1}, insert: {insert: 1}}; function setup(db, collName, cluster) { var res = db[collName].ensureIndex({indexed_insert_ttl: 1}, diff --git a/jstests/concurrency/fsm_workloads/indexed_insert_unordered_bulk.js b/jstests/concurrency/fsm_workloads/indexed_insert_unordered_bulk.js index aa64e8d21e5..3c1ea8f0ea0 100644 --- a/jstests/concurrency/fsm_workloads/indexed_insert_unordered_bulk.js +++ b/jstests/concurrency/fsm_workloads/indexed_insert_unordered_bulk.js @@ -11,30 +11,28 @@ load('jstests/concurrency/fsm_libs/extend_workload.js'); // for extendWorkload load('jstests/concurrency/fsm_workloads/indexed_insert_base.js'); // for $config -var $config = - extendWorkload($config, - function($config, $super) { +var $config = extendWorkload($config, function($config, $super) { - $config.data.indexedField = 'indexed_insert_unordered_bulk'; - $config.data.shardKey = {}; - $config.data.shardKey[$config.data.indexedField] = 1; + $config.data.indexedField = 'indexed_insert_unordered_bulk'; + $config.data.shardKey = {}; + $config.data.shardKey[$config.data.indexedField] = 1; - $config.states.insert = function insert(db, collName) { - var doc = {}; - doc[this.indexedField] = this.indexedValue; + $config.states.insert = function insert(db, collName) { + var doc = {}; + doc[this.indexedField] = this.indexedValue; - var bulk = db[collName].initializeUnorderedBulkOp(); - for (var i = 0; i < this.docsPerInsert; ++i) { - bulk.insert(doc); - } - var res = bulk.execute(); - assertAlways.writeOK(res); - assertAlways.eq(this.docsPerInsert, res.nInserted, tojson(res)); + var bulk = db[collName].initializeUnorderedBulkOp(); + for (var i = 0; i < this.docsPerInsert; ++i) { + bulk.insert(doc); + } + var res = bulk.execute(); + assertAlways.writeOK(res); + assertAlways.eq(this.docsPerInsert, res.nInserted, tojson(res)); - this.nInserted += this.docsPerInsert; - }; + this.nInserted += this.docsPerInsert; + }; - $config.data.docsPerInsert = 15; + $config.data.docsPerInsert = 15; - return $config; - }); + return $config; +}); diff --git a/jstests/concurrency/fsm_workloads/indexed_insert_upsert.js b/jstests/concurrency/fsm_workloads/indexed_insert_upsert.js index cc26d364ace..bc1b65e9597 100644 --- a/jstests/concurrency/fsm_workloads/indexed_insert_upsert.js +++ b/jstests/concurrency/fsm_workloads/indexed_insert_upsert.js @@ -13,34 +13,32 @@ load('jstests/concurrency/fsm_libs/extend_workload.js'); // for extendWorkload load('jstests/concurrency/fsm_workloads/indexed_insert_base.js'); // for $config -var $config = extendWorkload( - $config, - function($config, $super) { +var $config = extendWorkload($config, function($config, $super) { - $config.data.indexedField = 'indexed_insert_upsert'; - $config.data.shardKey = {}; - $config.data.shardKey[$config.data.indexedField] = 1; + $config.data.indexedField = 'indexed_insert_upsert'; + $config.data.shardKey = {}; + $config.data.shardKey[$config.data.indexedField] = 1; - $config.states.init = function init(db, collName) { - $super.states.init.apply(this, arguments); + $config.states.init = function init(db, collName) { + $super.states.init.apply(this, arguments); - this.counter = 0; - }; + this.counter = 0; + }; - $config.states.insert = function insert(db, collName) { - var doc = this.getDoc(); - doc.counter = this.counter++; // ensure doc is unique to guarantee an upsert occurs - doc._id = new ObjectId(); // _id is required for shard targeting + $config.states.insert = function insert(db, collName) { + var doc = this.getDoc(); + doc.counter = this.counter++; // ensure doc is unique to guarantee an upsert occurs + doc._id = new ObjectId(); // _id is required for shard targeting - var res = db[collName].update(doc, {$inc: {unused: 0}}, {upsert: true}); - assertAlways.eq(0, res.nMatched, tojson(res)); - assertAlways.eq(1, res.nUpserted, tojson(res)); - if (db.getMongo().writeMode() === 'commands') { - assertAlways.eq(0, res.nModified, tojson(res)); - } + var res = db[collName].update(doc, {$inc: {unused: 0}}, {upsert: true}); + assertAlways.eq(0, res.nMatched, tojson(res)); + assertAlways.eq(1, res.nUpserted, tojson(res)); + if (db.getMongo().writeMode() === 'commands') { + assertAlways.eq(0, res.nModified, tojson(res)); + } - this.nInserted += this.docsPerInsert; - }; + this.nInserted += this.docsPerInsert; + }; - return $config; - }); + return $config; +}); diff --git a/jstests/concurrency/fsm_workloads/indexed_insert_where.js b/jstests/concurrency/fsm_workloads/indexed_insert_where.js index 14408c26f69..e5d2a98b8c5 100644 --- a/jstests/concurrency/fsm_workloads/indexed_insert_where.js +++ b/jstests/concurrency/fsm_workloads/indexed_insert_where.js @@ -15,9 +15,7 @@ var $config = (function() { documentsToInsert: 100, insertedDocuments: 0, generateDocumentToInsert: function generateDocumentToInsert() { - return { - tid: this.tid - }; + return {tid: this.tid}; }, shardKey: {tid: 1} }; @@ -43,10 +41,7 @@ var $config = (function() { } }; - var transitions = { - insert: {insert: 0.2, query: 0.8}, - query: {insert: 0.8, query: 0.2} - }; + var transitions = {insert: {insert: 0.2, query: 0.8}, query: {insert: 0.8, query: 0.2}}; var setup = function setup(db, collName, cluster) { assertAlways.commandWorked(db[collName].ensureIndex({tid: 1})); diff --git a/jstests/concurrency/fsm_workloads/list_indexes.js b/jstests/concurrency/fsm_workloads/list_indexes.js index 6bcdb8ba96c..e62225eaa51 100644 --- a/jstests/concurrency/fsm_workloads/list_indexes.js +++ b/jstests/concurrency/fsm_workloads/list_indexes.js @@ -26,10 +26,7 @@ var $config = (function() { assertWhenOwnColl.gte(cursor.itcount(), 0); } - return { - modifyIndices: modifyIndices, - listIndices: listIndices - }; + return {modifyIndices: modifyIndices, listIndices: listIndices}; })(); var transitions = { diff --git a/jstests/concurrency/fsm_workloads/map_reduce_drop.js b/jstests/concurrency/fsm_workloads/map_reduce_drop.js index ef03805dffd..48398b4aae2 100644 --- a/jstests/concurrency/fsm_workloads/map_reduce_drop.js +++ b/jstests/concurrency/fsm_workloads/map_reduce_drop.js @@ -80,11 +80,7 @@ var $config = (function() { } } - return { - dropColl: dropColl, - dropDB: dropDB, - mapReduce: mapReduce - }; + return {dropColl: dropColl, dropDB: dropDB, mapReduce: mapReduce}; })(); diff --git a/jstests/concurrency/fsm_workloads/map_reduce_inline.js b/jstests/concurrency/fsm_workloads/map_reduce_inline.js index 1633ce0cc19..ade5a8aa369 100644 --- a/jstests/concurrency/fsm_workloads/map_reduce_inline.js +++ b/jstests/concurrency/fsm_workloads/map_reduce_inline.js @@ -38,12 +38,7 @@ var $config = (function() { return reducedValue; } - var data = { - numDocs: 2000, - mapper: mapper, - reducer: reducer, - finalizer: finalizer - }; + var data = {numDocs: 2000, mapper: mapper, reducer: reducer, finalizer: finalizer}; var states = (function() { @@ -53,26 +48,17 @@ var $config = (function() { } function mapReduce(db, collName) { - var options = { - finalize: this.finalizer, - out: {inline: 1} - }; + var options = {finalize: this.finalizer, out: {inline: 1}}; var res = db[collName].mapReduce(this.mapper, this.reducer, options); assertAlways.commandWorked(res); } - return { - init: init, - mapReduce: mapReduce - }; + return {init: init, mapReduce: mapReduce}; })(); - var transitions = { - init: {mapReduce: 1}, - mapReduce: {mapReduce: 1} - }; + var transitions = {init: {mapReduce: 1}, mapReduce: {mapReduce: 1}}; function makeDoc(keyLimit, valueLimit) { return { diff --git a/jstests/concurrency/fsm_workloads/map_reduce_merge.js b/jstests/concurrency/fsm_workloads/map_reduce_merge.js index 4f96c229eac..f12e7f24144 100644 --- a/jstests/concurrency/fsm_workloads/map_reduce_merge.js +++ b/jstests/concurrency/fsm_workloads/map_reduce_merge.js @@ -16,49 +16,44 @@ load('jstests/concurrency/fsm_libs/extend_workload.js'); // for extendWorkload load('jstests/concurrency/fsm_workloads/map_reduce_inline.js'); // for $config -var $config = - extendWorkload($config, - function($config, $super) { +var $config = extendWorkload($config, function($config, $super) { - // Use the workload name as the database name, - // since the workload name is assumed to be unique. - var uniqueDBName = 'map_reduce_merge'; + // Use the workload name as the database name, + // since the workload name is assumed to be unique. + var uniqueDBName = 'map_reduce_merge'; - $config.states.init = function init(db, collName) { - $super.states.init.apply(this, arguments); + $config.states.init = function init(db, collName) { + $super.states.init.apply(this, arguments); - this.outDBName = db.getName() + uniqueDBName; - }; + this.outDBName = db.getName() + uniqueDBName; + }; - $config.states.mapReduce = function mapReduce(db, collName) { - var outDB = db.getSiblingDB(this.outDBName); - var fullName = outDB[collName].getFullName(); - assertAlways(outDB[collName].exists() !== null, - "output collection '" + fullName + "' should exist"); + $config.states.mapReduce = function mapReduce(db, collName) { + var outDB = db.getSiblingDB(this.outDBName); + var fullName = outDB[collName].getFullName(); + assertAlways(outDB[collName].exists() !== null, + "output collection '" + fullName + "' should exist"); - // Have all threads combine their results into the same collection - var options = { - finalize: this.finalizer, - out: {merge: collName, db: this.outDBName} - }; + // Have all threads combine their results into the same collection + var options = {finalize: this.finalizer, out: {merge: collName, db: this.outDBName}}; - var res = db[collName].mapReduce(this.mapper, this.reducer, options); - assertAlways.commandWorked(res); - }; + var res = db[collName].mapReduce(this.mapper, this.reducer, options); + assertAlways.commandWorked(res); + }; - $config.setup = function setup(db, collName, cluster) { - $super.setup.apply(this, arguments); + $config.setup = function setup(db, collName, cluster) { + $super.setup.apply(this, arguments); - var outDB = db.getSiblingDB(db.getName() + uniqueDBName); - assertAlways.commandWorked(outDB.createCollection(collName)); - }; + var outDB = db.getSiblingDB(db.getName() + uniqueDBName); + assertAlways.commandWorked(outDB.createCollection(collName)); + }; - $config.teardown = function teardown(db, collName, cluster) { - var outDB = db.getSiblingDB(db.getName() + uniqueDBName); - var res = outDB.dropDatabase(); - assertAlways.commandWorked(res); - assertAlways.eq(db.getName() + uniqueDBName, res.dropped); - }; + $config.teardown = function teardown(db, collName, cluster) { + var outDB = db.getSiblingDB(db.getName() + uniqueDBName); + var res = outDB.dropDatabase(); + assertAlways.commandWorked(res); + assertAlways.eq(db.getName() + uniqueDBName, res.dropped); + }; - return $config; - }); + return $config; +}); diff --git a/jstests/concurrency/fsm_workloads/map_reduce_merge_nonatomic.js b/jstests/concurrency/fsm_workloads/map_reduce_merge_nonatomic.js index 8f0804b365d..9522854d566 100644 --- a/jstests/concurrency/fsm_workloads/map_reduce_merge_nonatomic.js +++ b/jstests/concurrency/fsm_workloads/map_reduce_merge_nonatomic.js @@ -17,45 +17,43 @@ load('jstests/concurrency/fsm_libs/extend_workload.js'); // for extendWo load('jstests/concurrency/fsm_workloads/map_reduce_inline.js'); // for $config load('jstests/concurrency/fsm_workload_helpers/drop_utils.js'); // for dropDatabases -var $config = - extendWorkload($config, - function($config, $super) { - - // Use the workload name as a prefix for the database name, - // since the workload name is assumed to be unique. - var prefix = 'map_reduce_merge_nonatomic'; - - function uniqueDBName(prefix, tid) { - return prefix + tid; - } - - $config.states.init = function init(db, collName) { - $super.states.init.apply(this, arguments); - - this.outDBName = db.getName() + uniqueDBName(prefix, this.tid); - var outDB = db.getSiblingDB(this.outDBName); - assertAlways.commandWorked(outDB.createCollection(collName)); - }; - - $config.states.mapReduce = function mapReduce(db, collName) { - var outDB = db.getSiblingDB(this.outDBName); - var fullName = outDB[collName].getFullName(); - assertAlways(outDB[collName].exists() !== null, - "output collection '" + fullName + "' should exist"); - - var options = { - finalize: this.finalizer, - out: {merge: collName, db: this.outDBName, nonAtomic: true} - }; - - var res = db[collName].mapReduce(this.mapper, this.reducer, options); - assertAlways.commandWorked(res); - }; - - $config.teardown = function teardown(db, collName, cluster) { - var pattern = new RegExp('^' + db.getName() + prefix + '\\d+$'); - dropDatabases(db, pattern); - }; - - return $config; - }); +var $config = extendWorkload($config, function($config, $super) { + + // Use the workload name as a prefix for the database name, + // since the workload name is assumed to be unique. + var prefix = 'map_reduce_merge_nonatomic'; + + function uniqueDBName(prefix, tid) { + return prefix + tid; + } + + $config.states.init = function init(db, collName) { + $super.states.init.apply(this, arguments); + + this.outDBName = db.getName() + uniqueDBName(prefix, this.tid); + var outDB = db.getSiblingDB(this.outDBName); + assertAlways.commandWorked(outDB.createCollection(collName)); + }; + + $config.states.mapReduce = function mapReduce(db, collName) { + var outDB = db.getSiblingDB(this.outDBName); + var fullName = outDB[collName].getFullName(); + assertAlways(outDB[collName].exists() !== null, + "output collection '" + fullName + "' should exist"); + + var options = { + finalize: this.finalizer, + out: {merge: collName, db: this.outDBName, nonAtomic: true} + }; + + var res = db[collName].mapReduce(this.mapper, this.reducer, options); + assertAlways.commandWorked(res); + }; + + $config.teardown = function teardown(db, collName, cluster) { + var pattern = new RegExp('^' + db.getName() + prefix + '\\d+$'); + dropDatabases(db, pattern); + }; + + return $config; +}); diff --git a/jstests/concurrency/fsm_workloads/map_reduce_reduce.js b/jstests/concurrency/fsm_workloads/map_reduce_reduce.js index b11ccf3614f..3acd8d3b64c 100644 --- a/jstests/concurrency/fsm_workloads/map_reduce_reduce.js +++ b/jstests/concurrency/fsm_workloads/map_reduce_reduce.js @@ -15,43 +15,38 @@ load('jstests/concurrency/fsm_libs/extend_workload.js'); // for extendWo load('jstests/concurrency/fsm_workloads/map_reduce_inline.js'); // for $config load('jstests/concurrency/fsm_workload_helpers/drop_utils.js'); // for dropCollections -var $config = - extendWorkload($config, - function($config, $super) { - - // Use the workload name as a prefix for the collection name, - // since the workload name is assumed to be unique. - var prefix = 'map_reduce_reduce'; - - function uniqueCollectionName(prefix, tid) { - return prefix + tid; - } - - $config.states.init = function init(db, collName) { - $super.states.init.apply(this, arguments); - - this.outCollName = uniqueCollectionName(prefix, this.tid); - assertAlways.commandWorked(db.createCollection(this.outCollName)); - }; - - $config.states.mapReduce = function mapReduce(db, collName) { - var fullName = db[this.outCollName].getFullName(); - assertAlways(db[this.outCollName].exists() !== null, - "output collection '" + fullName + "' should exist"); - - var options = { - finalize: this.finalizer, - out: {reduce: this.outCollName} - }; - - var res = db[collName].mapReduce(this.mapper, this.reducer, options); - assertAlways.commandWorked(res); - }; - - $config.teardown = function teardown(db, collName, cluster) { - var pattern = new RegExp('^' + prefix + '\\d+$'); - dropCollections(db, pattern); - }; - - return $config; - }); +var $config = extendWorkload($config, function($config, $super) { + + // Use the workload name as a prefix for the collection name, + // since the workload name is assumed to be unique. + var prefix = 'map_reduce_reduce'; + + function uniqueCollectionName(prefix, tid) { + return prefix + tid; + } + + $config.states.init = function init(db, collName) { + $super.states.init.apply(this, arguments); + + this.outCollName = uniqueCollectionName(prefix, this.tid); + assertAlways.commandWorked(db.createCollection(this.outCollName)); + }; + + $config.states.mapReduce = function mapReduce(db, collName) { + var fullName = db[this.outCollName].getFullName(); + assertAlways(db[this.outCollName].exists() !== null, + "output collection '" + fullName + "' should exist"); + + var options = {finalize: this.finalizer, out: {reduce: this.outCollName}}; + + var res = db[collName].mapReduce(this.mapper, this.reducer, options); + assertAlways.commandWorked(res); + }; + + $config.teardown = function teardown(db, collName, cluster) { + var pattern = new RegExp('^' + prefix + '\\d+$'); + dropCollections(db, pattern); + }; + + return $config; +}); diff --git a/jstests/concurrency/fsm_workloads/map_reduce_reduce_nonatomic.js b/jstests/concurrency/fsm_workloads/map_reduce_reduce_nonatomic.js index 5953c7c2a07..6ffdf20f85d 100644 --- a/jstests/concurrency/fsm_workloads/map_reduce_reduce_nonatomic.js +++ b/jstests/concurrency/fsm_workloads/map_reduce_reduce_nonatomic.js @@ -17,44 +17,39 @@ load('jstests/concurrency/fsm_libs/extend_workload.js'); // for extendWorkload load('jstests/concurrency/fsm_workloads/map_reduce_inline.js'); // for $config -var $config = - extendWorkload($config, - function($config, $super) { +var $config = extendWorkload($config, function($config, $super) { - // Use the workload name as the collection name, - // since the workload name is assumed to be unique. - var uniqueCollectionName = 'map_reduce_reduce_nonatomic'; + // Use the workload name as the collection name, + // since the workload name is assumed to be unique. + var uniqueCollectionName = 'map_reduce_reduce_nonatomic'; - $config.states.init = function init(db, collName) { - $super.states.init.apply(this, arguments); + $config.states.init = function init(db, collName) { + $super.states.init.apply(this, arguments); - this.outCollName = uniqueCollectionName; - }; + this.outCollName = uniqueCollectionName; + }; - $config.states.mapReduce = function mapReduce(db, collName) { - var fullName = db[this.outCollName].getFullName(); - assertAlways(db[this.outCollName].exists() !== null, - "output collection '" + fullName + "' should exist"); + $config.states.mapReduce = function mapReduce(db, collName) { + var fullName = db[this.outCollName].getFullName(); + assertAlways(db[this.outCollName].exists() !== null, + "output collection '" + fullName + "' should exist"); - // Have all threads combine their results into the same collection - var options = { - finalize: this.finalizer, - out: {reduce: this.outCollName, nonAtomic: true} - }; + // Have all threads combine their results into the same collection + var options = {finalize: this.finalizer, out: {reduce: this.outCollName, nonAtomic: true}}; - var res = db[collName].mapReduce(this.mapper, this.reducer, options); - assertAlways.commandWorked(res); - }; + var res = db[collName].mapReduce(this.mapper, this.reducer, options); + assertAlways.commandWorked(res); + }; - $config.setup = function setup(db, collName, cluster) { - $super.setup.apply(this, arguments); + $config.setup = function setup(db, collName, cluster) { + $super.setup.apply(this, arguments); - assertAlways.commandWorked(db.createCollection(uniqueCollectionName)); - }; + assertAlways.commandWorked(db.createCollection(uniqueCollectionName)); + }; - $config.teardown = function teardown(db, collName, cluster) { - assertAlways(db[uniqueCollectionName].drop()); - }; + $config.teardown = function teardown(db, collName, cluster) { + assertAlways(db[uniqueCollectionName].drop()); + }; - return $config; - }); + return $config; +}); diff --git a/jstests/concurrency/fsm_workloads/map_reduce_replace.js b/jstests/concurrency/fsm_workloads/map_reduce_replace.js index ce268bf5e20..3db3685a7ad 100644 --- a/jstests/concurrency/fsm_workloads/map_reduce_replace.js +++ b/jstests/concurrency/fsm_workloads/map_reduce_replace.js @@ -15,45 +15,43 @@ load('jstests/concurrency/fsm_libs/extend_workload.js'); // for extendWo load('jstests/concurrency/fsm_workloads/map_reduce_inline.js'); // for $config load('jstests/concurrency/fsm_workload_helpers/drop_utils.js'); // for dropCollections -var $config = - extendWorkload($config, - function($config, $super) { - - // Use the workload name as a prefix for the collection name, - // since the workload name is assumed to be unique. - var prefix = 'map_reduce_replace'; - - function uniqueCollectionName(prefix, tid) { - return prefix + tid; - } - - $config.states.init = function init(db, collName) { - $super.states.init.apply(this, arguments); - - this.outCollName = uniqueCollectionName(prefix, this.tid); - assertAlways.commandWorked(db.createCollection(this.outCollName)); - }; - - $config.states.mapReduce = function mapReduce(db, collName) { - var fullName = db[this.outCollName].getFullName(); - assertAlways(db[this.outCollName].exists() !== null, - "output collection '" + fullName + "' should exist"); - - var options = { - finalize: this.finalizer, - out: {replace: this.outCollName}, - query: {key: {$exists: true}, value: {$exists: true}}, - sort: {_id: -1} // sort key must be an existing index - }; - - var res = db[collName].mapReduce(this.mapper, this.reducer, options); - assertAlways.commandWorked(res); - }; - - $config.teardown = function teardown(db, collName, cluster) { - var pattern = new RegExp('^' + prefix + '\\d+$'); - dropCollections(db, pattern); - }; - - return $config; - }); +var $config = extendWorkload($config, function($config, $super) { + + // Use the workload name as a prefix for the collection name, + // since the workload name is assumed to be unique. + var prefix = 'map_reduce_replace'; + + function uniqueCollectionName(prefix, tid) { + return prefix + tid; + } + + $config.states.init = function init(db, collName) { + $super.states.init.apply(this, arguments); + + this.outCollName = uniqueCollectionName(prefix, this.tid); + assertAlways.commandWorked(db.createCollection(this.outCollName)); + }; + + $config.states.mapReduce = function mapReduce(db, collName) { + var fullName = db[this.outCollName].getFullName(); + assertAlways(db[this.outCollName].exists() !== null, + "output collection '" + fullName + "' should exist"); + + var options = { + finalize: this.finalizer, + out: {replace: this.outCollName}, + query: {key: {$exists: true}, value: {$exists: true}}, + sort: {_id: -1} // sort key must be an existing index + }; + + var res = db[collName].mapReduce(this.mapper, this.reducer, options); + assertAlways.commandWorked(res); + }; + + $config.teardown = function teardown(db, collName, cluster) { + var pattern = new RegExp('^' + prefix + '\\d+$'); + dropCollections(db, pattern); + }; + + return $config; +}); diff --git a/jstests/concurrency/fsm_workloads/map_reduce_replace_nonexistent.js b/jstests/concurrency/fsm_workloads/map_reduce_replace_nonexistent.js index 3bfdb6086de..cb802da7a90 100644 --- a/jstests/concurrency/fsm_workloads/map_reduce_replace_nonexistent.js +++ b/jstests/concurrency/fsm_workloads/map_reduce_replace_nonexistent.js @@ -14,39 +14,37 @@ load('jstests/concurrency/fsm_libs/extend_workload.js'); // for extendWo load('jstests/concurrency/fsm_workloads/map_reduce_inline.js'); // for $config load('jstests/concurrency/fsm_workload_helpers/drop_utils.js'); // for dropCollections -var $config = extendWorkload( - $config, - function($config, $super) { - - // Use the workload name as a prefix for the collection name, - // since the workload name is assumed to be unique. - var prefix = 'map_reduce_replace_nonexistent'; - - function uniqueCollectionName(prefix, tid) { - return prefix + tid; - } - - $config.states.mapReduce = function mapReduce(db, collName) { - var outCollName = uniqueCollectionName(prefix, this.tid); - var fullName = db[outCollName].getFullName(); - assertAlways.isnull(db[outCollName].exists(), - "output collection '" + fullName + "' should not exist"); - - var options = { - finalize: this.finalizer, - out: {replace: outCollName}, - query: {key: {$exists: true}, value: {$exists: true}} - }; - - var res = db[collName].mapReduce(this.mapper, this.reducer, options); - assertAlways.commandWorked(res); - assertAlways(db[outCollName].drop()); +var $config = extendWorkload($config, function($config, $super) { + + // Use the workload name as a prefix for the collection name, + // since the workload name is assumed to be unique. + var prefix = 'map_reduce_replace_nonexistent'; + + function uniqueCollectionName(prefix, tid) { + return prefix + tid; + } + + $config.states.mapReduce = function mapReduce(db, collName) { + var outCollName = uniqueCollectionName(prefix, this.tid); + var fullName = db[outCollName].getFullName(); + assertAlways.isnull(db[outCollName].exists(), + "output collection '" + fullName + "' should not exist"); + + var options = { + finalize: this.finalizer, + out: {replace: outCollName}, + query: {key: {$exists: true}, value: {$exists: true}} }; - $config.teardown = function teardown(db, collName, cluster) { - var pattern = new RegExp('^' + prefix + '\\d+$'); - dropCollections(db, pattern); - }; + var res = db[collName].mapReduce(this.mapper, this.reducer, options); + assertAlways.commandWorked(res); + assertAlways(db[outCollName].drop()); + }; + + $config.teardown = function teardown(db, collName, cluster) { + var pattern = new RegExp('^' + prefix + '\\d+$'); + dropCollections(db, pattern); + }; - return $config; - }); + return $config; +}); diff --git a/jstests/concurrency/fsm_workloads/plan_cache_drop_database.js b/jstests/concurrency/fsm_workloads/plan_cache_drop_database.js index abd1312b7c3..51ec0c3780b 100644 --- a/jstests/concurrency/fsm_workloads/plan_cache_drop_database.js +++ b/jstests/concurrency/fsm_workloads/plan_cache_drop_database.js @@ -40,10 +40,7 @@ var $config = (function() { function count(db, collName) { var coll = db.getSiblingDB(this.dbName)[collName]; - var cmdObj = { - query: {a: 1, b: {$gt: Random.rand()}}, - limit: Random.randInt(10) - }; + var cmdObj = {query: {a: 1, b: {$gt: Random.rand()}}, limit: Random.randInt(10)}; // We can't use assertAlways.commandWorked here because the plan // executor can be killed during the count. @@ -61,17 +58,11 @@ var $config = (function() { populateData(myDB, collName); } - return { - count: count, - dropDB: dropDB - }; + return {count: count, dropDB: dropDB}; })(); - var transitions = { - count: {count: 0.95, dropDB: 0.05}, - dropDB: {count: 0.95, dropDB: 0.05} - }; + var transitions = {count: {count: 0.95, dropDB: 0.05}, dropDB: {count: 0.95, dropDB: 0.05}}; function setup(db, collName, cluster) { var myDB = db.getSiblingDB(this.dbName); diff --git a/jstests/concurrency/fsm_workloads/reindex.js b/jstests/concurrency/fsm_workloads/reindex.js index cec33eddc5f..523e29789e0 100644 --- a/jstests/concurrency/fsm_workloads/reindex.js +++ b/jstests/concurrency/fsm_workloads/reindex.js @@ -62,9 +62,7 @@ var $config = (function() { 'inserted'); var coords = [[[-26, -26], [-26, 26], [26, 26], [26, -26], [-26, -26]]]; - var geoQuery = { - geo: {$geoWithin: {$geometry: {type: 'Polygon', coordinates: coords}}} - }; + var geoQuery = {geo: {$geoWithin: {$geometry: {type: 'Polygon', coordinates: coords}}}}; // We can only perform a geo query when we own the collection and are sure a geo index // is present. The same is true of text queries. @@ -91,12 +89,7 @@ var $config = (function() { assertAlways.commandWorked(res); } - return { - init: init, - createIndexes: createIndexes, - reIndex: reIndex, - query: query - }; + return {init: init, createIndexes: createIndexes, reIndex: reIndex, query: query}; })(); var transitions = { diff --git a/jstests/concurrency/fsm_workloads/reindex_background.js b/jstests/concurrency/fsm_workloads/reindex_background.js index 22db164ae6a..ff5dbc8d4d2 100644 --- a/jstests/concurrency/fsm_workloads/reindex_background.js +++ b/jstests/concurrency/fsm_workloads/reindex_background.js @@ -12,24 +12,22 @@ load('jstests/concurrency/fsm_libs/extend_workload.js'); // for extendWorkload load('jstests/concurrency/fsm_workloads/reindex.js'); // for $config -var $config = - extendWorkload($config, - function($config, $super) { - $config.data.prefix = 'reindex_background'; +var $config = extendWorkload($config, function($config, $super) { + $config.data.prefix = 'reindex_background'; - $config.states.createIndexes = function createIndexes(db, collName) { - var coll = db[this.threadCollName]; + $config.states.createIndexes = function createIndexes(db, collName) { + var coll = db[this.threadCollName]; - // The number of indexes created here is also stored in data.nIndexes - var textResult = coll.ensureIndex({text: 'text'}, {background: true}); - assertAlways.commandWorked(textResult); + // The number of indexes created here is also stored in data.nIndexes + var textResult = coll.ensureIndex({text: 'text'}, {background: true}); + assertAlways.commandWorked(textResult); - var geoResult = coll.ensureIndex({geo: '2dsphere'}, {background: true}); - assertAlways.commandWorked(geoResult); + var geoResult = coll.ensureIndex({geo: '2dsphere'}, {background: true}); + assertAlways.commandWorked(geoResult); - var integerResult = coll.ensureIndex({integer: 1}, {background: true}); - assertAlways.commandWorked(integerResult); - }; + var integerResult = coll.ensureIndex({integer: 1}, {background: true}); + assertAlways.commandWorked(integerResult); + }; - return $config; - }); + return $config; +}); diff --git a/jstests/concurrency/fsm_workloads/remove_and_bulk_insert.js b/jstests/concurrency/fsm_workloads/remove_and_bulk_insert.js index a57e61a44b0..63e179a0d2b 100644 --- a/jstests/concurrency/fsm_workloads/remove_and_bulk_insert.js +++ b/jstests/concurrency/fsm_workloads/remove_and_bulk_insert.js @@ -26,10 +26,7 @@ var $config = (function() { } }; - var transitions = { - insert: {insert: 0.5, remove: 0.5}, - remove: {insert: 0.5, remove: 0.5} - }; + var transitions = {insert: {insert: 0.5, remove: 0.5}, remove: {insert: 0.5, remove: 0.5}}; return { threadCount: 5, diff --git a/jstests/concurrency/fsm_workloads/remove_multiple_documents.js b/jstests/concurrency/fsm_workloads/remove_multiple_documents.js index d809b0be8e3..bfd64cd6790 100644 --- a/jstests/concurrency/fsm_workloads/remove_multiple_documents.js +++ b/jstests/concurrency/fsm_workloads/remove_multiple_documents.js @@ -34,17 +34,8 @@ var $config = (function() { } }; - var transitions = { - init: {count: 1}, - count: {remove: 1}, - remove: {remove: 0.825, count: 0.125} - }; + var transitions = {init: {count: 1}, count: {remove: 1}, remove: {remove: 0.825, count: 0.125}}; - return { - threadCount: 10, - iterations: 20, - states: states, - transitions: transitions - }; + return {threadCount: 10, iterations: 20, states: states, transitions: transitions}; })(); diff --git a/jstests/concurrency/fsm_workloads/remove_single_document.js b/jstests/concurrency/fsm_workloads/remove_single_document.js index 5f83e0f57f8..1bfdb2b6897 100644 --- a/jstests/concurrency/fsm_workloads/remove_single_document.js +++ b/jstests/concurrency/fsm_workloads/remove_single_document.js @@ -23,9 +23,7 @@ var $config = (function() { } }; - var transitions = { - remove: {remove: 1} - }; + var transitions = {remove: {remove: 1}}; function setup(db, collName, cluster) { // insert enough documents so that each thread can remove exactly one per iteration diff --git a/jstests/concurrency/fsm_workloads/remove_single_document_eval.js b/jstests/concurrency/fsm_workloads/remove_single_document_eval.js index e90eaa63114..3109c743e29 100644 --- a/jstests/concurrency/fsm_workloads/remove_single_document_eval.js +++ b/jstests/concurrency/fsm_workloads/remove_single_document_eval.js @@ -8,32 +8,30 @@ load('jstests/concurrency/fsm_libs/extend_workload.js'); // for extendWorkload load('jstests/concurrency/fsm_workloads/remove_single_document.js'); // for $config -var $config = - extendWorkload($config, - function($config, $super) { +var $config = extendWorkload($config, function($config, $super) { - $config.data.doRemove = function doRemove(db, collName, query, options) { - var evalResult = db.runCommand({ - eval: function(f, collName, query, options) { - return tojson(f(db, collName, query, options)); - }, - args: [$super.data.doRemove, collName, query, options], - nolock: this.nolock - }); - assertAlways.commandWorked(evalResult); - var res = JSON.parse(evalResult.retval); - return res; - }; + $config.data.doRemove = function doRemove(db, collName, query, options) { + var evalResult = db.runCommand({ + eval: function(f, collName, query, options) { + return tojson(f(db, collName, query, options)); + }, + args: [$super.data.doRemove, collName, query, options], + nolock: this.nolock + }); + assertAlways.commandWorked(evalResult); + var res = JSON.parse(evalResult.retval); + return res; + }; - $config.data.assertResult = function assertResult(res) { - assertWhenOwnColl.eq(1, res.nRemoved, tojson(res)); - }; + $config.data.assertResult = function assertResult(res) { + assertWhenOwnColl.eq(1, res.nRemoved, tojson(res)); + }; - $config.data.nolock = false; + $config.data.nolock = false; - // scale down threadCount and iterations because eval takes a global lock - $config.threadCount = 5; - $config.iterations = 10; + // scale down threadCount and iterations because eval takes a global lock + $config.threadCount = 5; + $config.iterations = 10; - return $config; - }); + return $config; +}); diff --git a/jstests/concurrency/fsm_workloads/remove_single_document_eval_nolock.js b/jstests/concurrency/fsm_workloads/remove_single_document_eval_nolock.js index e88868c3345..a3f67c26892 100644 --- a/jstests/concurrency/fsm_workloads/remove_single_document_eval_nolock.js +++ b/jstests/concurrency/fsm_workloads/remove_single_document_eval_nolock.js @@ -8,10 +8,9 @@ load('jstests/concurrency/fsm_libs/extend_workload.js'); // for extendWorkload load('jstests/concurrency/fsm_workloads/remove_single_document_eval.js'); // for $config -var $config = extendWorkload($config, - function($config, $super) { +var $config = extendWorkload($config, function($config, $super) { - $config.data.nolock = true; + $config.data.nolock = true; - return $config; - }); + return $config; +}); diff --git a/jstests/concurrency/fsm_workloads/remove_where.js b/jstests/concurrency/fsm_workloads/remove_where.js index 36e228ebd9a..f9c0e6a2c03 100644 --- a/jstests/concurrency/fsm_workloads/remove_where.js +++ b/jstests/concurrency/fsm_workloads/remove_where.js @@ -11,37 +11,32 @@ load('jstests/concurrency/fsm_libs/extend_workload.js'); // for extendWorkload load('jstests/concurrency/fsm_workloads/indexed_insert_where.js'); // for $config -var $config = extendWorkload( - $config, - function($config, $super) { - $config.data.randomBound = 10; - $config.data.generateDocumentToInsert = function generateDocumentToInsert() { - return { - tid: this.tid, - x: Random.randInt(this.randomBound) - }; - }; +var $config = extendWorkload($config, function($config, $super) { + $config.data.randomBound = 10; + $config.data.generateDocumentToInsert = function generateDocumentToInsert() { + return {tid: this.tid, x: Random.randInt(this.randomBound)}; + }; - $config.states.remove = function remove(db, collName) { - var res = db[collName].remove({ - // Server-side JS does not support Random.randInt, so use Math.floor/random instead - $where: 'this.x === Math.floor(Math.random() * ' + this.randomBound + ') ' + - '&& this.tid === ' + this.tid - }); - assertWhenOwnColl.gte(res.nRemoved, 0); - assertWhenOwnColl.lte(res.nRemoved, this.insertedDocuments); - this.insertedDocuments -= res.nRemoved; - }; + $config.states.remove = function remove(db, collName) { + var res = db[collName].remove({ + // Server-side JS does not support Random.randInt, so use Math.floor/random instead + $where: 'this.x === Math.floor(Math.random() * ' + this.randomBound + ') ' + + '&& this.tid === ' + this.tid + }); + assertWhenOwnColl.gte(res.nRemoved, 0); + assertWhenOwnColl.lte(res.nRemoved, this.insertedDocuments); + this.insertedDocuments -= res.nRemoved; + }; - $config.transitions = { - insert: {insert: 0.2, remove: 0.4, query: 0.4}, - remove: {insert: 0.4, remove: 0.2, query: 0.4}, - query: {insert: 0.4, remove: 0.4, query: 0.2} - }; + $config.transitions = { + insert: {insert: 0.2, remove: 0.4, query: 0.4}, + remove: {insert: 0.4, remove: 0.2, query: 0.4}, + query: {insert: 0.4, remove: 0.4, query: 0.2} + }; - $config.setup = function setup(db, collName, cluster) { - /* no-op to prevent index from being created */ - }; + $config.setup = function setup(db, collName, cluster) { + /* no-op to prevent index from being created */ + }; - return $config; - }); + return $config; +}); diff --git a/jstests/concurrency/fsm_workloads/rename_capped_collection_chain.js b/jstests/concurrency/fsm_workloads/rename_capped_collection_chain.js index b02642cb4c2..cc3de60d3c0 100644 --- a/jstests/concurrency/fsm_workloads/rename_capped_collection_chain.js +++ b/jstests/concurrency/fsm_workloads/rename_capped_collection_chain.js @@ -27,10 +27,7 @@ var $config = (function() { this.fromCollName = uniqueCollectionName(this.prefix, this.tid, 0); this.num = 1; - var options = { - capped: true, - size: 4096 - }; + var options = {capped: true, size: 4096}; assertAlways.commandWorked(db.createCollection(this.fromCollName, options)); assertWhenOwnDB(db[this.fromCollName].isCapped()); @@ -44,17 +41,11 @@ var $config = (function() { this.fromCollName = toCollName; } - return { - init: init, - rename: rename - }; + return {init: init, rename: rename}; })(); - var transitions = { - init: {rename: 1}, - rename: {rename: 1} - }; + var transitions = {init: {rename: 1}, rename: {rename: 1}}; function teardown(db, collName, cluster) { var pattern = new RegExp('^' + this.prefix + '\\d+_\\d+$'); diff --git a/jstests/concurrency/fsm_workloads/rename_capped_collection_dbname_chain.js b/jstests/concurrency/fsm_workloads/rename_capped_collection_dbname_chain.js index d69bb975d62..93d52f8c251 100644 --- a/jstests/concurrency/fsm_workloads/rename_capped_collection_dbname_chain.js +++ b/jstests/concurrency/fsm_workloads/rename_capped_collection_dbname_chain.js @@ -28,10 +28,7 @@ var $config = (function() { this.num = 1; var fromDB = db.getSiblingDB(this.fromDBName); - var options = { - capped: true, - size: 4096 - }; + var options = {capped: true, size: 4096}; assertAlways.commandWorked(fromDB.createCollection(collName, options)); assertAlways(fromDB[collName].isCapped()); @@ -57,17 +54,11 @@ var $config = (function() { this.fromDBName = toDBName; } - return { - init: init, - rename: rename - }; + return {init: init, rename: rename}; })(); - var transitions = { - init: {rename: 1}, - rename: {rename: 1} - }; + var transitions = {init: {rename: 1}, rename: {rename: 1}}; function teardown(db, collName, cluster) { var pattern = new RegExp('^' + db.getName() + this.prefix + '\\d+_\\d+$'); diff --git a/jstests/concurrency/fsm_workloads/rename_capped_collection_dbname_droptarget.js b/jstests/concurrency/fsm_workloads/rename_capped_collection_dbname_droptarget.js index 06930a0457c..b1c4c156c3f 100644 --- a/jstests/concurrency/fsm_workloads/rename_capped_collection_dbname_droptarget.js +++ b/jstests/concurrency/fsm_workloads/rename_capped_collection_dbname_droptarget.js @@ -19,10 +19,7 @@ var $config = (function() { var states = (function() { - var options = { - capped: true, - size: 4096 - }; + var options = {capped: true, size: 4096}; function uniqueDBName(prefix, tid, num) { return prefix + tid + '_' + num; @@ -80,17 +77,11 @@ var $config = (function() { this.toDBName = temp; } - return { - init: init, - rename: rename - }; + return {init: init, rename: rename}; })(); - var transitions = { - init: {rename: 1}, - rename: {rename: 1} - }; + var transitions = {init: {rename: 1}, rename: {rename: 1}}; function teardown(db, collName, cluster) { var pattern = new RegExp('^' + db.getName() + this.prefix + '\\d+_\\d+$'); diff --git a/jstests/concurrency/fsm_workloads/rename_capped_collection_droptarget.js b/jstests/concurrency/fsm_workloads/rename_capped_collection_droptarget.js index 11621a0318b..1d6dfd6faf4 100644 --- a/jstests/concurrency/fsm_workloads/rename_capped_collection_droptarget.js +++ b/jstests/concurrency/fsm_workloads/rename_capped_collection_droptarget.js @@ -19,10 +19,7 @@ var $config = (function() { var states = (function() { - var options = { - capped: true, - size: 4096 - }; + var options = {capped: true, size: 4096}; function uniqueCollectionName(prefix, tid, num) { return prefix + tid + '_' + num; @@ -72,17 +69,11 @@ var $config = (function() { this.toCollName = temp; } - return { - init: init, - rename: rename - }; + return {init: init, rename: rename}; })(); - var transitions = { - init: {rename: 1}, - rename: {rename: 1} - }; + var transitions = {init: {rename: 1}, rename: {rename: 1}}; function teardown(db, collName, cluster) { var pattern = new RegExp('^' + this.prefix + '\\d+_\\d+$'); diff --git a/jstests/concurrency/fsm_workloads/rename_collection_chain.js b/jstests/concurrency/fsm_workloads/rename_collection_chain.js index 81c0313e217..eb6792f6df8 100644 --- a/jstests/concurrency/fsm_workloads/rename_collection_chain.js +++ b/jstests/concurrency/fsm_workloads/rename_collection_chain.js @@ -36,17 +36,11 @@ var $config = (function() { this.fromCollName = toCollName; } - return { - init: init, - rename: rename - }; + return {init: init, rename: rename}; })(); - var transitions = { - init: {rename: 1}, - rename: {rename: 1} - }; + var transitions = {init: {rename: 1}, rename: {rename: 1}}; function teardown(db, collName, cluster) { var pattern = new RegExp('^' + this.prefix + '\\d+_\\d+$'); diff --git a/jstests/concurrency/fsm_workloads/rename_collection_dbname_chain.js b/jstests/concurrency/fsm_workloads/rename_collection_dbname_chain.js index d11dfd19d22..bf76caa5014 100644 --- a/jstests/concurrency/fsm_workloads/rename_collection_dbname_chain.js +++ b/jstests/concurrency/fsm_workloads/rename_collection_dbname_chain.js @@ -49,17 +49,11 @@ var $config = (function() { this.fromDBName = toDBName; } - return { - init: init, - rename: rename - }; + return {init: init, rename: rename}; })(); - var transitions = { - init: {rename: 1}, - rename: {rename: 1} - }; + var transitions = {init: {rename: 1}, rename: {rename: 1}}; function teardown(db, collName, cluster) { var pattern = new RegExp('^' + db.getName() + this.prefix + '\\d+_\\d+$'); diff --git a/jstests/concurrency/fsm_workloads/rename_collection_dbname_droptarget.js b/jstests/concurrency/fsm_workloads/rename_collection_dbname_droptarget.js index 453d5a27379..7f23ecbc2d7 100644 --- a/jstests/concurrency/fsm_workloads/rename_collection_dbname_droptarget.js +++ b/jstests/concurrency/fsm_workloads/rename_collection_dbname_droptarget.js @@ -72,17 +72,11 @@ var $config = (function() { this.toDBName = temp; } - return { - init: init, - rename: rename - }; + return {init: init, rename: rename}; })(); - var transitions = { - init: {rename: 1}, - rename: {rename: 1} - }; + var transitions = {init: {rename: 1}, rename: {rename: 1}}; function teardown(db, collName, cluster) { var pattern = new RegExp('^' + db.getName() + this.prefix + '\\d+_\\d+$'); diff --git a/jstests/concurrency/fsm_workloads/rename_collection_droptarget.js b/jstests/concurrency/fsm_workloads/rename_collection_droptarget.js index bb2651258a5..592654ed3b1 100644 --- a/jstests/concurrency/fsm_workloads/rename_collection_droptarget.js +++ b/jstests/concurrency/fsm_workloads/rename_collection_droptarget.js @@ -64,17 +64,11 @@ var $config = (function() { this.toCollName = temp; } - return { - init: init, - rename: rename - }; + return {init: init, rename: rename}; })(); - var transitions = { - init: {rename: 1}, - rename: {rename: 1} - }; + var transitions = {init: {rename: 1}, rename: {rename: 1}}; function teardown(db, collName, cluster) { var pattern = new RegExp('^' + this.prefix + '\\d+_\\d+$'); diff --git a/jstests/concurrency/fsm_workloads/server_status.js b/jstests/concurrency/fsm_workloads/server_status.js index dbde1420b99..fa3c8cbbeef 100644 --- a/jstests/concurrency/fsm_workloads/server_status.js +++ b/jstests/concurrency/fsm_workloads/server_status.js @@ -9,23 +9,15 @@ var $config = (function() { var states = { status: function status(db, collName) { - var opts = { - opcounterRepl: 1, - oplog: 1, - rangeDeleter: 1, - repl: 1, - security: 1, - tcmalloc: 1 - }; + var opts = + {opcounterRepl: 1, oplog: 1, rangeDeleter: 1, repl: 1, security: 1, tcmalloc: 1}; var res = db.serverStatus(); assertAlways.commandWorked(res); assertAlways(res.hasOwnProperty('version')); } }; - var transitions = { - status: {status: 1} - }; + var transitions = {status: {status: 1}}; return { threadCount: 10, diff --git a/jstests/concurrency/fsm_workloads/touch_base.js b/jstests/concurrency/fsm_workloads/touch_base.js index df419e17db7..d69b7c94b2e 100644 --- a/jstests/concurrency/fsm_workloads/touch_base.js +++ b/jstests/concurrency/fsm_workloads/touch_base.js @@ -12,52 +12,42 @@ load('jstests/concurrency/fsm_workloads/indexed_insert_where.js'); // for $conf // For isMongod, isMMAPv1, and isEphemeral. load('jstests/concurrency/fsm_workload_helpers/server_types.js'); -var $config = - extendWorkload($config, - function($config, $super) { - $config.data.generateDocumentToInsert = function generateDocumentToInsert() { - return { - tid: this.tid, - x: Random.randInt(10) - }; - }; - - $config.data.generateTouchCmdObj = function generateTouchCmdObj(collName) { - return { - touch: collName, - data: true, - index: true - }; - }; - - $config.states.touch = function touch(db, collName) { - var res = db.runCommand(this.generateTouchCmdObj(collName)); - if (isMongod(db) && (isMMAPv1(db) || isEphemeral(db))) { - assertAlways.commandWorked(res); - } else { - // SERVER-16850 and SERVER-16797 - assertAlways.commandFailed(res); - } - }; - - $config.states.query = function query(db, collName) { - var count = db[collName].find({tid: this.tid}).itcount(); - assertWhenOwnColl.eq( - count, - this.insertedDocuments, - 'collection scan should return the number of documents this thread' + - ' inserted'); - }; - - $config.transitions = { - insert: {insert: 0.2, touch: 0.4, query: 0.4}, - touch: {insert: 0.4, touch: 0.2, query: 0.4}, - query: {insert: 0.4, touch: 0.4, query: 0.2} - }; - - $config.setup = function setup(db, collName, cluster) { - assertAlways.commandWorked(db[collName].ensureIndex({x: 1})); - }; - - return $config; - }); +var $config = extendWorkload($config, function($config, $super) { + $config.data.generateDocumentToInsert = function generateDocumentToInsert() { + return {tid: this.tid, x: Random.randInt(10)}; + }; + + $config.data.generateTouchCmdObj = function generateTouchCmdObj(collName) { + return {touch: collName, data: true, index: true}; + }; + + $config.states.touch = function touch(db, collName) { + var res = db.runCommand(this.generateTouchCmdObj(collName)); + if (isMongod(db) && (isMMAPv1(db) || isEphemeral(db))) { + assertAlways.commandWorked(res); + } else { + // SERVER-16850 and SERVER-16797 + assertAlways.commandFailed(res); + } + }; + + $config.states.query = function query(db, collName) { + var count = db[collName].find({tid: this.tid}).itcount(); + assertWhenOwnColl.eq(count, + this.insertedDocuments, + 'collection scan should return the number of documents this thread' + + ' inserted'); + }; + + $config.transitions = { + insert: {insert: 0.2, touch: 0.4, query: 0.4}, + touch: {insert: 0.4, touch: 0.2, query: 0.4}, + query: {insert: 0.4, touch: 0.4, query: 0.2} + }; + + $config.setup = function setup(db, collName, cluster) { + assertAlways.commandWorked(db[collName].ensureIndex({x: 1})); + }; + + return $config; +}); diff --git a/jstests/concurrency/fsm_workloads/touch_data.js b/jstests/concurrency/fsm_workloads/touch_data.js index dc3b7cecef0..11d2e53cdb6 100644 --- a/jstests/concurrency/fsm_workloads/touch_data.js +++ b/jstests/concurrency/fsm_workloads/touch_data.js @@ -10,16 +10,10 @@ load('jstests/concurrency/fsm_libs/extend_workload.js'); // for extendWorkload load('jstests/concurrency/fsm_workloads/touch_base.js'); // for $config -var $config = - extendWorkload($config, - function($config, $super) { - $config.data.generateTouchCmdObj = function generateTouchCmdObj(collName) { - return { - touch: collName, - data: true, - index: false - }; - }; +var $config = extendWorkload($config, function($config, $super) { + $config.data.generateTouchCmdObj = function generateTouchCmdObj(collName) { + return {touch: collName, data: true, index: false}; + }; - return $config; - }); + return $config; +}); diff --git a/jstests/concurrency/fsm_workloads/touch_index.js b/jstests/concurrency/fsm_workloads/touch_index.js index cc0b6fcf48d..b4e47835073 100644 --- a/jstests/concurrency/fsm_workloads/touch_index.js +++ b/jstests/concurrency/fsm_workloads/touch_index.js @@ -10,16 +10,10 @@ load('jstests/concurrency/fsm_libs/extend_workload.js'); // for extendWorkload load('jstests/concurrency/fsm_workloads/touch_base.js'); // for $config -var $config = - extendWorkload($config, - function($config, $super) { - $config.data.generateTouchCmdObj = function generateTouchCmdObj(collName) { - return { - touch: collName, - data: false, - index: true - }; - }; +var $config = extendWorkload($config, function($config, $super) { + $config.data.generateTouchCmdObj = function generateTouchCmdObj(collName) { + return {touch: collName, data: false, index: true}; + }; - return $config; - }); + return $config; +}); diff --git a/jstests/concurrency/fsm_workloads/touch_no_data_no_index.js b/jstests/concurrency/fsm_workloads/touch_no_data_no_index.js index 25ce50fc5ac..14c3e81993d 100644 --- a/jstests/concurrency/fsm_workloads/touch_no_data_no_index.js +++ b/jstests/concurrency/fsm_workloads/touch_no_data_no_index.js @@ -10,22 +10,16 @@ load('jstests/concurrency/fsm_libs/extend_workload.js'); // for extendWorkload load('jstests/concurrency/fsm_workloads/touch_base.js'); // for $config -var $config = - extendWorkload($config, - function($config, $super) { - $config.data.generateTouchCmdObj = function generateTouchCmdObj(collName) { - return { - touch: collName, - data: false, - index: false - }; - }; +var $config = extendWorkload($config, function($config, $super) { + $config.data.generateTouchCmdObj = function generateTouchCmdObj(collName) { + return {touch: collName, data: false, index: false}; + }; - $config.states.touch = function touch(db, collName) { - var res = db.runCommand(this.generateTouchCmdObj(collName)); - // The command always fails because "index" and "data" are both false - assertAlways.commandFailed(res); - }; + $config.states.touch = function touch(db, collName) { + var res = db.runCommand(this.generateTouchCmdObj(collName)); + // The command always fails because "index" and "data" are both false + assertAlways.commandFailed(res); + }; - return $config; - }); + return $config; +}); diff --git a/jstests/concurrency/fsm_workloads/update_and_bulk_insert.js b/jstests/concurrency/fsm_workloads/update_and_bulk_insert.js index 5d59ff2b0ef..dde8b4b7093 100644 --- a/jstests/concurrency/fsm_workloads/update_and_bulk_insert.js +++ b/jstests/concurrency/fsm_workloads/update_and_bulk_insert.js @@ -31,10 +31,7 @@ var $config = (function() { } }; - var transitions = { - insert: {insert: 0.2, update: 0.8}, - update: {insert: 0.2, update: 0.8} - }; + var transitions = {insert: {insert: 0.2, update: 0.8}, update: {insert: 0.2, update: 0.8}}; return { threadCount: 5, diff --git a/jstests/concurrency/fsm_workloads/update_array.js b/jstests/concurrency/fsm_workloads/update_array.js index 192626c2430..2020ee3c60a 100644 --- a/jstests/concurrency/fsm_workloads/update_array.js +++ b/jstests/concurrency/fsm_workloads/update_array.js @@ -110,10 +110,7 @@ var $config = (function() { })(); - var transitions = { - push: {push: 0.8, pull: 0.2}, - pull: {push: 0.8, pull: 0.2} - }; + var transitions = {push: {push: 0.8, pull: 0.2}, pull: {push: 0.8, pull: 0.2}}; function setup(db, collName, cluster) { // index on 'arr', the field being updated diff --git a/jstests/concurrency/fsm_workloads/update_check_index.js b/jstests/concurrency/fsm_workloads/update_check_index.js index 3e099d6b2a5..bd82e39c471 100644 --- a/jstests/concurrency/fsm_workloads/update_check_index.js +++ b/jstests/concurrency/fsm_workloads/update_check_index.js @@ -15,14 +15,10 @@ var $config = (function() { db[collName].update({a: 1, b: 1}, {$set: {c: newC}}, {multi: true}); } - return { - multiUpdate: multiUpdate - }; + return {multiUpdate: multiUpdate}; })(); - var transitions = { - multiUpdate: {multiUpdate: 1.0} - }; + var transitions = {multiUpdate: {multiUpdate: 1.0}}; function setup(db, collName, cluster) { assertAlways.commandWorked(db[collName].ensureIndex({a: 1})); diff --git a/jstests/concurrency/fsm_workloads/update_inc.js b/jstests/concurrency/fsm_workloads/update_inc.js index f16d841d3bb..a8328c26703 100644 --- a/jstests/concurrency/fsm_workloads/update_inc.js +++ b/jstests/concurrency/fsm_workloads/update_inc.js @@ -27,9 +27,7 @@ var $config = (function() { }, update: function update(db, collName) { - var updateDoc = { - $inc: {} - }; + var updateDoc = {$inc: {}}; updateDoc.$inc[this.fieldName] = 1; var res = db[collName].update({_id: this.id}, updateDoc); @@ -74,16 +72,10 @@ var $config = (function() { } }; - var transitions = { - init: {update: 1}, - update: {find: 1}, - find: {update: 1} - }; + var transitions = {init: {update: 1}, update: {find: 1}, find: {update: 1}}; function setup(db, collName, cluster) { - var doc = { - _id: this.id - }; + var doc = {_id: this.id}; // Pre-populate the fields we need to avoid size change for capped collections. for (var i = 0; i < this.threadCount; ++i) { diff --git a/jstests/concurrency/fsm_workloads/update_multifield.js b/jstests/concurrency/fsm_workloads/update_multifield.js index 1f62472f754..7428c289c98 100644 --- a/jstests/concurrency/fsm_workloads/update_multifield.js +++ b/jstests/concurrency/fsm_workloads/update_multifield.js @@ -35,15 +35,9 @@ var $config = (function() { var push = Random.rand() > 0.2; var updateDoc = {}; - updateDoc[set ? '$set' : '$unset'] = { - x: x - }; - updateDoc[push ? '$push' : '$pull'] = { - y: y - }; - updateDoc.$inc = { - z: z - }; + updateDoc[set ? '$set' : '$unset'] = {x: x}; + updateDoc[push ? '$push' : '$pull'] = {y: y}; + updateDoc.$inc = {z: z}; return updateDoc; } @@ -61,9 +55,7 @@ var $config = (function() { } }; - var transitions = { - update: {update: 1} - }; + var transitions = {update: {update: 1}}; function setup(db, collName, cluster) { assertAlways.commandWorked(db[collName].ensureIndex({x: 1})); diff --git a/jstests/concurrency/fsm_workloads/update_multifield_isolated_multiupdate.js b/jstests/concurrency/fsm_workloads/update_multifield_isolated_multiupdate.js index 3dd8b584d98..8d95deac710 100644 --- a/jstests/concurrency/fsm_workloads/update_multifield_isolated_multiupdate.js +++ b/jstests/concurrency/fsm_workloads/update_multifield_isolated_multiupdate.js @@ -9,32 +9,30 @@ load('jstests/concurrency/fsm_libs/extend_workload.js'); // for extendWorkload load('jstests/concurrency/fsm_workloads/update_multifield.js'); // for $config -var $config = - extendWorkload($config, - function($config, $super) { +var $config = extendWorkload($config, function($config, $super) { - $config.data.multi = true; - $config.data.isolated = true; + $config.data.multi = true; + $config.data.isolated = true; - $config.data.assertResult = function assertResult(res, db, collName, query) { - assertAlways.eq(0, res.nUpserted, tojson(res)); - // documents can't move during an update, because we use $isolated - assertWhenOwnColl.eq(this.numDocs, res.nMatched, tojson(res)); - if (db.getMongo().writeMode() === 'commands') { - assertWhenOwnColl.eq(this.numDocs, res.nModified, tojson(res)); - } + $config.data.assertResult = function assertResult(res, db, collName, query) { + assertAlways.eq(0, res.nUpserted, tojson(res)); + // documents can't move during an update, because we use $isolated + assertWhenOwnColl.eq(this.numDocs, res.nMatched, tojson(res)); + if (db.getMongo().writeMode() === 'commands') { + assertWhenOwnColl.eq(this.numDocs, res.nModified, tojson(res)); + } - // every thread only increments z, and z starts at 0, - // so z should always be strictly greater than 0 after an update, - // even if other threads modify the doc. - var docs = db[collName].find().toArray(); - assertWhenOwnColl(function() { - docs.forEach(function(doc) { - assertWhenOwnColl.eq('number', typeof doc.z); - assertWhenOwnColl.gt(doc.z, 0); - }); - }); - }; + // every thread only increments z, and z starts at 0, + // so z should always be strictly greater than 0 after an update, + // even if other threads modify the doc. + var docs = db[collName].find().toArray(); + assertWhenOwnColl(function() { + docs.forEach(function(doc) { + assertWhenOwnColl.eq('number', typeof doc.z); + assertWhenOwnColl.gt(doc.z, 0); + }); + }); + }; - return $config; - }); + return $config; +}); diff --git a/jstests/concurrency/fsm_workloads/update_multifield_multiupdate.js b/jstests/concurrency/fsm_workloads/update_multifield_multiupdate.js index 2cc975085ca..2ca02e2f38e 100644 --- a/jstests/concurrency/fsm_workloads/update_multifield_multiupdate.js +++ b/jstests/concurrency/fsm_workloads/update_multifield_multiupdate.js @@ -12,40 +12,38 @@ load('jstests/concurrency/fsm_workloads/update_multifield.js'); // for $config // For isMongod and recordIdCanChangeOnUpdate. load('jstests/concurrency/fsm_workload_helpers/server_types.js'); -var $config = - extendWorkload($config, - function($config, $super) { - - $config.data.multi = true; - - $config.data.assertResult = function(res, db, collName, query) { - assertAlways.eq(0, res.nUpserted, tojson(res)); - - if (isMongod(db)) { - if (!recordIdCanChangeOnUpdate(db)) { - // If a document's RecordId cannot change, then we should not - // have updated any document more than once, since the update - // stage internally de-duplicates based on RecordId. - assertWhenOwnColl.lte(this.numDocs, res.nMatched, tojson(res)); - } else { - // If RecordIds can change, then there are no guarantees on how - // many documents were updated. - assertAlways.gte(res.nMatched, 0, tojson(res)); - } - } else { // mongos - assertAlways.gte(res.nMatched, 0, tojson(res)); - } - - if (db.getMongo().writeMode() === 'commands') { - assertWhenOwnColl.eq(res.nMatched, res.nModified, tojson(res)); - } - - var docs = db[collName].find().toArray(); - docs.forEach(function(doc) { - assertWhenOwnColl.eq('number', typeof doc.z); - assertWhenOwnColl.gt(doc.z, 0); - }); - }; - - return $config; - }); +var $config = extendWorkload($config, function($config, $super) { + + $config.data.multi = true; + + $config.data.assertResult = function(res, db, collName, query) { + assertAlways.eq(0, res.nUpserted, tojson(res)); + + if (isMongod(db)) { + if (!recordIdCanChangeOnUpdate(db)) { + // If a document's RecordId cannot change, then we should not + // have updated any document more than once, since the update + // stage internally de-duplicates based on RecordId. + assertWhenOwnColl.lte(this.numDocs, res.nMatched, tojson(res)); + } else { + // If RecordIds can change, then there are no guarantees on how + // many documents were updated. + assertAlways.gte(res.nMatched, 0, tojson(res)); + } + } else { // mongos + assertAlways.gte(res.nMatched, 0, tojson(res)); + } + + if (db.getMongo().writeMode() === 'commands') { + assertWhenOwnColl.eq(res.nMatched, res.nModified, tojson(res)); + } + + var docs = db[collName].find().toArray(); + docs.forEach(function(doc) { + assertWhenOwnColl.eq('number', typeof doc.z); + assertWhenOwnColl.gt(doc.z, 0); + }); + }; + + return $config; +}); diff --git a/jstests/concurrency/fsm_workloads/update_ordered_bulk_inc.js b/jstests/concurrency/fsm_workloads/update_ordered_bulk_inc.js index 0d6b4651a5d..45a079091e0 100644 --- a/jstests/concurrency/fsm_workloads/update_ordered_bulk_inc.js +++ b/jstests/concurrency/fsm_workloads/update_ordered_bulk_inc.js @@ -22,9 +22,7 @@ var $config = (function() { }, update: function update(db, collName) { - var updateDoc = { - $inc: {} - }; + var updateDoc = {$inc: {}}; updateDoc.$inc[this.fieldName] = 1; var bulk = db[collName].initializeOrderedBulkOp(); @@ -74,11 +72,7 @@ var $config = (function() { } }; - var transitions = { - init: {update: 1}, - update: {find: 1}, - find: {update: 1} - }; + var transitions = {init: {update: 1}, update: {find: 1}, find: {update: 1}}; function setup(db, collName, cluster) { this.count = 0; diff --git a/jstests/concurrency/fsm_workloads/update_rename.js b/jstests/concurrency/fsm_workloads/update_rename.js index b163b44f690..ca74ac5287d 100644 --- a/jstests/concurrency/fsm_workloads/update_rename.js +++ b/jstests/concurrency/fsm_workloads/update_rename.js @@ -20,15 +20,11 @@ var $config = (function() { var to = choose(fieldNames.filter(function(n) { return n !== from; })); - var updater = { - $rename: {} - }; + var updater = {$rename: {}}; updater.$rename[from] = to; var query = {}; - query[from] = { - $exists: 1 - }; + query[from] = {$exists: 1}; var res = db[collName].update(query, updater); @@ -40,9 +36,7 @@ var $config = (function() { } }; - var transitions = { - update: {update: 1} - }; + var transitions = {update: {update: 1}}; function setup(db, collName, cluster) { // Create an index on all but one fieldName key to make it possible to test renames diff --git a/jstests/concurrency/fsm_workloads/update_replace.js b/jstests/concurrency/fsm_workloads/update_replace.js index f7edb05126d..2d04f38294c 100644 --- a/jstests/concurrency/fsm_workloads/update_replace.js +++ b/jstests/concurrency/fsm_workloads/update_replace.js @@ -56,9 +56,7 @@ var $config = (function() { } }; - var transitions = { - update: {update: 1} - }; + var transitions = {update: {update: 1}}; function setup(db, collName, cluster) { assertAlways.commandWorked(db[collName].ensureIndex({a: 1})); diff --git a/jstests/concurrency/fsm_workloads/update_simple.js b/jstests/concurrency/fsm_workloads/update_simple.js index 85f877e6090..cb4adf926c9 100644 --- a/jstests/concurrency/fsm_workloads/update_simple.js +++ b/jstests/concurrency/fsm_workloads/update_simple.js @@ -24,10 +24,7 @@ var $config = (function() { } }; - var transitions = { - set: {set: 0.5, unset: 0.5}, - unset: {set: 0.5, unset: 0.5} - }; + var transitions = {set: {set: 0.5, unset: 0.5}, unset: {set: 0.5, unset: 0.5}}; function setup(db, collName, cluster) { // index on 'value', the field being updated @@ -83,13 +80,9 @@ var $config = (function() { var value = Random.randInt(5); var updater = {}; - updater[set ? '$set' : '$unset'] = { - value: value - }; + updater[set ? '$set' : '$unset'] = {value: value}; - var query = { - _id: docIndex - }; + var query = {_id: docIndex}; var res = this.doUpdate(db, collName, query, updater); this.assertResult(db, res); }, diff --git a/jstests/concurrency/fsm_workloads/update_simple_eval.js b/jstests/concurrency/fsm_workloads/update_simple_eval.js index 988c2e44ab3..f8b9115e455 100644 --- a/jstests/concurrency/fsm_workloads/update_simple_eval.js +++ b/jstests/concurrency/fsm_workloads/update_simple_eval.js @@ -12,24 +12,22 @@ load('jstests/concurrency/fsm_libs/extend_workload.js'); // for extendWorkload load('jstests/concurrency/fsm_workloads/update_simple.js'); // for $config -var $config = - extendWorkload($config, - function($config, $super) { +var $config = extendWorkload($config, function($config, $super) { - $config.data.doUpdate = function doUpdate(db, collName, query, updater) { - var evalResult = db.runCommand({ - eval: function(f, collName, query, updater) { - return tojson(f(db, collName, query, updater)); - }, - args: [$super.data.doUpdate, collName, query, updater], - nolock: this.nolock - }); - assertAlways.commandWorked(evalResult); - var res = JSON.parse(evalResult.retval); - return res; - }; + $config.data.doUpdate = function doUpdate(db, collName, query, updater) { + var evalResult = db.runCommand({ + eval: function(f, collName, query, updater) { + return tojson(f(db, collName, query, updater)); + }, + args: [$super.data.doUpdate, collName, query, updater], + nolock: this.nolock + }); + assertAlways.commandWorked(evalResult); + var res = JSON.parse(evalResult.retval); + return res; + }; - $config.data.nolock = false; + $config.data.nolock = false; - return $config; - }); + return $config; +}); diff --git a/jstests/concurrency/fsm_workloads/update_simple_eval_nolock.js b/jstests/concurrency/fsm_workloads/update_simple_eval_nolock.js index 282e98a461d..c5f081088cd 100644 --- a/jstests/concurrency/fsm_workloads/update_simple_eval_nolock.js +++ b/jstests/concurrency/fsm_workloads/update_simple_eval_nolock.js @@ -8,10 +8,9 @@ load('jstests/concurrency/fsm_libs/extend_workload.js'); // for extendWorkload load('jstests/concurrency/fsm_workloads/update_simple_eval.js'); // for $config -var $config = extendWorkload($config, - function($config, $super) { +var $config = extendWorkload($config, function($config, $super) { - $config.data.nolock = true; + $config.data.nolock = true; - return $config; - }); + return $config; +}); diff --git a/jstests/concurrency/fsm_workloads/update_upsert_multi.js b/jstests/concurrency/fsm_workloads/update_upsert_multi.js index 96d83cb5115..61e7f84f2e9 100644 --- a/jstests/concurrency/fsm_workloads/update_upsert_multi.js +++ b/jstests/concurrency/fsm_workloads/update_upsert_multi.js @@ -51,13 +51,10 @@ var $config = (function() { // because docs with lower i are newer, so they have had fewer // opportunities to have n incremented.) var prevN = Infinity; - db[collName] - .find({tid: this.tid}) - .sort({i: 1}) - .forEach(function(doc) { - assertWhenOwnColl.gte(prevN, doc.n); - prevN = doc.n; - }); + db[collName].find({tid: this.tid}).sort({i: 1}).forEach(function(doc) { + assertWhenOwnColl.gte(prevN, doc.n); + prevN = doc.n; + }); } }; diff --git a/jstests/concurrency/fsm_workloads/update_where.js b/jstests/concurrency/fsm_workloads/update_where.js index d7ef045131f..614cbc86093 100644 --- a/jstests/concurrency/fsm_workloads/update_where.js +++ b/jstests/concurrency/fsm_workloads/update_where.js @@ -10,43 +10,38 @@ load('jstests/concurrency/fsm_libs/extend_workload.js'); // for extendWorkload load('jstests/concurrency/fsm_workloads/indexed_insert_where.js'); // for $config -var $config = extendWorkload( - $config, - function($config, $super) { - $config.data.randomBound = 10; - $config.data.generateDocumentToInsert = function generateDocumentToInsert() { - return { - tid: this.tid, - x: Random.randInt(this.randomBound) - }; - }; - - $config.states.update = function update(db, collName) { - var res = db[collName].update( - // Server-side JS does not support Random.randInt, so use Math.floor/random instead - { - $where: 'this.x === Math.floor(Math.random() * ' + this.randomBound + ') ' + - '&& this.tid === ' + this.tid - }, - {$set: {x: Random.randInt(this.randomBound)}}, - {multi: true}); - assertAlways.writeOK(res); - - if (db.getMongo().writeMode() === 'commands') { - assertWhenOwnColl.gte(res.nModified, 0); - assertWhenOwnColl.lte(res.nModified, this.insertedDocuments); - } - }; - - $config.transitions = { - insert: {insert: 0.2, update: 0.4, query: 0.4}, - update: {insert: 0.4, update: 0.2, query: 0.4}, - query: {insert: 0.4, update: 0.4, query: 0.2} - }; - - $config.setup = function setup(db, collName, cluster) { - /* no-op to prevent index from being created */ - }; - - return $config; - }); +var $config = extendWorkload($config, function($config, $super) { + $config.data.randomBound = 10; + $config.data.generateDocumentToInsert = function generateDocumentToInsert() { + return {tid: this.tid, x: Random.randInt(this.randomBound)}; + }; + + $config.states.update = function update(db, collName) { + var res = db[collName].update( + // Server-side JS does not support Random.randInt, so use Math.floor/random instead + { + $where: 'this.x === Math.floor(Math.random() * ' + this.randomBound + ') ' + + '&& this.tid === ' + this.tid + }, + {$set: {x: Random.randInt(this.randomBound)}}, + {multi: true}); + assertAlways.writeOK(res); + + if (db.getMongo().writeMode() === 'commands') { + assertWhenOwnColl.gte(res.nModified, 0); + assertWhenOwnColl.lte(res.nModified, this.insertedDocuments); + } + }; + + $config.transitions = { + insert: {insert: 0.2, update: 0.4, query: 0.4}, + update: {insert: 0.4, update: 0.2, query: 0.4}, + query: {insert: 0.4, update: 0.4, query: 0.2} + }; + + $config.setup = function setup(db, collName, cluster) { + /* no-op to prevent index from being created */ + }; + + return $config; +}); diff --git a/jstests/concurrency/fsm_workloads/upsert_where.js b/jstests/concurrency/fsm_workloads/upsert_where.js index 72ff542c572..7fa00727725 100644 --- a/jstests/concurrency/fsm_workloads/upsert_where.js +++ b/jstests/concurrency/fsm_workloads/upsert_where.js @@ -9,39 +9,34 @@ load('jstests/concurrency/fsm_libs/extend_workload.js'); // for extendWorkload load('jstests/concurrency/fsm_workloads/indexed_insert_where.js'); // for $config -var $config = extendWorkload( - $config, - function($config, $super) { - $config.data.randomBound = 10; - $config.data.generateDocumentToInsert = function generateDocumentToInsert() { - return { - tid: this.tid, - x: Random.randInt(this.randomBound) - }; - }; +var $config = extendWorkload($config, function($config, $super) { + $config.data.randomBound = 10; + $config.data.generateDocumentToInsert = function generateDocumentToInsert() { + return {tid: this.tid, x: Random.randInt(this.randomBound)}; + }; - $config.states.upsert = function upsert(db, collName) { - var res = db[collName].update( - {$where: 'this.x === ' + this.randomBound + ' && this.tid === ' + this.tid}, - {$set: {x: Random.randInt(this.randomBound), tid: this.tid}}, - {upsert: true}); - assertWhenOwnColl.eq(res.nUpserted, 1); - var upsertedDocument = db[collName].findOne({_id: res.getUpsertedId()._id}); - assertWhenOwnColl(function() { - assertWhenOwnColl.eq(upsertedDocument.tid, this.tid); - }.bind(this)); - this.insertedDocuments += res.nUpserted; - }; + $config.states.upsert = function upsert(db, collName) { + var res = db[collName].update( + {$where: 'this.x === ' + this.randomBound + ' && this.tid === ' + this.tid}, + {$set: {x: Random.randInt(this.randomBound), tid: this.tid}}, + {upsert: true}); + assertWhenOwnColl.eq(res.nUpserted, 1); + var upsertedDocument = db[collName].findOne({_id: res.getUpsertedId()._id}); + assertWhenOwnColl(function() { + assertWhenOwnColl.eq(upsertedDocument.tid, this.tid); + }.bind(this)); + this.insertedDocuments += res.nUpserted; + }; - $config.transitions = { - insert: {insert: 0.2, upsert: 0.4, query: 0.4}, - upsert: {insert: 0.4, upsert: 0.2, query: 0.4}, - query: {insert: 0.4, upsert: 0.4, query: 0.2} - }; + $config.transitions = { + insert: {insert: 0.2, upsert: 0.4, query: 0.4}, + upsert: {insert: 0.4, upsert: 0.2, query: 0.4}, + query: {insert: 0.4, upsert: 0.4, query: 0.2} + }; - $config.setup = function setup(db, collName, cluster) { - /* no-op to prevent index from being created */ - }; + $config.setup = function setup(db, collName, cluster) { + /* no-op to prevent index from being created */ + }; - return $config; - }); + return $config; +}); diff --git a/jstests/concurrency/fsm_workloads/yield.js b/jstests/concurrency/fsm_workloads/yield.js index 0ef6aa9b1a0..adbe1076ee6 100644 --- a/jstests/concurrency/fsm_workloads/yield.js +++ b/jstests/concurrency/fsm_workloads/yield.js @@ -44,9 +44,7 @@ var $config = (function() { */ genUpdateDoc: function genUpdateDoc() { var newVal = Random.randInt(this.nDocs); - return { - $set: {a: newVal} - }; + return {$set: {a: newVal}}; } }; diff --git a/jstests/concurrency/fsm_workloads/yield_and_hashed.js b/jstests/concurrency/fsm_workloads/yield_and_hashed.js index 48a14d706e2..f9267b9c020 100644 --- a/jstests/concurrency/fsm_workloads/yield_and_hashed.js +++ b/jstests/concurrency/fsm_workloads/yield_and_hashed.js @@ -9,67 +9,63 @@ load('jstests/concurrency/fsm_libs/extend_workload.js'); // for extendWorkload load('jstests/concurrency/fsm_workloads/yield_rooted_or.js'); // for $config -var $config = extendWorkload( - $config, - function($config, $super) { +var $config = extendWorkload($config, function($config, $super) { - /* - * Issue a query that will use the AND_HASH stage. This is a little tricky, so use - * stagedebug to force it to happen. Unfortunately this means it can't be batched. - */ - $config.states.query = function andHash(db, collName) { - var nMatches = 100; - assertAlways.lte(nMatches, this.nDocs); - // Construct the query plan: two ixscans under an andHashed. - // Scan c <= nMatches - var ixscan1 = { - ixscan: { - args: { - name: 'stages_and_hashed', - keyPattern: {c: 1}, - startKey: {'': nMatches}, - endKey: {}, - endKeyInclusive: true, - direction: -1 - } + /* + * Issue a query that will use the AND_HASH stage. This is a little tricky, so use + * stagedebug to force it to happen. Unfortunately this means it can't be batched. + */ + $config.states.query = function andHash(db, collName) { + var nMatches = 100; + assertAlways.lte(nMatches, this.nDocs); + // Construct the query plan: two ixscans under an andHashed. + // Scan c <= nMatches + var ixscan1 = { + ixscan: { + args: { + name: 'stages_and_hashed', + keyPattern: {c: 1}, + startKey: {'': nMatches}, + endKey: {}, + endKeyInclusive: true, + direction: -1 } - }; + } + }; - // Scan d >= this.nDocs - nMatches - var ixscan2 = { - ixscan: { - args: { - name: 'stages_and_hashed', - keyPattern: {d: 1}, - startKey: {'': this.nDocs - nMatches}, - endKey: {}, - endKeyInclusive: true, - direction: 1 - } + // Scan d >= this.nDocs - nMatches + var ixscan2 = { + ixscan: { + args: { + name: 'stages_and_hashed', + keyPattern: {d: 1}, + startKey: {'': this.nDocs - nMatches}, + endKey: {}, + endKeyInclusive: true, + direction: 1 } - }; - - var andix1ix2 = { - andHash: {args: {nodes: [ixscan1, ixscan2]}} - }; + } + }; - // On non-MMAP storage engines, index intersection plans will always re-filter - // the docs to make sure we don't get any spurious matches. - var fetch = { - fetch: { - filter: {c: {$lte: nMatches}, d: {$gte: (this.nDocs - nMatches)}}, - args: {node: andix1ix2} - } - }; + var andix1ix2 = {andHash: {args: {nodes: [ixscan1, ixscan2]}}}; - var res = db.runCommand({stageDebug: {plan: fetch, collection: collName}}); - assertAlways.commandWorked(res); - for (var i = 0; i < res.results.length; i++) { - var result = res.results[i]; - assertAlways.lte(result.c, nMatches); - assertAlways.gte(result.d, this.nDocs - nMatches); + // On non-MMAP storage engines, index intersection plans will always re-filter + // the docs to make sure we don't get any spurious matches. + var fetch = { + fetch: { + filter: {c: {$lte: nMatches}, d: {$gte: (this.nDocs - nMatches)}}, + args: {node: andix1ix2} } }; - return $config; - }); + var res = db.runCommand({stageDebug: {plan: fetch, collection: collName}}); + assertAlways.commandWorked(res); + for (var i = 0; i < res.results.length; i++) { + var result = res.results[i]; + assertAlways.lte(result.c, nMatches); + assertAlways.gte(result.d, this.nDocs - nMatches); + } + }; + + return $config; +}); diff --git a/jstests/concurrency/fsm_workloads/yield_and_sorted.js b/jstests/concurrency/fsm_workloads/yield_and_sorted.js index 2bea4226ba0..aed15988b10 100644 --- a/jstests/concurrency/fsm_workloads/yield_and_sorted.js +++ b/jstests/concurrency/fsm_workloads/yield_and_sorted.js @@ -9,62 +9,58 @@ load('jstests/concurrency/fsm_libs/extend_workload.js'); // for extendWorkload load('jstests/concurrency/fsm_workloads/yield_rooted_or.js'); // for $config -var $config = extendWorkload( - $config, - function($config, $super) { +var $config = extendWorkload($config, function($config, $super) { - /* - * Issue a query that will use the AND_SORTED stage. This is a little tricky, so use - * stagedebug to force it to happen. Unfortunately this means it can't be batched. - */ - $config.states.query = function andSorted(db, collName) { - // Not very many docs returned in this, so loop to increase chances of yielding in the - // middle. - for (var i = 0; i < 100; i++) { - // Construct the query plan: two ixscans under an andSorted. - // Scan a == 0 - var ixscan1 = { - ixscan: { - args: { - name: 'stages_and_sorted', - keyPattern: {c: 1}, - startKey: {'': 0}, - endKey: {'': 0}, - endKeyInclusive: false, - direction: 1 - } + /* + * Issue a query that will use the AND_SORTED stage. This is a little tricky, so use + * stagedebug to force it to happen. Unfortunately this means it can't be batched. + */ + $config.states.query = function andSorted(db, collName) { + // Not very many docs returned in this, so loop to increase chances of yielding in the + // middle. + for (var i = 0; i < 100; i++) { + // Construct the query plan: two ixscans under an andSorted. + // Scan a == 0 + var ixscan1 = { + ixscan: { + args: { + name: 'stages_and_sorted', + keyPattern: {c: 1}, + startKey: {'': 0}, + endKey: {'': 0}, + endKeyInclusive: false, + direction: 1 } - }; - // Scan b == this.nDocs - var ixscan2 = { - ixscan: { - args: { - name: 'stages_and_sorted', - keyPattern: {d: 1}, - startKey: {'': this.nDocs}, - endKey: {'': this.nDocs}, - endKeyInclusive: false, - direction: -1 - } + } + }; + // Scan b == this.nDocs + var ixscan2 = { + ixscan: { + args: { + name: 'stages_and_sorted', + keyPattern: {d: 1}, + startKey: {'': this.nDocs}, + endKey: {'': this.nDocs}, + endKeyInclusive: false, + direction: -1 } - }; - - // Intersect the two - var andix1ix2 = { - andSorted: {args: {nodes: [ixscan1, ixscan2]}} - }; - var res = db.runCommand({stageDebug: {collection: collName, plan: andix1ix2}}); - assertAlways.commandWorked(res); - for (var j = 0; j < res.results.length; j++) { - var result = res.results[j]; - // These should always be true, since they're just verifying that the results - // match - // the query predicate. - assertAlways.eq(result.c, 0); - assertAlways.eq(result.d, this.nDocs); } + }; + + // Intersect the two + var andix1ix2 = {andSorted: {args: {nodes: [ixscan1, ixscan2]}}}; + var res = db.runCommand({stageDebug: {collection: collName, plan: andix1ix2}}); + assertAlways.commandWorked(res); + for (var j = 0; j < res.results.length; j++) { + var result = res.results[j]; + // These should always be true, since they're just verifying that the results + // match + // the query predicate. + assertAlways.eq(result.c, 0); + assertAlways.eq(result.d, this.nDocs); } - }; + } + }; - return $config; - }); + return $config; +}); diff --git a/jstests/concurrency/fsm_workloads/yield_fetch.js b/jstests/concurrency/fsm_workloads/yield_fetch.js index b3f47a5fe5d..e802635af73 100644 --- a/jstests/concurrency/fsm_workloads/yield_fetch.js +++ b/jstests/concurrency/fsm_workloads/yield_fetch.js @@ -9,24 +9,22 @@ load('jstests/concurrency/fsm_libs/extend_workload.js'); // for extendWorkload load('jstests/concurrency/fsm_workloads/yield_rooted_or.js'); // for $config -var $config = extendWorkload( - $config, - function($config, $super) { +var $config = extendWorkload($config, function($config, $super) { - /* - * Issue a query that will use the FETCH stage. - */ - $config.states.query = function fetch(db, collName) { - var nMatches = 100; + /* + * Issue a query that will use the FETCH stage. + */ + $config.states.query = function fetch(db, collName) { + var nMatches = 100; - var cursor = db[collName].find({c: {$lt: nMatches}}).batchSize(this.batchSize); + var cursor = db[collName].find({c: {$lt: nMatches}}).batchSize(this.batchSize); - var verifier = function fetchVerifier(doc, prevDoc) { - return doc.c < nMatches; - }; - - this.advanceCursor(cursor, verifier); + var verifier = function fetchVerifier(doc, prevDoc) { + return doc.c < nMatches; }; - return $config; - }); + this.advanceCursor(cursor, verifier); + }; + + return $config; +}); diff --git a/jstests/concurrency/fsm_workloads/yield_geo_near.js b/jstests/concurrency/fsm_workloads/yield_geo_near.js index fd13bd31014..3ed79835906 100644 --- a/jstests/concurrency/fsm_workloads/yield_geo_near.js +++ b/jstests/concurrency/fsm_workloads/yield_geo_near.js @@ -8,80 +8,69 @@ load('jstests/concurrency/fsm_libs/extend_workload.js'); // for extendWorkload load('jstests/concurrency/fsm_workloads/yield.js'); // for $config -var $config = extendWorkload( - $config, - function($config, $super) { +var $config = extendWorkload($config, function($config, $super) { - /* - * Use geo $near query to find points near the origin. Note this should be done using the - * geoNear command, rather than a $near query, as the $near query doesn't work in a sharded - * environment. Unfortunately this means we cannot batch the request. - */ - $config.states.query = function geoNear(db, collName) { - // This distance gets about 80 docs around the origin. There is one doc inserted - // every 1m^2 and the area scanned by a 5m radius is PI*(5m)^2 ~ 79. - var maxDistance = 5; + /* + * Use geo $near query to find points near the origin. Note this should be done using the + * geoNear command, rather than a $near query, as the $near query doesn't work in a sharded + * environment. Unfortunately this means we cannot batch the request. + */ + $config.states.query = function geoNear(db, collName) { + // This distance gets about 80 docs around the origin. There is one doc inserted + // every 1m^2 and the area scanned by a 5m radius is PI*(5m)^2 ~ 79. + var maxDistance = 5; - var res = db.runCommand({geoNear: collName, near: [0, 0], maxDistance: maxDistance}); - assertWhenOwnColl.commandWorked(res); // Could fail if more than 1 2d index. - assertWhenOwnColl(function verifyResults() { - var results = res.results; - var prevDoc = { - dis: 0 - }; // distance should never be less than 0 - for (var i = 0; i < results.length; i++) { - var doc = results[i]; - assertAlways.lte(NumberInt(doc.dis), maxDistance); // satisfies query - assertAlways.lte(prevDoc.dis, doc.dis); // returned in the correct order - prevDoc = doc; - } - }); - }; + var res = db.runCommand({geoNear: collName, near: [0, 0], maxDistance: maxDistance}); + assertWhenOwnColl.commandWorked(res); // Could fail if more than 1 2d index. + assertWhenOwnColl(function verifyResults() { + var results = res.results; + var prevDoc = {dis: 0}; // distance should never be less than 0 + for (var i = 0; i < results.length; i++) { + var doc = results[i]; + assertAlways.lte(NumberInt(doc.dis), maxDistance); // satisfies query + assertAlways.lte(prevDoc.dis, doc.dis); // returned in the correct order + prevDoc = doc; + } + }); + }; - $config.data.genUpdateDoc = function genUpdateDoc() { - var P = Math.floor(Math.sqrt(this.nDocs)); + $config.data.genUpdateDoc = function genUpdateDoc() { + var P = Math.floor(Math.sqrt(this.nDocs)); - // Move the point to another location within the PxP grid. - var newX = Random.randInt(P) - P / 2; - var newY = Random.randInt(P) - P / 2; - return { - $set: {geo: [newX, newY]} - }; - }; + // Move the point to another location within the PxP grid. + var newX = Random.randInt(P) - P / 2; + var newY = Random.randInt(P) - P / 2; + return {$set: {geo: [newX, newY]}}; + }; - $config.data.getIndexSpec = function getIndexSpec() { - return { - geo: '2d' - }; - }; + $config.data.getIndexSpec = function getIndexSpec() { + return {geo: '2d'}; + }; - $config.data.getReplaceSpec = function getReplaceSpec(i, coords) { - return { - _id: i, - geo: coords - }; - }; + $config.data.getReplaceSpec = function getReplaceSpec(i, coords) { + return {_id: i, geo: coords}; + }; - /* - * Insert some docs in geo form and make a 2d index. - */ - $config.setup = function setup(db, collName, cluster) { - $super.setup.apply(this, arguments); + /* + * Insert some docs in geo form and make a 2d index. + */ + $config.setup = function setup(db, collName, cluster) { + $super.setup.apply(this, arguments); - var P = Math.floor(Math.sqrt(this.nDocs)); - var i = 0; - // Set up some points to query (in a PxP grid around 0,0). - var bulk = db[collName].initializeUnorderedBulkOp(); - for (var x = 0; x < P; x++) { - for (var y = 0; y < P; y++) { - var coords = [x - P / 2, y - P / 2]; - bulk.find({_id: i}).upsert().replaceOne(this.getReplaceSpec(i, coords)); - i++; - } + var P = Math.floor(Math.sqrt(this.nDocs)); + var i = 0; + // Set up some points to query (in a PxP grid around 0,0). + var bulk = db[collName].initializeUnorderedBulkOp(); + for (var x = 0; x < P; x++) { + for (var y = 0; y < P; y++) { + var coords = [x - P / 2, y - P / 2]; + bulk.find({_id: i}).upsert().replaceOne(this.getReplaceSpec(i, coords)); + i++; } - assertAlways.writeOK(bulk.execute()); - assertAlways.commandWorked(db[collName].ensureIndex(this.getIndexSpec())); - }; + } + assertAlways.writeOK(bulk.execute()); + assertAlways.commandWorked(db[collName].ensureIndex(this.getIndexSpec())); + }; - return $config; - }); + return $config; +}); diff --git a/jstests/concurrency/fsm_workloads/yield_geo_near_dedup.js b/jstests/concurrency/fsm_workloads/yield_geo_near_dedup.js index 5efd9cf7242..9f3476873f7 100644 --- a/jstests/concurrency/fsm_workloads/yield_geo_near_dedup.js +++ b/jstests/concurrency/fsm_workloads/yield_geo_near_dedup.js @@ -8,92 +8,78 @@ load('jstests/concurrency/fsm_libs/extend_workload.js'); // for extendWorkload load('jstests/concurrency/fsm_workloads/yield_geo_near.js'); // for $config -var $config = extendWorkload( - $config, - function($config, $super) { +var $config = extendWorkload($config, function($config, $super) { - $config.states.remove = function remove(db, collName) { - var id = Random.randInt(this.nDocs); - var doc = db[collName].findOne({_id: id}); - if (doc !== null) { - var res = db[collName].remove({_id: id}); - assertAlways.writeOK(res); - if (res.nRemoved > 0) { - // Re-insert the document with the same '_id', but an incremented - // 'timesInserted' to - // distinguish it from the deleted document. - doc.timesInserted++; - assertAlways.writeOK(db[collName].insert(doc)); - } + $config.states.remove = function remove(db, collName) { + var id = Random.randInt(this.nDocs); + var doc = db[collName].findOne({_id: id}); + if (doc !== null) { + var res = db[collName].remove({_id: id}); + assertAlways.writeOK(res); + if (res.nRemoved > 0) { + // Re-insert the document with the same '_id', but an incremented + // 'timesInserted' to + // distinguish it from the deleted document. + doc.timesInserted++; + assertAlways.writeOK(db[collName].insert(doc)); } - }; + } + }; - /* - * Use geo $nearSphere query to find points near the origin. Note this should be done using - *the - * geoNear command, rather than a $nearSphere query, as the $nearSphere query doesn't work - *in a - * sharded environment. Unfortunately this means we cannot batch the request. - * - * Only points are covered in this test as there is no guarantee that geometries indexed in - * multiple cells will be deduplicated correctly with interspersed updates. If multiple - *index - * cells for the same geometry occur in the same search interval, an update may cause - *geoNear - * to return the same document multiple times. - */ - $config.states.query = function geoNear(db, collName) { - // This distance gets about 80 docs around the origin. There is one doc inserted - // every 1m^2 and the area scanned by a 5m radius is PI*(5m)^2 ~ 79. - var maxDistance = 5; + /* + * Use geo $nearSphere query to find points near the origin. Note this should be done using + *the + * geoNear command, rather than a $nearSphere query, as the $nearSphere query doesn't work + *in a + * sharded environment. Unfortunately this means we cannot batch the request. + * + * Only points are covered in this test as there is no guarantee that geometries indexed in + * multiple cells will be deduplicated correctly with interspersed updates. If multiple + *index + * cells for the same geometry occur in the same search interval, an update may cause + *geoNear + * to return the same document multiple times. + */ + $config.states.query = function geoNear(db, collName) { + // This distance gets about 80 docs around the origin. There is one doc inserted + // every 1m^2 and the area scanned by a 5m radius is PI*(5m)^2 ~ 79. + var maxDistance = 5; - var res = db.runCommand( - {geoNear: collName, near: [0, 0], maxDistance: maxDistance, spherical: true}); - assertWhenOwnColl.commandWorked(res); - assertWhenOwnColl(function verifyResults() { - var results = res.results; - var seenObjs = []; - for (var i = 0; i < results.length; i++) { - var doc = results[i].obj; + var res = db.runCommand( + {geoNear: collName, near: [0, 0], maxDistance: maxDistance, spherical: true}); + assertWhenOwnColl.commandWorked(res); + assertWhenOwnColl(function verifyResults() { + var results = res.results; + var seenObjs = []; + for (var i = 0; i < results.length; i++) { + var doc = results[i].obj; - // The pair (_id, timesInserted) is the smallest set of attributes that uniquely - // identifies a document. - var objToSearchFor = { - _id: doc._id, - timesInserted: doc.timesInserted - }; - var found = seenObjs.some(function(obj) { - return bsonWoCompare(obj, objToSearchFor) === 0; - }); - assertWhenOwnColl(!found, - 'geoNear command returned the document ' + tojson(doc) + - ' multiple times: ' + tojson(seenObjs)); - seenObjs.push(objToSearchFor); - } - }); - }; + // The pair (_id, timesInserted) is the smallest set of attributes that uniquely + // identifies a document. + var objToSearchFor = {_id: doc._id, timesInserted: doc.timesInserted}; + var found = seenObjs.some(function(obj) { + return bsonWoCompare(obj, objToSearchFor) === 0; + }); + assertWhenOwnColl(!found, + 'geoNear command returned the document ' + tojson(doc) + + ' multiple times: ' + tojson(seenObjs)); + seenObjs.push(objToSearchFor); + } + }); + }; - $config.data.genUpdateDoc = function genUpdateDoc() { - // Attempts to perform an in-place update to trigger an invalidation on MMAP v1. - return { - $inc: {timesUpdated: 1} - }; - }; + $config.data.genUpdateDoc = function genUpdateDoc() { + // Attempts to perform an in-place update to trigger an invalidation on MMAP v1. + return {$inc: {timesUpdated: 1}}; + }; - $config.data.getIndexSpec = function getIndexSpec() { - return { - geo: '2dsphere' - }; - }; + $config.data.getIndexSpec = function getIndexSpec() { + return {geo: '2dsphere'}; + }; - $config.data.getReplaceSpec = function getReplaceSpec(i, coords) { - return { - _id: i, - geo: coords, - timesUpdated: 0, - timesInserted: 0 - }; - }; + $config.data.getReplaceSpec = function getReplaceSpec(i, coords) { + return {_id: i, geo: coords, timesUpdated: 0, timesInserted: 0}; + }; - return $config; - }); + return $config; +}); diff --git a/jstests/concurrency/fsm_workloads/yield_id_hack.js b/jstests/concurrency/fsm_workloads/yield_id_hack.js index 0d50eb7d350..eddb653c1d8 100644 --- a/jstests/concurrency/fsm_workloads/yield_id_hack.js +++ b/jstests/concurrency/fsm_workloads/yield_id_hack.js @@ -9,26 +9,25 @@ load('jstests/concurrency/fsm_libs/extend_workload.js'); // for extendWorkload load('jstests/concurrency/fsm_workloads/yield.js'); // for $config -var $config = extendWorkload($config, - function($config, $super) { +var $config = extendWorkload($config, function($config, $super) { - /* - * Issue a query that will use the ID_HACK stage. This cannot be - * batched, so issue a - * number of them to increase the chances of yielding between - * getting the key and looking - * up its value. - */ - $config.states.query = function idHack(db, collName) { - var nQueries = 100; - for (var i = 0; i < nQueries; i++) { - assertAlways.lte(db[collName].find({_id: i}).itcount(), 1); - var res = db[collName].findOne({_id: i}); - if (res !== null) { - assertAlways.eq(i, res._id); - } - } - }; + /* + * Issue a query that will use the ID_HACK stage. This cannot be + * batched, so issue a + * number of them to increase the chances of yielding between + * getting the key and looking + * up its value. + */ + $config.states.query = function idHack(db, collName) { + var nQueries = 100; + for (var i = 0; i < nQueries; i++) { + assertAlways.lte(db[collName].find({_id: i}).itcount(), 1); + var res = db[collName].findOne({_id: i}); + if (res !== null) { + assertAlways.eq(i, res._id); + } + } + }; - return $config; - }); + return $config; +}); diff --git a/jstests/concurrency/fsm_workloads/yield_rooted_or.js b/jstests/concurrency/fsm_workloads/yield_rooted_or.js index f7dd0dcffdf..2d21427b42b 100644 --- a/jstests/concurrency/fsm_workloads/yield_rooted_or.js +++ b/jstests/concurrency/fsm_workloads/yield_rooted_or.js @@ -10,41 +10,37 @@ load('jstests/concurrency/fsm_libs/extend_workload.js'); // for extendWorkload load('jstests/concurrency/fsm_workloads/yield.js'); // for $config -var $config = - extendWorkload($config, - function($config, $super) { - - /* - * Issue a query with an or stage as the root. - */ - $config.states.query = function rootedOr(db, collName) { - var nMatches = 100; - - var cursor = db[collName].find({ - $or: [{c: {$lte: nMatches / 2}}, {d: {$lte: nMatches / 2}}] - }).batchSize(this.batchSize); - - var verifier = function rootedOrVerifier(doc, prevDoc) { - return (doc.c <= nMatches / 2 || doc.d <= nMatches / 2); - }; - - this.advanceCursor(cursor, verifier); - }; - - $config.data.genUpdateDoc = function genUpdateDoc() { - var newC = Random.randInt(this.nDocs); - var newD = Random.randInt(this.nDocs); - return { - $set: {c: newC, d: newD} - }; - }; - - $config.setup = function setup(db, collName, cluster) { - $super.setup.apply(this, arguments); - - assertAlways.commandWorked(db[collName].ensureIndex({c: 1})); - assertAlways.commandWorked(db[collName].ensureIndex({d: 1})); - }; - - return $config; - }); +var $config = extendWorkload($config, function($config, $super) { + + /* + * Issue a query with an or stage as the root. + */ + $config.states.query = function rootedOr(db, collName) { + var nMatches = 100; + + var cursor = db[collName] + .find({$or: [{c: {$lte: nMatches / 2}}, {d: {$lte: nMatches / 2}}]}) + .batchSize(this.batchSize); + + var verifier = function rootedOrVerifier(doc, prevDoc) { + return (doc.c <= nMatches / 2 || doc.d <= nMatches / 2); + }; + + this.advanceCursor(cursor, verifier); + }; + + $config.data.genUpdateDoc = function genUpdateDoc() { + var newC = Random.randInt(this.nDocs); + var newD = Random.randInt(this.nDocs); + return {$set: {c: newC, d: newD}}; + }; + + $config.setup = function setup(db, collName, cluster) { + $super.setup.apply(this, arguments); + + assertAlways.commandWorked(db[collName].ensureIndex({c: 1})); + assertAlways.commandWorked(db[collName].ensureIndex({d: 1})); + }; + + return $config; +}); diff --git a/jstests/concurrency/fsm_workloads/yield_sort.js b/jstests/concurrency/fsm_workloads/yield_sort.js index d0d905177f8..1c535ae6415 100644 --- a/jstests/concurrency/fsm_workloads/yield_sort.js +++ b/jstests/concurrency/fsm_workloads/yield_sort.js @@ -9,37 +9,33 @@ load('jstests/concurrency/fsm_libs/extend_workload.js'); // for extendWorkload load('jstests/concurrency/fsm_workloads/yield_sort_merge.js'); // for $config -var $config = extendWorkload( - $config, - function($config, $super) { +var $config = extendWorkload($config, function($config, $super) { - /* - * Execute a query that will use the SORT stage. - */ - $config.states.query = function sort(db, collName) { - var nMatches = 100; - // Sort on c, since it's not an indexed field. - var cursor = - db[collName].find({a: {$lt: nMatches}}).sort({c: -1}).batchSize(this.batchSize); + /* + * Execute a query that will use the SORT stage. + */ + $config.states.query = function sort(db, collName) { + var nMatches = 100; + // Sort on c, since it's not an indexed field. + var cursor = + db[collName].find({a: {$lt: nMatches}}).sort({c: -1}).batchSize(this.batchSize); - var verifier = function sortVerifier(doc, prevDoc) { - var correctOrder = true; - if (prevDoc !== null) { - correctOrder = (doc.c <= prevDoc.c); - } - return doc.a < nMatches && correctOrder; - }; - - this.advanceCursor(cursor, verifier); + var verifier = function sortVerifier(doc, prevDoc) { + var correctOrder = true; + if (prevDoc !== null) { + correctOrder = (doc.c <= prevDoc.c); + } + return doc.a < nMatches && correctOrder; }; - $config.data.genUpdateDoc = function genUpdateDoc() { - var newA = Random.randInt(this.nDocs); - var newC = Random.randInt(this.nDocs); - return { - $set: {a: newA, c: newC} - }; - }; + this.advanceCursor(cursor, verifier); + }; + + $config.data.genUpdateDoc = function genUpdateDoc() { + var newA = Random.randInt(this.nDocs); + var newC = Random.randInt(this.nDocs); + return {$set: {a: newA, c: newC}}; + }; - return $config; - }); + return $config; +}); diff --git a/jstests/concurrency/fsm_workloads/yield_sort_merge.js b/jstests/concurrency/fsm_workloads/yield_sort_merge.js index c46163df492..d715a813701 100644 --- a/jstests/concurrency/fsm_workloads/yield_sort_merge.js +++ b/jstests/concurrency/fsm_workloads/yield_sort_merge.js @@ -10,49 +10,44 @@ load('jstests/concurrency/fsm_libs/extend_workload.js'); // for extendWorkload load('jstests/concurrency/fsm_workloads/yield.js'); // for $config -var $config = extendWorkload( - $config, - function($config, $super) { - - /* - * Execute a query that will use the SORT_MERGE stage. - */ - $config.states.query = function sortMerge(db, collName) { - var nMatches = 50; // Don't push this too high, or SORT_MERGE stage won't be selected. - - // Build an array [0, nMatches). - var matches = []; - for (var i = 0; i < nMatches; i++) { - matches.push(i); +var $config = extendWorkload($config, function($config, $super) { + + /* + * Execute a query that will use the SORT_MERGE stage. + */ + $config.states.query = function sortMerge(db, collName) { + var nMatches = 50; // Don't push this too high, or SORT_MERGE stage won't be selected. + + // Build an array [0, nMatches). + var matches = []; + for (var i = 0; i < nMatches; i++) { + matches.push(i); + } + + var cursor = db[collName].find({a: {$in: matches}}).sort({b: -1}).batchSize(this.batchSize); + + var verifier = function sortMergeVerifier(doc, prevDoc) { + var correctOrder = true; + if (prevDoc !== null) { + correctOrder = (doc.b <= prevDoc.b); } - - var cursor = - db[collName].find({a: {$in: matches}}).sort({b: -1}).batchSize(this.batchSize); - - var verifier = function sortMergeVerifier(doc, prevDoc) { - var correctOrder = true; - if (prevDoc !== null) { - correctOrder = (doc.b <= prevDoc.b); - } - return doc.a < nMatches && correctOrder; - }; - - this.advanceCursor(cursor, verifier); + return doc.a < nMatches && correctOrder; }; - $config.data.genUpdateDoc = function genUpdateDoc() { - var newA = Random.randInt(this.nDocs); - var newB = Random.randInt(this.nDocs); - return { - $set: {a: newA, b: newB} - }; - }; + this.advanceCursor(cursor, verifier); + }; - $config.setup = function setup(db, collName, cluster) { - $super.setup.apply(this, arguments); + $config.data.genUpdateDoc = function genUpdateDoc() { + var newA = Random.randInt(this.nDocs); + var newB = Random.randInt(this.nDocs); + return {$set: {a: newA, b: newB}}; + }; - assertAlways.commandWorked(db[collName].ensureIndex({a: 1, b: 1})); - }; + $config.setup = function setup(db, collName, cluster) { + $super.setup.apply(this, arguments); + + assertAlways.commandWorked(db[collName].ensureIndex({a: 1, b: 1})); + }; - return $config; - }); + return $config; +}); diff --git a/jstests/concurrency/fsm_workloads/yield_text.js b/jstests/concurrency/fsm_workloads/yield_text.js index 9291c25e527..0ccf5b8a7d4 100644 --- a/jstests/concurrency/fsm_workloads/yield_text.js +++ b/jstests/concurrency/fsm_workloads/yield_text.js @@ -9,47 +9,42 @@ load('jstests/concurrency/fsm_libs/extend_workload.js'); // for extendWorkload load('jstests/concurrency/fsm_workloads/yield.js'); // for $config -var $config = extendWorkload( - $config, - function($config, $super) { - - /* - * Pick a random word and search for it using full text search. - */ - $config.states.query = function text(db, collName) { - var word = this.words[Random.randInt(this.words.length)]; - - var cursor = db[collName].find({ - $text: {$search: word}, - yield_text: {$exists: true} - }).batchSize(this.batchSize); - - var verifier = function textVerifier(doc, prevDoc) { - return doc.yield_text.indexOf(word) !== -1; - }; - - // If we don't have the right text index, or someone drops our text index, this - // assertion - // is either pointless or won't work. So only verify the results when we know no one - // else - // is messing with our indices. - assertWhenOwnColl(function verifyTextResults() { - this.advanceCursor(cursor, verifier); - }.bind(this)); - }; +var $config = extendWorkload($config, function($config, $super) { - $config.data.genUpdateDoc = function genUpdateDoc() { - var newWord = this.words[Random.randInt(this.words.length)]; - return { - $set: {yield_text: newWord} - }; - }; + /* + * Pick a random word and search for it using full text search. + */ + $config.states.query = function text(db, collName) { + var word = this.words[Random.randInt(this.words.length)]; - $config.setup = function setup(db, collName, cluster) { - $super.setup.apply(this, arguments); + var cursor = db[collName] + .find({$text: {$search: word}, yield_text: {$exists: true}}) + .batchSize(this.batchSize); - assertWhenOwnColl.commandWorked(db[collName].ensureIndex({yield_text: 'text'})); + var verifier = function textVerifier(doc, prevDoc) { + return doc.yield_text.indexOf(word) !== -1; }; - return $config; - }); + // If we don't have the right text index, or someone drops our text index, this + // assertion + // is either pointless or won't work. So only verify the results when we know no one + // else + // is messing with our indices. + assertWhenOwnColl(function verifyTextResults() { + this.advanceCursor(cursor, verifier); + }.bind(this)); + }; + + $config.data.genUpdateDoc = function genUpdateDoc() { + var newWord = this.words[Random.randInt(this.words.length)]; + return {$set: {yield_text: newWord}}; + }; + + $config.setup = function setup(db, collName, cluster) { + $super.setup.apply(this, arguments); + + assertWhenOwnColl.commandWorked(db[collName].ensureIndex({yield_text: 'text'})); + }; + + return $config; +}); |