From feb2dfc188dd4108224c85ab03b0dd0d7ceaa8ea Mon Sep 17 00:00:00 2001 From: Pierlauro Sciarelli Date: Mon, 16 May 2022 15:45:52 +0000 Subject: SERVER-66031 rename must succeed on all shards when UUIDs provided for C2C --- jstests/sharding/rename_sharded.js | 30 +++++++++++++++++++++- .../db/s/rename_collection_participant_service.cpp | 2 -- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/jstests/sharding/rename_sharded.js b/jstests/sharding/rename_sharded.js index 87f98dee46b..c352ebf4f20 100644 --- a/jstests/sharding/rename_sharded.js +++ b/jstests/sharding/rename_sharded.js @@ -221,12 +221,12 @@ const mongos = st.s0; assert.commandFailed(fromColl.renameCollection(toNs.split('.')[1], false /* dropTarget*/)); } +const fcvDoc = testDB.adminCommand({getParameter: 1, featureCompatibilityVersion: 1}); // Rename to target collection with very a long name { const dbName = 'testRenameToCollectionWithVeryLongName'; const testDB = st.rs0.getPrimary().getDB(dbName); - const fcvDoc = testDB.adminCommand({getParameter: 1, featureCompatibilityVersion: 1}); if (MongoRunner.compareBinVersions(fcvDoc.featureCompatibilityVersion.version, '5.3') >= 0) { const longEnoughNs = dbName + '.' + 'x'.repeat(235 - dbName.length - 1); @@ -237,4 +237,32 @@ const mongos = st.s0; } } +// For C2C: rename of existing collection with correct uuid as argument must succeed +// (Also creating target collection to test target UUID internal check) +if (MongoRunner.compareBinVersions(fcvDoc.featureCompatibilityVersion.version, '6.0') >= 0) { + const dbName = 'testRenameToUnshardedCollectionWithSourceUUID'; + const fromCollName = 'from'; + const fromNs = dbName + '.' + fromCollName; + const toNs = dbName + '.to'; + assert.commandWorked( + mongos.adminCommand({enablesharding: dbName, primaryShard: st.shard0.shardName})); + const fromColl = mongos.getCollection(fromNs); + fromColl.insert({a: 0}); + + const toColl = mongos.getCollection(toNs); + toColl.insert({b: 0}); + + const sourceUUID = assert.commandWorked(st.getDB(dbName).runCommand({listCollections: 1})) + .cursor.firstBatch.find(c => c.name === fromCollName) + .info.uuid; + + // The command succeeds when the correct UUID is provided. + assert.commandWorked(mongos.adminCommand({ + renameCollection: fromNs, + to: toNs, + dropTarget: true, + collectionUUID: sourceUUID, + })); +} + st.stop(); diff --git a/src/mongo/db/s/rename_collection_participant_service.cpp b/src/mongo/db/s/rename_collection_participant_service.cpp index bf2766e668d..e09cb196980 100644 --- a/src/mongo/db/s/rename_collection_participant_service.cpp +++ b/src/mongo/db/s/rename_collection_participant_service.cpp @@ -328,8 +328,6 @@ SemiFuture RenameParticipantInstance::_runImpl( RenameCollectionOptions options; options.dropTarget = _doc.getDropTarget(); options.stayTemp = _doc.getStayTemp(); - options.expectedSourceUUID = _doc.getExpectedSourceUUID(); - options.expectedTargetUUID = _doc.getExpectedTargetUUID(); renameOrDropTarget( opCtx, fromNss(), toNss(), options, _doc.getSourceUUID(), _doc.getTargetUUID()); -- cgit v1.2.1