summaryrefslogtreecommitdiff
path: root/jstests/noPassthroughWithMongod/indexbg_updates.js
diff options
context:
space:
mode:
authorKyle Suarez <ksuarz@gmail.com>2016-04-14 12:18:36 -0400
committerKyle Suarez <ksuarz@gmail.com>2016-04-14 12:18:36 -0400
commit81e98e4f298c22792e7158afeb6215e54ef5531a (patch)
tree2bd958e582da6f08df74c8fafb305dff09195860 /jstests/noPassthroughWithMongod/indexbg_updates.js
parent7082da52febebd96d6d7871dcfc8868299ec123b (diff)
downloadmongo-81e98e4f298c22792e7158afeb6215e54ef5531a.tar.gz
SERVER-23590 add background index build test
Tests that indexes are properly updated when updates are performed during a background index scan. This test is disabled for now and will be re-enabled in SERVER-23695.
Diffstat (limited to 'jstests/noPassthroughWithMongod/indexbg_updates.js')
-rw-r--r--jstests/noPassthroughWithMongod/indexbg_updates.js65
1 files changed, 65 insertions, 0 deletions
diff --git a/jstests/noPassthroughWithMongod/indexbg_updates.js b/jstests/noPassthroughWithMongod/indexbg_updates.js
new file mode 100644
index 00000000000..37bc9b325fe
--- /dev/null
+++ b/jstests/noPassthroughWithMongod/indexbg_updates.js
@@ -0,0 +1,65 @@
+// Perform concurrent updates with a background index build, testing that
+// indexes are updated appropriately. See SERVER-23590 and SERVER-22970.
+//
+// Variation of index_multi.js
+
+(function() {
+ "use strict";
+ Random.setRandomSeed();
+
+ var coll = db.getSiblingDB("indexbg_updates").coll;
+ coll.drop();
+
+ var numDocs = 10000;
+
+ var bulk = coll.initializeUnorderedBulkOp();
+ print("Populate the collection with random data");
+ for (var i = 0; i < numDocs; i++) {
+ var doc = {
+ "_id": i,
+ "field0": Random.rand()
+ };
+
+ bulk.insert(doc);
+ }
+ assert.writeOK(bulk.execute());
+
+ // Perform a bulk update on a single document, targeting the updates on the
+ // field being actively indexed in the background
+ bulk = coll.initializeUnorderedBulkOp();
+ for (i = 0; i < numDocs; i++) {
+ var criteria = {
+ "_id": 1000
+ };
+ var mod = {};
+
+ if (Random.rand() < .8) {
+ mod["$set"] = {};
+ mod["$set"]["field0"] = Random.rand();
+ } else {
+ mod["$unset"] = {};
+ mod["$unset"]["field0"] = true;
+ }
+
+ bulk.find(criteria).update(mod);
+ }
+
+ // Build an index in the background on field0
+ var backgroundIndexBuildShell = startParallelShell(
+ function() {
+ var coll = db.getSiblingDB("indexbg_updates").coll;
+ assert.commandWorked(coll.createIndex({ "field0": 1 }, { "background": true }));
+ },
+ null, // port -- use default
+ false // noconnect
+ );
+
+ print("Do some sets and unsets");
+ assert.writeOK(bulk.execute());
+
+ print("Start background index build");
+ backgroundIndexBuildShell();
+
+ var explain = coll.find().hint({ "field0": 1 }).explain();
+ assert("queryPlanner" in explain, tojson(explain));
+}());