diff options
author | Benety Goh <benety@mongodb.com> | 2017-12-20 15:41:57 -0500 |
---|---|---|
committer | Benety Goh <benety@mongodb.com> | 2017-12-29 11:48:08 -0500 |
commit | 9fc948694d27b5ed78f713b026cb6e5661c95551 (patch) | |
tree | bc77e48827a1a6b5fb07ec4dc444ae16abef856f /jstests/replsets | |
parent | e304b58275d36a1c28d0e652582268c070f599b7 (diff) | |
download | mongo-9fc948694d27b5ed78f713b026cb6e5661c95551.tar.gz |
SERVER-32098 renaming drop-pending collection fails with NamespaceNotFound
Diffstat (limited to 'jstests/replsets')
-rw-r--r-- | jstests/replsets/drop_collections_two_phase_apply_ops_rename.js | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/jstests/replsets/drop_collections_two_phase_apply_ops_rename.js b/jstests/replsets/drop_collections_two_phase_apply_ops_rename.js new file mode 100644 index 00000000000..85c9bbab953 --- /dev/null +++ b/jstests/replsets/drop_collections_two_phase_apply_ops_rename.js @@ -0,0 +1,74 @@ +/** + * Test to ensure that using applyOps to rename a drop-pending collection is a no-op. The collection + * remains in a drop-pending state. This is the same behavior as renaming a non-existent collection. + */ + +(function() { + "use strict"; + + load("jstests/replsets/libs/two_phase_drops.js"); // For TwoPhaseDropCollectionTest. + + // Set up a two phase drop test. + let testName = "drop_collection_two_phase_apply_ops_rename"; + let dbName = testName; + let collName = "collToDrop"; + let twoPhaseDropTest = new TwoPhaseDropCollectionTest(testName, dbName); + + // Initialize replica set. + let replTest = twoPhaseDropTest.initReplSet(); + + // Create the collection that will be dropped. + twoPhaseDropTest.createCollection(collName); + + // PREPARE collection drop. + twoPhaseDropTest.prepareDropCollection(collName); + + try { + // Rename drop-pending collection using applyOps with system.drop namespace. + const dropPendingColl = twoPhaseDropTest.collectionIsPendingDrop(collName); + const dropPendingCollName = dropPendingColl.name; + const primary = replTest.getPrimary(); + const cmdNs = dbName + '.$cmd'; + const sourceNs = dbName + '.' + dropPendingCollName; + const destNs = dbName + '.bar'; + const applyOpsCmdWithName = { + applyOps: [{op: 'c', ns: cmdNs, o: {renameCollection: sourceNs, to: destNs}}] + }; + TwoPhaseDropCollectionTest._testLog( + 'Attempting to rename collection using applyOps with system.drop namespace: ' + + tojson(applyOpsCmdWithName)); + assert.commandWorked(primary.adminCommand(applyOpsCmdWithName)); + assert(twoPhaseDropTest.collectionIsPendingDrop(collName), + 'applyOps using collection name ' + dropPendingCollName + + ' renamed drop-pending collection unexpectedly'); + assert(!twoPhaseDropTest.collectionExists(collName)); + + // Rename drop-pending collection using applyOps with UUID. + const dropPendingCollUuid = dropPendingColl.info.uuid; + const applyOpsCmdWithUuid = { + applyOps: [{ + op: 'c', + ns: cmdNs, + ui: dropPendingCollUuid, + o: {renameCollection: dbName + '.ignored_collection_name', to: destNs} + }] + }; + TwoPhaseDropCollectionTest._testLog( + 'Attempting to rename collection using applyOps with UUID: ' + + tojson(applyOpsCmdWithUuid)); + assert.commandWorked(primary.adminCommand(applyOpsCmdWithUuid)); + const dropPendingCollInfo = twoPhaseDropTest.collectionIsPendingDrop(collName); + assert(dropPendingCollInfo, + 'applyOps using UUID ' + dropPendingCollUuid + + ' renamed drop-pending collection unexpectedly'); + assert.eq(dropPendingCollUuid.hex(), + dropPendingCollInfo.info.uuid.hex(), + 'drop pending collection UUID does not match UUID of original collection: ' + + tojson(dropPendingCollInfo)); + + // COMMIT collection drop. + twoPhaseDropTest.commitDropCollection(collName); + } finally { + twoPhaseDropTest.stop(); + } +}()); |