[SERVER-67679] Concurrent collection drops can return NamespaceNotFound instead of CollectionUUIDMismatch Created: 29/Jun/22  Updated: 29/Oct/23  Resolved: 09/Aug/22

Status: Closed
Project: Core Server
Component/s: None
Affects Version/s: None
Fix Version/s: 6.0.2, 6.1.0-rc0

Type: Bug Priority: Major - P3
Reporter: Gregory Noma Assignee: Fausto Leyva (Inactive)
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Backports
Depends
Backwards Compatibility: Fully Compatible
Operating System: ALL
Backport Requested:
v6.0
Sprint: Execution Team 2022-08-08, Execution Team 2022-08-22
Participants:

 Description   

Because the dropCollection command releases and reacquires locks, after reacquiring locks it has to perform some checks again including whether the collection still exists. If there are multiple concurrent commands trying to drop the same collection, one thread can actually do the drop while another has yielded its locks. If the collectionUUID parameter was specified, this should result in a CollectionUUIDMismatch error rather than NamespaceNotFound. The following test reproduces this issue.

/**
 * Tests that CollectionUUIDMismatch is properly returned with concurrent collection drops.
 */
(function() {
'use strict';
 
load('jstests/libs/parallel_shell_helpers.js');
load('jstests/libs/wait_for_command.js');
 
const testDB = db.getSiblingDB(jsTestName());
testDB.dropDatabase();
 
const coll = testDB.coll;
assert.commandWorked(testDB.createCollection(coll.getName()));
 
const uuid = assert.commandWorked(testDB.runCommand({listCollections: 1}))
                 .cursor.firstBatch.find(c => c.name === coll.getName())
                 .info.uuid;
 
const sleepCommand = startParallelShell(
    funWithArgs(function(ns) {
        assert.commandFailedWithCode(
            db.adminCommand(
                {sleep: 1, secs: 18000, lockTarget: ns, lock: 'iw', $comment: jsTestName()}),
            ErrorCodes.Interrupted);
    }, coll.getFullName()), testDB.getMongo().port);
const sleepID =
    waitForCommand('sleepCmd',
                   op => (op['ns'] == 'admin.$cmd' && op['command']['$comment'] == jsTestName()),
                   testDB.getSiblingDB('admin'));
 
const firstDrop = startParallelShell(
    funWithArgs(function(dbName, collName, uuid) {
        assert.commandWorked(
            db.getSiblingDB(dbName).runCommand({drop: collName, collectionUUID: uuid}));
    }, testDB.getName(), coll.getName(), uuid), testDB.getMongo().port);
assert.soon(() => {
    return testDB
               .currentOp({
                   'command.drop': coll.getName(),
                   'command.collectionUUID': uuid,
                   'locks.Collection': 'W',
                   waitingForLock: true,
               })
               .inprog.length === 1;
});
 
const secondDrop = startParallelShell(
    funWithArgs(function(dbName, collName, uuid) {
        const res = assert.commandFailedWithCode(
            db.getSiblingDB(dbName).runCommand({drop: collName, collectionUUID: uuid}),
            ErrorCodes.CollectionUUIDMismatch);
        assert.eq(res.db, dbName);
        assert.eq(res.collectionUUID, uuid);
        assert.eq(res.expectedCollection, collName);
        assert.eq(res.actualCollection, null);
    }, testDB.getName(), coll.getName(), uuid), testDB.getMongo().port);
assert.soon(() => {
    return testDB
               .currentOp({
                   'command.drop': coll.getName(),
                   'command.collectionUUID': uuid,
                   'locks.Collection': 'w',
                   waitingForLock: true,
               })
               .inprog.length === 1;
});
 
assert.commandWorked(testDB.getSiblingDB('admin').killOp(sleepID));
sleepCommand();
firstDrop();
secondDrop();
})();



 Comments   
Comment by Githook User [ 15/Aug/22 ]

Author:

{'name': 'Faustoleyva54', 'email': 'fausto.leyva@mongodb.com', 'username': 'Faustoleyva54'}

Message: SERVER-67679 Fix concurrent collection drops from returning NamespaceNotFound instead of CollectionUUIDMismatch
Branch: v6.0
https://github.com/mongodb/mongo/commit/ffe4b7bdd411acfab2beee597ef0c95d046840da

Comment by Githook User [ 08/Aug/22 ]

Author:

{'name': 'Faustoleyva54', 'email': 'fausto.leyva@mongodb.com', 'username': 'Faustoleyva54'}

Message: SERVER-67679 Fix concurrent collection drops from returning NamespaceNotFound instead of CollectionUUIDMismatch
Branch: master
https://github.com/mongodb/mongo/commit/f6bd80cf73d0c3e9cbcb26b70e9c038d9edaed9a

Comment by Connie Chen [ 08/Jul/22 ]

gregory.noma@mongodb.com - What is the priority for this ticket, if it slips 6.1 would it be ok?

Generated at Thu Feb 08 06:08:46 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.