diff options
-rw-r--r-- | jstests/noPassthroughWithMongod/coll_mod_takes_database_x_lock.js | 33 | ||||
-rw-r--r-- | src/mongo/db/catalog/coll_mod.cpp | 7 |
2 files changed, 36 insertions, 4 deletions
diff --git a/jstests/noPassthroughWithMongod/coll_mod_takes_database_x_lock.js b/jstests/noPassthroughWithMongod/coll_mod_takes_database_x_lock.js new file mode 100644 index 00000000000..bf78d13f887 --- /dev/null +++ b/jstests/noPassthroughWithMongod/coll_mod_takes_database_x_lock.js @@ -0,0 +1,33 @@ +/** + * Ensures that the 'collMod' command takes a database MODE_X lock during a no-op. + */ +(function() { + 'use strict'; + + const failpoint = 'hangAfterDatabaseLock'; + assert.commandWorked(db.adminCommand({configureFailPoint: failpoint, mode: "alwaysOn"})); + + const conn = db.getMongo(); + db.createCollection('foo'); + + // Run a no-op collMod command. + const awaitParallelShell = startParallelShell(() => { + assert.commandWorked(db.runCommand({collMod: 'foo'})); + }, conn.port); + + // Check that the database MODE_X lock is being held by checking in lockInfo. + assert.soon(() => { + let lockInfo = assert.commandWorked(db.adminCommand({lockInfo: 1})).lockInfo; + for (let i = 0; i < lockInfo.length; i++) { + let resourceId = lockInfo[i].resourceId; + if (resourceId.includes("Database") && resourceId.includes("test")) { + return true; + } + } + + return false; + }); + + assert.commandWorked(db.adminCommand({configureFailPoint: failpoint, mode: "off"})); + awaitParallelShell(); +})(); diff --git a/src/mongo/db/catalog/coll_mod.cpp b/src/mongo/db/catalog/coll_mod.cpp index 9337230d819..1c56a6ae270 100644 --- a/src/mongo/db/catalog/coll_mod.cpp +++ b/src/mongo/db/catalog/coll_mod.cpp @@ -61,10 +61,7 @@ namespace mongo { namespace { -// Causes the server to hang when it attempts to assign UUIDs to the provided database (or all -// databases if none are provided). -MONGO_FAIL_POINT_DEFINE(hangBeforeDatabaseUpgrade); - +MONGO_FAIL_POINT_DEFINE(hangAfterDatabaseLock); MONGO_FAIL_POINT_DEFINE(assertAfterIndexUpdate); struct CollModRequest { @@ -307,6 +304,8 @@ Status _collModInternal(OperationContext* opCtx, Database* const db = autoDb.getDb(); Collection* coll = db ? db->getCollection(opCtx, nss) : nullptr; + MONGO_FAIL_POINT_PAUSE_WHILE_SET(hangAfterDatabaseLock); + // May also modify a view instead of a collection. boost::optional<ViewDefinition> view; if (db && !coll) { |