diff options
author | Gregory Wlodarek <gregory.wlodarek@mongodb.com> | 2019-10-14 19:13:55 +0000 |
---|---|---|
committer | evergreen <evergreen@mongodb.com> | 2019-10-14 19:13:55 +0000 |
commit | 3135b6a77d4fbabccc113186817ba670e31d13b6 (patch) | |
tree | 6cb8812084baff0887ffcd04c990e2814a356ce9 | |
parent | 16fd1f4552014554be4ae5daa2c5bca5073dc3af (diff) | |
download | mongo-3135b6a77d4fbabccc113186817ba670e31d13b6.tar.gz |
SERVER-42373 Prevent "invalid view definition" error while dropping nonexistent collection
(cherry picked from commit 00bd5405dfaa44f3094965cf6bb0e6dc55062b99)
-rw-r--r-- | jstests/noPassthrough/durable_view_catalog.js | 5 | ||||
-rw-r--r-- | jstests/sharding/invalid_system_views_sharded_collection.js | 6 | ||||
-rw-r--r-- | src/mongo/db/catalog/drop_collection.cpp | 7 |
3 files changed, 16 insertions, 2 deletions
diff --git a/jstests/noPassthrough/durable_view_catalog.js b/jstests/noPassthrough/durable_view_catalog.js index 23de01b4b30..50540f33bbb 100644 --- a/jstests/noPassthrough/durable_view_catalog.js +++ b/jstests/noPassthrough/durable_view_catalog.js @@ -72,7 +72,10 @@ assert.commandFailedWithCode(viewsDB.runCommand({create: "view4", viewOn: "colle ErrorCodes.InvalidViewDefinition); assert.commandFailedWithCode(viewsDB.runCommand({collMod: "view2", viewOn: "view4"}), ErrorCodes.InvalidViewDefinition); -assert.commandFailedWithCode(viewsDB.runCommand({drop: "view4"}), ErrorCodes.InvalidViewDefinition); + +// Checks that dropping a nonexistent view or collection is not affected by an invalid view existing +// in the view catalog. +assert.commandFailedWithCode(viewsDB.runCommand({drop: "view4"}), ErrorCodes.NamespaceNotFound); assert.commandFailedWithCode(viewsDB.runCommand({listCollections: 1}), ErrorCodes.InvalidViewDefinition); diff --git a/jstests/sharding/invalid_system_views_sharded_collection.js b/jstests/sharding/invalid_system_views_sharded_collection.js index 899d4482987..504c1b6e9eb 100644 --- a/jstests/sharding/invalid_system_views_sharded_collection.js +++ b/jstests/sharding/invalid_system_views_sharded_collection.js @@ -95,6 +95,12 @@ function runTest(st, badViewDefinition) { makeErrorMessage("drop")); assert.commandWorked(db.runCommand({drop: staticCollection.getName()}), makeErrorMessage("drop")); + + // An invalid view in the view catalog should not interfere with attempting to run operations on + // nonexistent collections. + assert.commandWorked(db.runCommand({drop: staticCollection.getName()}), + makeErrorMessage("drop")); + assert.commandWorked(db.runCommand({drop: unshardedColl.getName()}), makeErrorMessage("drop")); // Drop the offending view so that the validate hook succeeds. diff --git a/src/mongo/db/catalog/drop_collection.cpp b/src/mongo/db/catalog/drop_collection.cpp index 5a8c2828f63..538aaa1e1b4 100644 --- a/src/mongo/db/catalog/drop_collection.cpp +++ b/src/mongo/db/catalog/drop_collection.cpp @@ -59,10 +59,15 @@ Status _dropView(OperationContext* opCtx, if (!db) { return Status(ErrorCodes::NamespaceNotFound, "ns not found"); } - auto view = ViewCatalog::get(db)->lookup(opCtx, collectionName.ns()); + auto view = + ViewCatalog::get(db)->lookupWithoutValidatingDurableViews(opCtx, collectionName.ns()); if (!view) { return Status(ErrorCodes::NamespaceNotFound, "ns not found"); } + + // Validates the view or throws an "invalid view" error. + ViewCatalog::get(db)->lookup(opCtx, collectionName.ns()); + Lock::CollectionLock collLock(opCtx, collectionName, MODE_IX); // Operations all lock system.views in the end to prevent deadlock. Lock::CollectionLock systemViewsLock(opCtx, db->getSystemViewsName(), MODE_X); |