summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames Wahlin <james.wahlin@10gen.com>2016-10-17 13:08:58 -0400
committerJames Wahlin <james.wahlin@10gen.com>2016-10-28 08:42:17 -0400
commit732f151dcdcf7e9a014cc5effbcddbacf7118b10 (patch)
tree93081b5a8d4038fbd2182c15b835e36733abfe2e
parent66d95ea28c4eb6e239c8d94339b0587cf8f5159f (diff)
downloadmongo-732f151dcdcf7e9a014cc5effbcddbacf7118b10.tar.gz
SERVER-26435 Add FSM tests that exercise parallel unique index builds
-rw-r--r--jstests/concurrency/fsm_workloads/create_index_background_unique.js100
-rw-r--r--jstests/concurrency/fsm_workloads/create_index_background_unique_capped.js23
2 files changed, 123 insertions, 0 deletions
diff --git a/jstests/concurrency/fsm_workloads/create_index_background_unique.js b/jstests/concurrency/fsm_workloads/create_index_background_unique.js
new file mode 100644
index 00000000000..d3cc47b5c58
--- /dev/null
+++ b/jstests/concurrency/fsm_workloads/create_index_background_unique.js
@@ -0,0 +1,100 @@
+'use strict';
+
+/**
+ * create_index_background_unique.js
+ *
+ * Creates multiple unique background indexes in parallel.
+ */
+
+load('jstests/concurrency/fsm_workload_helpers/drop_utils.js'); // for dropCollections
+
+var $config = (function() {
+
+ var data = {
+ prefix: "create_index_background_unique_",
+ iterationCount: 0,
+ getCollectionNameForThread: function(threadId) {
+ return this.prefix + threadId.toString();
+ },
+ // Allows tests that inherit from this one to specify options other than the default.
+ getCollectionOptions: function() {
+ return {};
+ },
+ buildvariableSizedDoc: function(uniquePrefix) {
+ const indexedVal = uniquePrefix + Array(Random.randInt(1000)).toString();
+ const doc = {x: indexedVal};
+ return doc;
+ },
+ };
+
+ var states = (function() {
+ function buildIndex(db, collName) {
+ this.iterationCount++;
+
+ const res = db.runCommand({
+ createIndexes: this.getCollectionNameForThread(this.tid),
+ indexes: [{key: {x: 1}, name: "x_1", unique: true, background: true}]
+ });
+ assertAlways.commandWorked(res);
+ }
+
+ function dropIndex(db, collName) {
+ this.iterationCount++;
+
+ // In the case that we have an even # of iterations, we skip the final drop so that
+ // validation can be performed on the indexes created.
+ if (this.iterationCount === this.iterations) {
+ return;
+ }
+
+ assertAlways.commandWorked(db.runCommand(
+ {dropIndexes: this.getCollectionNameForThread(this.tid), index: "x_1"}));
+ }
+
+ return {
+ buildIndex: buildIndex,
+ dropIndex: dropIndex,
+ };
+
+ })();
+
+ var transitions = {
+ buildIndex: {dropIndex: 1.0},
+ dropIndex: {buildIndex: 1.0},
+ };
+
+ function setup(db, collName, cluster) {
+ for (let j = 0; j < this.threadCount; ++j) {
+ const collectionName = this.getCollectionNameForThread(j);
+ assertAlways.commandWorked(
+ db.createCollection(collectionName, this.getCollectionOptions()));
+ var bulk = db[collectionName].initializeUnorderedBulkOp();
+
+ // Preload 15K documents for each thread's collection. This ensures that index build and
+ // drop has meaningful work to do.
+ for (let i = 0; i < 15000; ++i) {
+ const uniqueValuePrefix = i.toString() + "_";
+ bulk.insert(this.buildvariableSizedDoc(uniqueValuePrefix));
+ }
+ assertAlways.writeOK(bulk.execute());
+ assertAlways.eq(15000, db[collectionName].find({}).itcount());
+ }
+ }
+
+ function teardown(db, collName, cluster) {
+ // Drop all collections from this workload.
+ const pattern = new RegExp('^' + this.prefix + '[0-9]*$');
+ dropCollections(db, pattern);
+ }
+
+ return {
+ threadCount: 10,
+ iterations: 11,
+ data: data,
+ states: states,
+ startState: 'buildIndex',
+ transitions: transitions,
+ setup: setup,
+ teardown: teardown,
+ };
+})();
diff --git a/jstests/concurrency/fsm_workloads/create_index_background_unique_capped.js b/jstests/concurrency/fsm_workloads/create_index_background_unique_capped.js
new file mode 100644
index 00000000000..ae4fa632c84
--- /dev/null
+++ b/jstests/concurrency/fsm_workloads/create_index_background_unique_capped.js
@@ -0,0 +1,23 @@
+'use strict';
+
+/**
+ * create_index_background_unique_capped.js
+ *
+ * Creates multiple unique background indexes in parallel, on capped collections.
+ */
+
+load('jstests/concurrency/fsm_libs/extend_workload.js'); // for extendWorkload
+load('jstests/concurrency/fsm_workloads/create_index_background_unique.js'); // for $config
+
+var $config = extendWorkload($config, function($config, $super) {
+
+ $config.data.prefix = "create_index_background_unique_capped_";
+ $config.data.getCollectionOptions = function() {
+ // We create an 8MB capped collection, as it will comfortably fit the collection data
+ // inserted by this test.
+ const ONE_MB = 1024 * 1024;
+ return {capped: true, size: 8 * ONE_MB};
+ };
+
+ return $config;
+});