summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJack Mulrow <jack.mulrow@mongodb.com>2023-02-22 19:49:50 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2023-02-23 00:22:25 +0000
commit09fe46995dca6375632632f5fc334035359db870 (patch)
tree463cf1b01b1c1de5b1ab7684c294b50b3a65013e /src
parent24f148eec2575aff086f596075441cbfde79b9bc (diff)
downloadmongo-09fe46995dca6375632632f5fc334035359db870.tar.gz
SERVER-73865 Use config shard name for the config server
Diffstat (limited to 'src')
-rw-r--r--src/mongo/db/commands/set_feature_compatibility_version_command.cpp4
-rw-r--r--src/mongo/db/pipeline/sharded_agg_helpers.cpp10
-rw-r--r--src/mongo/db/s/config/sharding_catalog_manager_add_shard_test.cpp2
-rw-r--r--src/mongo/db/s/config/sharding_catalog_manager_shard_operations.cpp6
-rw-r--r--src/mongo/db/shard_id.cpp3
-rw-r--r--src/mongo/db/shard_id.h1
-rw-r--r--src/mongo/s/client/shard_registry.cpp6
-rw-r--r--src/mongo/s/client/shard_remote.cpp5
-rw-r--r--src/mongo/s/client/sharding_network_connection_hook.cpp16
-rw-r--r--src/mongo/s/cluster_commands_helpers.cpp10
-rw-r--r--src/mongo/s/commands/cluster_analyze_shard_key_cmd.cpp4
-rw-r--r--src/mongo/s/commands/cluster_list_databases_cmd.cpp11
-rw-r--r--src/mongo/s/commands/cluster_split_vector_cmd.cpp2
-rw-r--r--src/mongo/s/query/cluster_aggregate.cpp4
-rw-r--r--src/mongo/s/query/cluster_aggregation_planner.cpp4
-rw-r--r--src/mongo/shell/shardingtest.js2
16 files changed, 38 insertions, 52 deletions
diff --git a/src/mongo/db/commands/set_feature_compatibility_version_command.cpp b/src/mongo/db/commands/set_feature_compatibility_version_command.cpp
index e1b1faf56fd..11deb0947d3 100644
--- a/src/mongo/db/commands/set_feature_compatibility_version_command.cpp
+++ b/src/mongo/db/commands/set_feature_compatibility_version_command.cpp
@@ -359,13 +359,13 @@ public:
FeatureCompatibilityVersion::enterFCVChangeRegion(opCtx));
// If catalogShard is enabled and there is an entry in config.shards with _id:
- // ShardId::kCatalogShardId then the config server is a catalog shard
+ // ShardId::kConfigServerId then the config server is a catalog shard.
auto isCatalogShard = serverGlobalParams.clusterRole == ClusterRole::ConfigServer &&
serverGlobalParams.clusterRole == ClusterRole::ShardServer &&
!ShardingCatalogManager::get(opCtx)
->findOneConfigDocument(opCtx,
NamespaceString::kConfigsvrShardsNamespace,
- BSON("_id" << ShardId::kCatalogShardId.toString()))
+ BSON("_id" << ShardId::kConfigServerId.toString()))
.isEmpty();
// TODO SERVER-73784: Update catalog_shard_feature_flag.idl so that the version for
diff --git a/src/mongo/db/pipeline/sharded_agg_helpers.cpp b/src/mongo/db/pipeline/sharded_agg_helpers.cpp
index c43ef0c810f..88ef19f4c3e 100644
--- a/src/mongo/db/pipeline/sharded_agg_helpers.cpp
+++ b/src/mongo/db/pipeline/sharded_agg_helpers.cpp
@@ -223,8 +223,8 @@ std::vector<RemoteCursor> establishShardCursors(
}
} else {
// The collection is unsharded. Target only the primary shard for the database.
- // Don't append shard version info when contacting the config servers.
- auto versionedCmdObj = cri->cm.dbPrimary() != ShardId::kConfigServerId
+ // Don't append shard version info when contacting a fixed db collection.
+ auto versionedCmdObj = !cri->cm.dbVersion().isFixed()
? appendShardVersion(cmdObj, ShardVersion::UNSHARDED())
: cmdObj;
versionedCmdObj = appendDbVersionIfPresent(versionedCmdObj, cri->cm.dbVersion());
@@ -845,9 +845,9 @@ std::unique_ptr<Pipeline, PipelineDeleter> runPipelineDirectlyOnSingleShard(
return appendShardVersion(aggregation_request_helper::serializeToCommandObj(request),
cri.getShardVersion(shardId));
} else {
- // The collection is unsharded. Don't append shard version info when contacting the
- // config servers.
- const auto cmdObjWithShardVersion = (shardId != ShardId::kConfigServerId)
+ // The collection is unsharded. Don't append shard version info when contacting a fixed
+ // db collection.
+ const auto cmdObjWithShardVersion = !cri.cm.dbVersion().isFixed()
? appendShardVersion(aggregation_request_helper::serializeToCommandObj(request),
ShardVersion::UNSHARDED())
: aggregation_request_helper::serializeToCommandObj(request);
diff --git a/src/mongo/db/s/config/sharding_catalog_manager_add_shard_test.cpp b/src/mongo/db/s/config/sharding_catalog_manager_add_shard_test.cpp
index 45997339039..19bf2a00fce 100644
--- a/src/mongo/db/s/config/sharding_catalog_manager_add_shard_test.cpp
+++ b/src/mongo/db/s/config/sharding_catalog_manager_add_shard_test.cpp
@@ -49,6 +49,7 @@
#include "mongo/db/s/type_shard_identity.h"
#include "mongo/idl/cluster_server_parameter_common.h"
#include "mongo/idl/cluster_server_parameter_gen.h"
+#include "mongo/idl/server_parameter_test_util.h"
#include "mongo/logv2/log.h"
#include "mongo/s/catalog/sharding_catalog_client.h"
#include "mongo/s/catalog/type_changelog.h"
@@ -1424,6 +1425,7 @@ TEST_F(AddShardTest, SuccessfullyAddReplicaSet) {
TEST_F(AddShardTest, SuccessfullyAddConfigShard) {
std::unique_ptr<RemoteCommandTargeterMock> targeter(
std::make_unique<RemoteCommandTargeterMock>());
+ RAIIServerParameterControllerForTest featureFlagController("featureFlagCatalogShard", true);
ConnectionString connString =
assertGet(ConnectionString::parse("mySet/host1:12345,host2:12345"));
targeter->setConnectionStringReturnValue(connString);
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 4bbe1aa6e0d..b0642ea686f 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
@@ -612,7 +612,7 @@ void ShardingCatalogManager::installConfigShardIdentityDocument(OperationContext
// Insert a shard identity document. Note we insert with local write concern, so the shard
// identity may roll back, which will trigger an fassert to clear the in-memory sharding state.
{
- auto addShardCmd = add_shard_util::createAddShardCmd(opCtx, ShardId::kCatalogShardId);
+ auto addShardCmd = add_shard_util::createAddShardCmd(opCtx, ShardId::kConfigServerId);
auto shardIdUpsertCmd = add_shard_util::createShardIdentityUpsertForAddShard(
addShardCmd, ShardingCatalogClient::kLocalWriteConcern);
@@ -765,7 +765,7 @@ StatusWith<std::string> ShardingCatalogManager::addShard(
"Cannot add catalog shard because it is not supported in featureCompatibilityVersion: {}"_format(
multiversion::toString(serverGlobalParams.featureCompatibility.getVersion())),
gFeatureFlagCatalogShard.isEnabled(serverGlobalParams.featureCompatibility) ||
- shardType.getName() != ShardId::kCatalogShardId.toString());
+ !isCatalogShard);
uassert(5563603,
"Cannot add shard while in upgrading/downgrading FCV state",
@@ -1011,7 +1011,7 @@ RemoveShardProgress ShardingCatalogManager::removeShard(OperationContext* opCtx,
// set monitor is removed, otherwise the shard would be referencing a dropped RSM.
Grid::get(opCtx)->shardRegistry()->reload(opCtx);
- if (shardId != ShardId::kCatalogShardId) {
+ if (shardId != ShardId::kConfigServerId) {
// Don't remove the catalog shard's RSM because it is used to target the config server.
ReplicaSetMonitor::remove(name);
}
diff --git a/src/mongo/db/shard_id.cpp b/src/mongo/db/shard_id.cpp
index 445abe37baa..39d66aa56a7 100644
--- a/src/mongo/db/shard_id.cpp
+++ b/src/mongo/db/shard_id.cpp
@@ -35,9 +35,6 @@ namespace mongo {
const ShardId ShardId::kConfigServerId("config");
-// TODO SERVER-XXXXX: Use "config" shard id instead.
-const ShardId ShardId::kCatalogShardId("catalogShard");
-
bool ShardId::isValid() const {
return !_shardId.empty();
}
diff --git a/src/mongo/db/shard_id.h b/src/mongo/db/shard_id.h
index b99469d1459..798f8e427a1 100644
--- a/src/mongo/db/shard_id.h
+++ b/src/mongo/db/shard_id.h
@@ -43,7 +43,6 @@ namespace mongo {
class ShardId {
public:
static const ShardId kConfigServerId;
- static const ShardId kCatalogShardId;
ShardId(std::string shardId) : _shardId(std::move(shardId)) {}
diff --git a/src/mongo/s/client/shard_registry.cpp b/src/mongo/s/client/shard_registry.cpp
index 77e02f641c6..3f194e72edb 100644
--- a/src/mongo/s/client/shard_registry.cpp
+++ b/src/mongo/s/client/shard_registry.cpp
@@ -188,7 +188,7 @@ ShardRegistry::Cache::LookupResult ShardRegistry::_lookup(OperationContext* opCt
invariant(shard);
auto name = shard->getConnString().getSetName();
- if (shardId != ShardId::kCatalogShardId) {
+ if (shardId != ShardId::kConfigServerId) {
// Don't remove the catalog shard's RSM because it is used to target the config server.
ReplicaSetMonitor::remove(name);
}
@@ -643,10 +643,6 @@ std::pair<ShardRegistryData, Timestamp> ShardRegistryData::createFromCatalogClie
ShardRegistryData data;
for (auto& shardInfo : shardsInfo) {
- if (std::get<0>(shardInfo) == "config") {
- continue;
- }
-
auto shard = shardFactory->createShard(std::move(std::get<0>(shardInfo)),
std::move(std::get<1>(shardInfo)));
diff --git a/src/mongo/s/client/shard_remote.cpp b/src/mongo/s/client/shard_remote.cpp
index 658c6de68ed..9331ba70e29 100644
--- a/src/mongo/s/client/shard_remote.cpp
+++ b/src/mongo/s/client/shard_remote.cpp
@@ -504,7 +504,10 @@ StatusWith<ShardRemote::AsyncCmdHandle> ShardRemote::_scheduleCommand(
const TaskExecutor::RemoteCommandCallbackFn& cb) {
const auto readPrefWithConfigTime = [&]() -> ReadPreferenceSetting {
- if (isConfig()) {
+ // TODO SERVER-74281: Append this higher up when we know we're targeting the config to read
+ // metadata or use a better filter to avoid matching logical sessions collection.
+ if (isConfig() &&
+ (dbName == NamespaceString::kConfigDb || dbName == NamespaceString::kAdminDb)) {
const auto vcTime = VectorClock::get(opCtx)->getTime();
ReadPreferenceSetting readPrefToReturn{readPref};
readPrefToReturn.minClusterTime = vcTime.configTime().asTimestamp();
diff --git a/src/mongo/s/client/sharding_network_connection_hook.cpp b/src/mongo/s/client/sharding_network_connection_hook.cpp
index b3ebb145975..fda37ac9f5b 100644
--- a/src/mongo/s/client/sharding_network_connection_hook.cpp
+++ b/src/mongo/s/client/sharding_network_connection_hook.cpp
@@ -62,26 +62,12 @@ Status ShardingNetworkConnectionHook::validateHostImpl(
}
long long configServerModeNumber;
- auto isMasterReplyData = isMasterReply.data;
- auto status = bsonExtractIntegerField(isMasterReplyData, "configsvr", &configServerModeNumber);
+ auto status = bsonExtractIntegerField(isMasterReply.data, "configsvr", &configServerModeNumber);
switch (status.code()) {
case ErrorCodes::OK: {
// The ismaster response indicates remoteHost is a config server.
if (!shard->isConfig()) {
- auto isMasterSetName = isMasterReplyData.getStringField("setName");
- // getSetName() can return an empty string for a non-replica set but config servers
- // are always a replica set, so we can skip that check here.
- auto configSetName = Grid::get(getGlobalServiceContext())
- ->shardRegistry()
- ->getConfigShard()
- ->getConnString()
- .getSetName();
- if (gFeatureFlagCatalogShard.isEnabledAndIgnoreFCV() &&
- isMasterSetName == configSetName) {
- return Status::OK();
- }
-
return {ErrorCodes::InvalidOptions,
str::stream() << "Surprised to discover that " << remoteHost.toString()
<< " believes it is a config server"};
diff --git a/src/mongo/s/cluster_commands_helpers.cpp b/src/mongo/s/cluster_commands_helpers.cpp
index 421015fbe20..2375122c485 100644
--- a/src/mongo/s/cluster_commands_helpers.cpp
+++ b/src/mongo/s/cluster_commands_helpers.cpp
@@ -152,8 +152,8 @@ std::vector<AsyncRequestsSender::Request> buildVersionedRequestsForTargetedShard
return {};
}
- // Attach shardVersion "UNSHARDED", unless targeting the config server.
- auto cmdObjWithVersions = (primaryShardId != ShardId::kConfigServerId)
+ // Attach shardVersion "UNSHARDED", unless targeting a fixed db collection.
+ auto cmdObjWithVersions = !cm.dbVersion().isFixed()
? appendShardVersion(cmdObj, ShardVersion::UNSHARDED())
: cmdObj;
cmdObjWithVersions = appendDbVersionIfPresent(cmdObjWithVersions, cm.dbVersion());
@@ -461,8 +461,8 @@ AsyncRequestsSender::Response executeCommandAgainstDatabasePrimary(
const BSONObj& cmdObj,
const ReadPreferenceSetting& readPref,
Shard::RetryPolicy retryPolicy) {
- // Attach shardVersion "UNSHARDED", unless targeting the config server.
- const auto cmdObjWithShardVersion = (dbInfo->getPrimary() != ShardId::kConfigServerId)
+ // Attach shardVersion "UNSHARDED", unless targeting a fixed db collection.
+ const auto cmdObjWithShardVersion = !dbInfo->getVersion().isFixed()
? appendShardVersion(cmdObj, ShardVersion::UNSHARDED())
: cmdObj;
@@ -737,7 +737,7 @@ StatusWith<Shard::QueryResponse> loadIndexesFromAuthoritativeShard(OperationCont
} else {
// For an unsharded collection, the primary shard will have correct indexes. We attach
// unsharded shard version to detect if the collection has become sharded.
- const auto cmdObjWithShardVersion = (cm.dbPrimary() != ShardId::kConfigServerId)
+ const auto cmdObjWithShardVersion = !cm.dbVersion().isFixed()
? appendShardVersion(cmdNoVersion, ShardVersion::UNSHARDED())
: cmdNoVersion;
return {
diff --git a/src/mongo/s/commands/cluster_analyze_shard_key_cmd.cpp b/src/mongo/s/commands/cluster_analyze_shard_key_cmd.cpp
index 45935adb538..7acf8c2964c 100644
--- a/src/mongo/s/commands/cluster_analyze_shard_key_cmd.cpp
+++ b/src/mongo/s/commands/cluster_analyze_shard_key_cmd.cpp
@@ -111,8 +111,8 @@ public:
candidateShardIds.erase(shardId);
uassert(ErrorCodes::IllegalOperation,
- "Cannot analyze a shard key for a collection on the config server",
- shardId != ShardId::kConfigServerId);
+ "Cannot analyze a shard key for a collection in a fixed database",
+ !cri.cm.dbVersion().isFixed());
// Build a versioned command for the selected shard.
auto versionedCmdObj = makeVersionedCmdObj(cri, unversionedCmdObj, shardId);
diff --git a/src/mongo/s/commands/cluster_list_databases_cmd.cpp b/src/mongo/s/commands/cluster_list_databases_cmd.cpp
index 107f904f694..e912b125556 100644
--- a/src/mongo/s/commands/cluster_list_databases_cmd.cpp
+++ b/src/mongo/s/commands/cluster_list_databases_cmd.cpp
@@ -105,7 +105,11 @@ public:
std::map<std::string, std::unique_ptr<BSONObjBuilder>> dbShardInfo;
auto shardIds = shardRegistry->getAllShardIds(opCtx);
- shardIds.emplace_back(ShardId::kConfigServerId);
+ if (std::find(shardIds.begin(), shardIds.end(), ShardId::kConfigServerId) ==
+ shardIds.end()) {
+ // The config server may be a shard, so only add if it isn't already in shardIds.
+ shardIds.emplace_back(ShardId::kConfigServerId);
+ }
// { filter: matchExpression }.
auto filteredCmd = applyReadWriteConcern(
@@ -138,11 +142,6 @@ public:
continue;
}
- // We don't collect config server info for dbs other than "admin" and "config".
- if (s->isConfig() && name != "config" && name != "admin") {
- continue;
- }
-
const long long size = dbObj["sizeOnDisk"].numberLong();
long long& sizeSumForDbAcrossShards = sizes[name];
diff --git a/src/mongo/s/commands/cluster_split_vector_cmd.cpp b/src/mongo/s/commands/cluster_split_vector_cmd.cpp
index 1eba418b28d..0de63a429c0 100644
--- a/src/mongo/s/commands/cluster_split_vector_cmd.cpp
+++ b/src/mongo/s/commands/cluster_split_vector_cmd.cpp
@@ -97,7 +97,7 @@ public:
opCtx,
ReadPreferenceSetting::get(opCtx),
dbName.toStringWithTenantId(),
- cm.dbPrimary() == ShardId::kConfigServerId ? filteredCmdObj : filteredCmdObjWithVersion,
+ cm.dbVersion().isFixed() ? filteredCmdObj : filteredCmdObjWithVersion,
Shard::RetryPolicy::kIdempotent));
uassert(ErrorCodes::IllegalOperation,
diff --git a/src/mongo/s/query/cluster_aggregate.cpp b/src/mongo/s/query/cluster_aggregate.cpp
index e4cea383b32..867e70d5a50 100644
--- a/src/mongo/s/query/cluster_aggregate.cpp
+++ b/src/mongo/s/query/cluster_aggregate.cpp
@@ -37,6 +37,7 @@
#include "mongo/db/api_parameters.h"
#include "mongo/db/auth/authorization_session.h"
#include "mongo/db/catalog/collection_uuid_mismatch_info.h"
+#include "mongo/db/catalog_shard_feature_flag_gen.h"
#include "mongo/db/client.h"
#include "mongo/db/commands.h"
#include "mongo/db/curop.h"
@@ -536,7 +537,8 @@ Status ClusterAggregate::runAggregate(OperationContext* opCtx,
ShardId shardId(std::string(request.getPassthroughToShard()->getShard()));
uassert(6273803,
"$_passthroughToShard not supported for queries against config replica set",
- shardId != ShardId::kConfigServerId);
+ shardId != ShardId::kConfigServerId ||
+ gFeatureFlagCatalogShard.isEnabledAndIgnoreFCV());
// This is an aggregation pipeline started internally, so it is not eligible for
// sampling.
const bool eligibleForSampling = false;
diff --git a/src/mongo/s/query/cluster_aggregation_planner.cpp b/src/mongo/s/query/cluster_aggregation_planner.cpp
index 4e506419246..621ed5af3f0 100644
--- a/src/mongo/s/query/cluster_aggregation_planner.cpp
+++ b/src/mongo/s/query/cluster_aggregation_planner.cpp
@@ -34,6 +34,7 @@
#include "mongo/bson/util/bson_extract.h"
#include "mongo/client/connpool.h"
#include "mongo/db/auth/authorization_session.h"
+#include "mongo/db/catalog_shard_feature_flag_gen.h"
#include "mongo/db/pipeline/change_stream_constants.h"
#include "mongo/db/pipeline/change_stream_invalidation_info.h"
#include "mongo/db/pipeline/document_source_limit.h"
@@ -825,7 +826,8 @@ Status runPipelineOnSpecificShardOnly(const boost::intrusive_ptr<ExpressionConte
boost::none,
overrideBatchSize);
- if (!forPerShardCursor && shardId != ShardId::kConfigServerId) {
+ if (!forPerShardCursor && (!dbVersion || !dbVersion->isFixed())) {
+ // A fixed dbVersion database can't move or be sharded, so we don't attach any version.
cmdObj = appendShardVersion(std::move(cmdObj), ShardVersion::UNSHARDED());
}
if (!forPerShardCursor) {
diff --git a/src/mongo/shell/shardingtest.js b/src/mongo/shell/shardingtest.js
index 603b866d8cd..52dfd16648e 100644
--- a/src/mongo/shell/shardingtest.js
+++ b/src/mongo/shell/shardingtest.js
@@ -1816,7 +1816,7 @@ var ShardingTest = function(params) {
var name;
if (isCatalogShardMode && idx == 0) {
- name = "catalogShard";
+ name = "config";
print("ShardingTest " + testName + " transitioning to catalog shard");