summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPol Pinol Castuera <pol.pinol@mongodb.com>2022-12-20 07:42:20 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2022-12-20 08:13:32 +0000
commita95672fe5d79b1f93164ab15743197ae9f4c6661 (patch)
tree19b193345b8dd72fef8e1a6c4b51dd0f4f3bacf1 /src
parent99edb0c1a7aabf41d4a6d92cdf5b6511e82a3333 (diff)
downloadmongo-a95672fe5d79b1f93164ab15743197ae9f4c6661.tar.gz
SERVER-71668 Move isLastNonHiddenShardKeyIndex check after hide index on system collection and hide _id index in coll_mod.cpp
Diffstat (limited to 'src')
-rw-r--r--src/mongo/db/catalog/coll_mod.cpp43
1 files changed, 22 insertions, 21 deletions
diff --git a/src/mongo/db/catalog/coll_mod.cpp b/src/mongo/db/catalog/coll_mod.cpp
index a085acab5fa..2365fb8d124 100644
--- a/src/mongo/db/catalog/coll_mod.cpp
+++ b/src/mongo/db/catalog/coll_mod.cpp
@@ -291,27 +291,6 @@ StatusWith<std::pair<ParsedCollModRequest, BSONObj>> parseCollModRequest(Operati
cmrIndex->idx = indexes[0];
}
- if (cmdIndex.getHidden()) {
- // Checks if it is possible to drop the shard key, so it could be possible to hide it
- if (auto catalogClient = Grid::get(opCtx)->catalogClient()) {
- try {
- auto shardedColl = catalogClient->getCollection(opCtx, nss);
-
- if (isLastNonHiddenShardKeyIndex(opCtx,
- coll,
- coll->getIndexCatalog(),
- cmrIndex->idx->indexName(),
- shardedColl.getKeyPattern().toBSON())) {
- return {ErrorCodes::InvalidOptions,
- "Cannot hide the only compatible index for this collection's shard "
- "key"};
- }
- } catch (ExceptionFor<ErrorCodes::NamespaceNotFound>&) {
- // The collection is unsharded or doesn't exist.
- }
- }
- }
-
if (cmdIndex.getExpireAfterSeconds()) {
parsed.numModifications++;
BSONElement oldExpireSecs = cmrIndex->idx->infoObj().getField("expireAfterSeconds");
@@ -374,6 +353,28 @@ StatusWith<std::pair<ParsedCollModRequest, BSONObj>> parseCollModRequest(Operati
return {ErrorCodes::BadValue, "can't hide _id index"};
}
+ // If the index is not hidden and we are trying to hide it, check if it is possible
+ // to drop the shard key index, so it could be possible to hide it.
+ if (!cmrIndex->idx->hidden() && *cmdIndex.getHidden()) {
+ if (auto catalogClient = Grid::get(opCtx)->catalogClient()) {
+ try {
+ auto shardedColl = catalogClient->getCollection(opCtx, nss);
+
+ if (isLastNonHiddenShardKeyIndex(opCtx,
+ coll,
+ coll->getIndexCatalog(),
+ cmrIndex->idx->indexName(),
+ shardedColl.getKeyPattern().toBSON())) {
+ return {ErrorCodes::InvalidOptions,
+ "Can't hide the only compatible index for this collection's "
+ "shard key"};
+ }
+ } catch (ExceptionFor<ErrorCodes::NamespaceNotFound>&) {
+ // The collection is unsharded or doesn't exist.
+ }
+ }
+ }
+
// Hiding a hidden index or unhiding a visible index should be treated as a no-op.
if (cmrIndex->idx->hidden() == *cmdIndex.getHidden()) {
indexForOplog->setHidden(boost::none);