summaryrefslogtreecommitdiff
path: root/jstests/core/rollback_index_drop.js
diff options
context:
space:
mode:
authorDavid Storch <david.storch@10gen.com>2019-02-11 07:50:37 -0500
committerDavid Storch <david.storch@10gen.com>2019-02-12 17:29:23 -0500
commit5c479de833f642873fc8b1f9464a0dddbc0243a5 (patch)
tree03d127623cffce809708a4d617d72ab7cc95ae3d /jstests/core/rollback_index_drop.js
parentefbc5f12fda0d76cf3f9ec6049232ab486e29977 (diff)
downloadmongo-5c479de833f642873fc8b1f9464a0dddbc0243a5.tar.gz
SERVER-38372 Fix rollback of index drop to update CollectionInfoCache.
Diffstat (limited to 'jstests/core/rollback_index_drop.js')
-rw-r--r--jstests/core/rollback_index_drop.js35
1 files changed, 35 insertions, 0 deletions
diff --git a/jstests/core/rollback_index_drop.js b/jstests/core/rollback_index_drop.js
new file mode 100644
index 00000000000..3e7c3a97952
--- /dev/null
+++ b/jstests/core/rollback_index_drop.js
@@ -0,0 +1,35 @@
+// Test that when an index drop rolls back, the index remains valid, and the server continues to
+// correctly maintain the index's set of keys.
+//
+// This test was designed to reproduce SERVER-38372.
+//
+// @tags: [does_not_support_stepdowns, assumes_unsharded_collection]
+(function() {
+ "use strict";
+
+ const coll = db.rollback_index_drop;
+ coll.drop();
+
+ assert.commandWorked(coll.insert([{a: 1}, {a: 2}, {a: 3}]));
+ assert.commandWorked(coll.createIndex({a: 1}));
+
+ // Verify that the index has the expected set of keys.
+ assert.eq([{a: 1}, {a: 2}, {a: 3}],
+ coll.find().hint({a: 1}).sort({a: 1}).returnKey().toArray());
+
+ // Run a dropIndexes command that attempts to drop both {a: 1} and an invalid index. This should
+ // cause the drop of {a: 1} to rollback, since the set of index drops happen atomically.
+ assert.commandFailedWithCode(
+ db.runCommand({dropIndexes: coll.getName(), index: ["a_1", "unknown"]}),
+ ErrorCodes.IndexNotFound);
+
+ // Verify that the {a: 1} index is still present in listIndexes output.
+ const indexList = coll.getIndexes();
+ assert.neq(undefined, indexList.find((idx) => idx.name === "a_1"), indexList);
+
+ // Write to the collection and ensure that the resulting set of index keys is correct.
+ assert.commandWorked(coll.update({a: 3}, {$inc: {a: 1}}));
+ assert.commandWorked(coll.insert({a: 5}));
+ assert.eq([{a: 1}, {a: 2}, {a: 4}, {a: 5}],
+ coll.find().hint({a: 1}).sort({a: 1}).returnKey().toArray());
+}());