summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--jstests/sharding/clone_catalog_data.js14
-rw-r--r--jstests/sharding/move_primary_clone_test.js5
-rw-r--r--src/mongo/db/cloner.cpp6
3 files changed, 19 insertions, 6 deletions
diff --git a/jstests/sharding/clone_catalog_data.js b/jstests/sharding/clone_catalog_data.js
index 94d3ee8fd8f..2d47e1a05e3 100644
--- a/jstests/sharding/clone_catalog_data.js
+++ b/jstests/sharding/clone_catalog_data.js
@@ -106,14 +106,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;
@@ -127,8 +131,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_test.js b/jstests/sharding/move_primary_clone_test.js
index 404562e7cd1..74b1f2023ee 100644
--- a/jstests/sharding/move_primary_clone_test.js
+++ b/jstests/sharding/move_primary_clone_test.js
@@ -58,7 +58,10 @@ function checkCollectionsCopiedCorrectly(fromShard, toShard, sharded, barUUID, f
var indexes = res.cursor.firstBatch;
indexes.sort(sortByName);
- assert.eq(indexes.length, 2);
+ 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 8ea31c0e57e..49d7bf850a9 100644
--- a/src/mongo/db/cloner.cpp
+++ b/src/mongo/db/cloner.cpp
@@ -545,6 +545,12 @@ 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",