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-27 06:05:32 +0000
commit8fdd3caaae08ef4f4e97299fb82d802c22c24af6 (patch)
tree2177da098023477cf05e74f1125642989e060f0e
parentbf77686ba9d6707aaf3ec594b447e39fbcecf5b4 (diff)
downloadmongo-8fdd3caaae08ef4f4e97299fb82d802c22c24af6.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_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",