diff options
author | David Storch <david.storch@10gen.com> | 2019-02-11 07:50:37 -0500 |
---|---|---|
committer | David Storch <david.storch@10gen.com> | 2019-02-12 17:29:23 -0500 |
commit | 5c479de833f642873fc8b1f9464a0dddbc0243a5 (patch) | |
tree | 03d127623cffce809708a4d617d72ab7cc95ae3d | |
parent | efbc5f12fda0d76cf3f9ec6049232ab486e29977 (diff) | |
download | mongo-5c479de833f642873fc8b1f9464a0dddbc0243a5.tar.gz |
SERVER-38372 Fix rollback of index drop to update CollectionInfoCache.
-rw-r--r-- | jstests/core/rollback_index_drop.js | 35 | ||||
-rw-r--r-- | src/mongo/db/catalog/index_catalog_impl.cpp | 7 |
2 files changed, 41 insertions, 1 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()); +}()); diff --git a/src/mongo/db/catalog/index_catalog_impl.cpp b/src/mongo/db/catalog/index_catalog_impl.cpp index 52df6a8e887..bf8ff459588 100644 --- a/src/mongo/db/catalog/index_catalog_impl.cpp +++ b/src/mongo/db/catalog/index_catalog_impl.cpp @@ -849,8 +849,13 @@ public: } void rollback() final { - _collection->infoCache()->addedIndex(_opCtx, _entry->descriptor()); + auto indexDescriptor = _entry->descriptor(); _entries->add(std::move(_entry)); + + // Refresh the CollectionInfoCache's knowledge of what indices are present. This must be + // done after re-adding our IndexCatalogEntry to the '_entries' list, since 'addedIndex()' + // refreshes its knowledge by iterating the list of indices currently in the catalog. + _collection->infoCache()->addedIndex(_opCtx, indexDescriptor); } private: |