summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJack Mulrow <jack.mulrow@mongodb.com>2023-03-28 20:28:21 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2023-03-29 01:47:34 +0000
commit40e62357f5f3095adb33d00419cbd6194b8ae99c (patch)
tree0e0846d09ecdccef87cd69220cdebeb0a06a5b2a
parentc9615e6c12f0f478f423c6b6b9f6177db1c56363 (diff)
downloadmongo-40e62357f5f3095adb33d00419cbd6194b8ae99c.tar.gz
SERVER-75385 Clean up code from earlier catalog shard design
-rw-r--r--jstests/core/index/hidden_index.js8
-rw-r--r--src/mongo/db/ops/insert.cpp3
-rw-r--r--src/mongo/db/pipeline/sharded_agg_helpers.cpp16
-rw-r--r--src/mongo/db/s/config/sharding_catalog_manager_shard_operations.cpp17
4 files changed, 14 insertions, 30 deletions
diff --git a/jstests/core/index/hidden_index.js b/jstests/core/index/hidden_index.js
index 572d9016ae0..248b3c7b875 100644
--- a/jstests/core/index/hidden_index.js
+++ b/jstests/core/index/hidden_index.js
@@ -133,11 +133,9 @@ assert.eq(idxSpec.hidden, true);
const systemColl = db.getSiblingDB("admin").system.version;
assert.commandWorked(systemColl.createIndex({a: 1}));
// The collMod command throws NoShardingEnabled on DDL coordinator implementation and BadValue on
-// old implementation. When the config server supports catalog shard mode, it fails with
-// ShardingStateNotInitialized.
-assert.commandFailedWithCode(
- systemColl.hideIndex("a_1"),
- [ErrorCodes.NoShardingEnabled, ErrorCodes.BadValue, ErrorCodes.ShardingStateNotInitialized]);
+// old implementation.
+assert.commandFailedWithCode(systemColl.hideIndex("a_1"),
+ [ErrorCodes.NoShardingEnabled, ErrorCodes.BadValue]);
assert.commandFailedWithCode(systemColl.createIndex({a: 1}, {hidden: true}), 2);
// Can't hide the '_id' index.
diff --git a/src/mongo/db/ops/insert.cpp b/src/mongo/db/ops/insert.cpp
index a1832c530e7..c7f18b2ab5f 100644
--- a/src/mongo/db/ops/insert.cpp
+++ b/src/mongo/db/ops/insert.cpp
@@ -206,8 +206,7 @@ Status userAllowedCreateNS(OperationContext* opCtx, const NamespaceString& ns) {
str::stream() << "Invalid collection name: " << ns.coll());
}
- if (serverGlobalParams.clusterRole == ClusterRole::ConfigServer && !ns.isOnInternalDb() &&
- !ShardingState::get(opCtx)->enabled()) {
+ if (serverGlobalParams.clusterRole.isExclusivelyConfigSvrRole() && !ns.isOnInternalDb()) {
return Status(ErrorCodes::InvalidNamespace,
str::stream()
<< "Can't create user databases on a dedicated --configsvr instance "
diff --git a/src/mongo/db/pipeline/sharded_agg_helpers.cpp b/src/mongo/db/pipeline/sharded_agg_helpers.cpp
index 9381748a04e..2f72457e2b8 100644
--- a/src/mongo/db/pipeline/sharded_agg_helpers.cpp
+++ b/src/mongo/db/pipeline/sharded_agg_helpers.cpp
@@ -1557,13 +1557,8 @@ StatusWith<CollectionRoutingInfo> getExecutionNsRoutingInfo(OperationContext* op
// a collection before its enclosing database is created. However, if there are no shards
// present, then $changeStream should immediately return an empty cursor just as other
// aggregations do when the database does not exist.
- //
- // Note despite config.collections always being unsharded, to support $shardedDataDistribution
- // we always take the shard targeting path. The collection must only exist on the config server,
- // so even if there are no shards, the query can still succeed and we shouldn't return
- // ShardNotFound.
const auto shardIds = Grid::get(opCtx)->shardRegistry()->getAllShardIds(opCtx);
- if (shardIds.empty() && execNss != NamespaceString::kConfigsvrCollectionsNamespace) {
+ if (shardIds.empty()) {
return {ErrorCodes::ShardNotFound, "No shards are present in the cluster"};
}
@@ -1644,7 +1639,8 @@ std::unique_ptr<Pipeline, PipelineDeleter> attachCursorToPipeline(
auto pipelineToTarget = pipeline->clone();
if (!cm.isSharded() &&
- (gFeatureFlagCatalogShard.isEnabled(serverGlobalParams.featureCompatibility) ||
+ // TODO SERVER-75391: Remove this condition.
+ (serverGlobalParams.clusterRole == ClusterRole::ConfigServer ||
expCtx->ns != NamespaceString::kConfigsvrCollectionsNamespace)) {
// If the collection is unsharded and we are on the primary, we should be able to
// do a local read. The primary may be moved right after the primary shard check,
@@ -1654,9 +1650,9 @@ std::unique_ptr<Pipeline, PipelineDeleter> attachCursorToPipeline(
// There is the case where we are in config.collections (collection unsharded) and
// we want to broadcast to all shards for the $shardedDataDistribution pipeline. In
// this case we don't want to do a local read and we must target the config servers.
- // If the catalog shard feature flag is enabled in the current FCV, read locally
- // because all nodes in the cluster should be running a recent enough binary so only
- // the config server will be targeted for the pipeline.
+ // In 7.0, only the config server will be targeted for this collection, but in a
+ // mixed version cluster, an older binary mongos may still target a shard, so if the
+ // current node is not the config server, we force remote targeting.
try {
auto expectUnshardedCollection(
expCtx->mongoProcessInterface->expectUnshardedCollectionInScope(
diff --git a/src/mongo/db/s/config/sharding_catalog_manager_shard_operations.cpp b/src/mongo/db/s/config/sharding_catalog_manager_shard_operations.cpp
index 560d8e237f7..f27ac525b62 100644
--- a/src/mongo/db/s/config/sharding_catalog_manager_shard_operations.cpp
+++ b/src/mongo/db/s/config/sharding_catalog_manager_shard_operations.cpp
@@ -432,19 +432,10 @@ StatusWith<ShardType> ShardingCatalogManager::_validateHostAsShard(
}
// Is it a config server?
- if (resIsMaster.hasField("configsvr")) {
- if (!isCatalogShard) {
- return {ErrorCodes::OperationFailed,
- str::stream() << "Cannot add " << connectionString.toString()
- << " as a shard since it is a config server"};
- }
-
- auto ourSetName = repl::ReplicationCoordinator::get(opCtx)->getSettings().ourSetName();
- if (providedSetName != ourSetName) {
- return {ErrorCodes::OperationFailed,
- str::stream() << "Cannot add " << connectionString.toString()
- << " as a catalog shard since it is a different config server"};
- }
+ if (resIsMaster.hasField("configsvr") && !isCatalogShard) {
+ return {ErrorCodes::OperationFailed,
+ str::stream() << "Cannot add " << connectionString.toString()
+ << " as a shard since it is a config server"};
}
if (resIsMaster.hasField(HelloCommandReply::kIsImplicitDefaultMajorityWCFieldName) &&