summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergi Mateo Bellido <sergi.mateo-bellido@mongodb.com>2023-02-22 11:44:24 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2023-03-17 12:41:09 +0000
commit988151ae978b51b5c4c9b28424c96ab6b0a436ce (patch)
tree489cf66b87a8d952bc42acc92638fa972786857c
parent5215370322146e1434ae094529d0049d84fe9988 (diff)
downloadmongo-988151ae978b51b5c4c9b28424c96ab6b0a436ce.tar.gz
SERVER-73751 MovePrimary shouldn't copy indexes of sharded collections
(cherry picked from commit c636ba3a9914fd3eddc905d8b1dfc50668e239b4)
-rw-r--r--jstests/sharding/clone_catalog_data.js14
-rw-r--r--jstests/sharding/move_primary_clone.js7
-rw-r--r--src/mongo/db/cloner.cpp7
3 files changed, 22 insertions, 6 deletions
diff --git a/jstests/sharding/clone_catalog_data.js b/jstests/sharding/clone_catalog_data.js
index d87e2dd1e11..264b0550db5 100644
--- a/jstests/sharding/clone_catalog_data.js
+++ b/jstests/sharding/clone_catalog_data.js
@@ -108,14 +108,18 @@
checkOptions(c2, Object.keys(coll2Options));
checkUUID(c2, coll2uuid);
- function checkIndexes(collName, expectedIndexes) {
+ function checkIndexes(collName, expectedIndexes, shardedColl) {
var res = toShard.getDB('test').runCommand({listIndexes: collName});
assert.commandWorked(res, 'Failed to get indexes for collection ' + collName);
var indexes = res.cursor.firstBatch;
indexes.sort(sortByName);
- // There should be 3 indexes on each collection - the _id one, and the 2 we created.
- assert.eq(indexes.length, 3);
+ // TODO SERVER-74252: once 7.0 becomes LastLTS we can assume that the movePrimary will never
+ // copy indexes of sharded collections.
+ if (shardedColl)
+ assert(indexes.length === 1 || indexes.length === 3);
+ else
+ assert(indexes.length === 3);
indexes.forEach((index, i) => {
var expected;
@@ -129,8 +133,8 @@
});
}
- checkIndexes('coll1', coll1Indexes);
- checkIndexes('coll2', coll2Indexes);
+ checkIndexes('coll1', coll1Indexes, /*shardedColl*/ false);
+ checkIndexes('coll2', coll2Indexes, /*shardedColl*/ true);
// Verify that the data from the unsharded collections resides on the new primary shard, and was
// copied as part of the clone.
diff --git a/jstests/sharding/move_primary_clone.js b/jstests/sharding/move_primary_clone.js
index a2ccc7eabac..7eeebf5397e 100644
--- a/jstests/sharding/move_primary_clone.js
+++ b/jstests/sharding/move_primary_clone.js
@@ -60,7 +60,12 @@ function checkCollectionsCopiedCorrectly(fromShard, toShard, sharded, barUUID, f
var indexes = res.cursor.firstBatch;
indexes.sort(sortByName);
- assert.eq(indexes.length, 2);
+ // TODO SERVER-74252: once 7.0 becomes LastLTS we can assume that the movePrimary will never
+ // copy indexes of sharded collections.
+ if (sharded)
+ assert(indexes.length == 1 || indexes.length == 2);
+ else
+ assert(indexes.length == 2);
indexes.forEach((index, i) => {
var expected;
diff --git a/src/mongo/db/cloner.cpp b/src/mongo/db/cloner.cpp
index 6450593641e..5ab99fc0f44 100644
--- a/src/mongo/db/cloner.cpp
+++ b/src/mongo/db/cloner.cpp
@@ -539,6 +539,13 @@ Status Cloner::copyDb(OperationContext* opCtx,
// now build the secondary indexes
for (auto&& params : createCollectionParams) {
+
+ // Indexes of sharded collections are not copied: the primary shard is not required to
+ // have all indexes. The listIndexes cmd is sent to the shard owning the MinKey value.
+ if (params.shardedColl) {
+ continue;
+ }
+
LOGV2(20422,
"copying indexes for: {collectionInfo}",
"Copying indexes",