Skip to content

Commit

Permalink
SERVER-71818: Use the new cluster param
Browse files Browse the repository at this point in the history
  • Loading branch information
kshitijng authored and Evergreen Agent committed Dec 7, 2022
1 parent edf22af commit affc265
Show file tree
Hide file tree
Showing 12 changed files with 250 additions and 64 deletions.
2 changes: 2 additions & 0 deletions buildscripts/resmokeconfig/fully_disabled_feature_flags.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,5 @@
# Disable the new logic for the resilient movePrimary for non-dedicated tests until the logic is
# mature enough to be enabled for all tests.
- featureFlagResilientMovePrimary
# Disable the feature flag for catalog shard until most of the codebase can run in this mode.
- featureFlagCatalogShard
14 changes: 14 additions & 0 deletions jstests/noPassthrough/catalog_shard.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/**
* Tests catalog shard topology.
*/
(function() {
"use strict";

const st = new ShardingTest({
shards: 0,
config: 1,
configOptions: {setParameter: {featureFlagCatalogShard: true}},
});

st.stop();
}());
33 changes: 19 additions & 14 deletions src/mongo/db/SConscript
Original file line number Diff line number Diff line change
Expand Up @@ -58,30 +58,22 @@ env.SConscript(
# all the server binaries. It must not depend on anything other than utilities that are outside of
# the server codebase.
env.Library(
target='server_base', source=[
'basic_types.idl',
target='server_base',
source=[
'database_name.cpp',
'feature_compatibility_version_parser.cpp',
'feature_compatibility_version_document.idl',
'feature_flag.cpp',
'index_names.cpp',
'keypattern.cpp',
'logical_time.cpp',
'multitenancy.idl',
'namespace_string.cpp',
'server_parameter_with_storage.cpp',
'server_parameter.cpp',
'server_parameter.idl',
'shard_id.cpp',
'shutdown_in_progress_quiesce_info.cpp',
'tenant_id.cpp',
], LIBDEPS=[
],
LIBDEPS=[
'$BUILD_DIR/mongo/base',
'$BUILD_DIR/mongo/idl/idl_parser',
'$BUILD_DIR/mongo/util/options_parser/options_parser',
], LIBDEPS_PRIVATE=[
'server_options_core',
])
],
)

#
# The db/'common' lib has the abstractions that are shared by components of the
Expand Down Expand Up @@ -314,11 +306,24 @@ env.Library(
env.Library(
target="server_options_core",
source=[
'basic_types.idl',
"server_options.cpp",
"catalog_shard_feature_flag.idl",
"cluster_role.cpp",
'feature_compatibility_version_parser.cpp',
'feature_compatibility_version_document.idl',
"feature_flag.cpp",
'logical_time.cpp',
'multitenancy.idl',
'namespace_string.cpp',
'server_parameter_with_storage.cpp',
'server_parameter.cpp',
'server_parameter.idl',
],
LIBDEPS=[
'$BUILD_DIR/mongo/base',
'$BUILD_DIR/mongo/bson/bson_validate',
'$BUILD_DIR/mongo/idl/idl_parser',
],
)

Expand Down
36 changes: 36 additions & 0 deletions src/mongo/db/catalog_shard_feature_flag.idl
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Copyright (C) 2022-present MongoDB, Inc.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the Server Side Public License, version 1,
# as published by MongoDB, Inc.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# Server Side Public License for more details.
#
# You should have received a copy of the Server Side Public License
# along with this program. If not, see
# <http://www.mongodb.com/licensing/server-side-public-license>.
#
# As a special exception, the copyright holders give permission to link the
# code of portions of this program with the OpenSSL library under certain
# conditions as described in each individual source file and distribute
# linked combinations including the program with the OpenSSL library. You
# must comply with the Server Side Public License in all respects for
# all of the code used other than as permitted herein. If you modify file(s)
# with this exception, you may extend this exception to your version of the
# file(s), but you are not obligated to do so. If you do not wish to do so,
# delete this exception statement from your version. If you delete this
# exception statement from all source files in the program, then also delete
# it in the license file.
#

global:
cpp_namespace: "mongo"

feature_flags:
featureFlagCatalogShard:
description: "Feature flag for enabling shared config server/shard server cluster role"
cpp_varname: gFeatureFlagCatalogShard
default: false
44 changes: 44 additions & 0 deletions src/mongo/db/cluster_role.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/**
* Copyright (C) 2022-present MongoDB, Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the Server Side Public License, version 1,
* as published by MongoDB, Inc.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* Server Side Public License for more details.
*
* You should have received a copy of the Server Side Public License
* along with this program. If not, see
* <http://www.mongodb.com/licensing/server-side-public-license>.
*
* As a special exception, the copyright holders give permission to link the
* code of portions of this program with the OpenSSL library under certain
* conditions as described in each individual source file and distribute
* linked combinations including the program with the OpenSSL library. You
* must comply with the Server Side Public License in all respects for
* all of the code used other than as permitted herein. If you modify file(s)
* with this exception, you may extend this exception to your version of the
* file(s), but you are not obligated to do so. If you do not wish to do so,
* delete this exception statement from your version. If you delete this
* exception statement from all source files in the program, then also delete
* it in the license file.
*/

#include "mongo/db/cluster_role.h"
#include "mongo/db/catalog_shard_feature_flag_gen.h"
#include "mongo/db/feature_flag.h"

namespace mongo {

bool ClusterRole::operator==(const ClusterRole& other) const {
if (gFeatureFlagCatalogShard.isEnabledAndIgnoreFCV() && _value == ClusterRole::ConfigServer) {
return other._value == ClusterRole::ConfigServer ||
other._value == ClusterRole::ShardServer;
}

return _value == other._value;
}
} // namespace mongo
63 changes: 63 additions & 0 deletions src/mongo/db/cluster_role.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/**
* Copyright (C) 2022-present MongoDB, Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the Server Side Public License, version 1,
* as published by MongoDB, Inc.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* Server Side Public License for more details.
*
* You should have received a copy of the Server Side Public License
* along with this program. If not, see
* <http://www.mongodb.com/licensing/server-side-public-license>.
*
* As a special exception, the copyright holders give permission to link the
* code of portions of this program with the OpenSSL library under certain
* conditions as described in each individual source file and distribute
* linked combinations including the program with the OpenSSL library. You
* must comply with the Server Side Public License in all respects for
* all of the code used other than as permitted herein. If you modify file(s)
* with this exception, you may extend this exception to your version of the
* file(s), but you are not obligated to do so. If you do not wish to do so,
* delete this exception statement from your version. If you delete this
* exception statement from all source files in the program, then also delete
* it in the license file.
*/

#pragma once

namespace mongo {
/**
* ClusterRole is not mutually exclusive when featureFlagCatalogShard is true. In this mode, a
* config server cluster role is also a shard server cluster role.
*/
class ClusterRole {
public:
enum Value {
None,
ShardServer,
ConfigServer,
};

ClusterRole(Value v = ClusterRole::None) : _value(v) {}

ClusterRole& operator=(const ClusterRole& rhs) {
if (this != &rhs) {
_value = rhs._value;
}
return *this;
}

bool operator==(const ClusterRole& other) const;

bool operator!=(const ClusterRole& other) const {
return !ClusterRole::operator==(other);
}

private:
Value _value;
};
} // namespace mongo
3 changes: 2 additions & 1 deletion src/mongo/db/commands/rwc_defaults_commands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ void assertNotStandaloneOrShardServer(OperationContext* opCtx, StringData cmdNam

uassert(51301,
str::stream() << "'" << cmdName << "' is not supported on shard nodes.",
serverGlobalParams.clusterRole != ClusterRole::ShardServer);
serverGlobalParams.clusterRole == ClusterRole::None ||
serverGlobalParams.clusterRole == ClusterRole::ConfigServer);
}

auto makeResponse(const ReadWriteConcernDefaults::RWConcernDefaultAndTime& rwcDefault,
Expand Down
47 changes: 34 additions & 13 deletions src/mongo/db/mongod_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
#include "mongo/db/catalog/health_log.h"
#include "mongo/db/catalog/index_catalog.h"
#include "mongo/db/catalog/index_key_validate.h"
#include "mongo/db/catalog_shard_feature_flag_gen.h"
#include "mongo/db/change_collection_expired_documents_remover.h"
#include "mongo/db/change_stream_change_collection_manager.h"
#include "mongo/db/change_stream_options_manager.h"
Expand Down Expand Up @@ -367,14 +368,18 @@ void registerPrimaryOnlyServices(ServiceContext* serviceContext) {
if (serverGlobalParams.clusterRole == ClusterRole::ConfigServer) {
services.push_back(std::make_unique<ReshardingCoordinatorService>(serviceContext));
services.push_back(std::make_unique<ConfigsvrCoordinatorService>(serviceContext));
} else if (serverGlobalParams.clusterRole == ClusterRole::ShardServer) {
}

if (serverGlobalParams.clusterRole == ClusterRole::ShardServer) {
services.push_back(std::make_unique<RenameCollectionParticipantService>(serviceContext));
services.push_back(std::make_unique<ShardingDDLCoordinatorService>(serviceContext));
services.push_back(std::make_unique<ReshardingDonorService>(serviceContext));
services.push_back(std::make_unique<ReshardingRecipientService>(serviceContext));
services.push_back(std::make_unique<TenantMigrationDonorService>(serviceContext));
services.push_back(std::make_unique<repl::TenantMigrationRecipientService>(serviceContext));
} else {
}

if (serverGlobalParams.clusterRole == ClusterRole::None) {
services.push_back(std::make_unique<TenantMigrationDonorService>(serviceContext));
services.push_back(std::make_unique<repl::TenantMigrationRecipientService>(serviceContext));
if (getGlobalReplSettings().isServerless()) {
Expand Down Expand Up @@ -674,7 +679,8 @@ ExitCode _initAndListen(ServiceContext* serviceContext, int listenPort) {
}

try {
if (serverGlobalParams.clusterRole != ClusterRole::ShardServer &&
if ((serverGlobalParams.clusterRole == ClusterRole::ConfigServer ||
serverGlobalParams.clusterRole == ClusterRole::None) &&
replSettings.usingReplSets()) {
ReadWriteConcernDefaults::get(startupOpCtx.get()->getServiceContext())
.refreshIfNecessary(startupOpCtx.get());
Expand Down Expand Up @@ -730,16 +736,23 @@ ExitCode _initAndListen(ServiceContext* serviceContext, int listenPort) {
uassertStatusOK(ShardingStateRecovery_DEPRECATED::recover(startupOpCtx.get()));
}
}
} else if (serverGlobalParams.clusterRole == ClusterRole::ConfigServer) {
}

if (serverGlobalParams.clusterRole == ClusterRole::ConfigServer) {
initializeGlobalShardingStateForMongoD(
startupOpCtx.get(), ShardId::kConfigServerId, ConnectionString::forLocal());

ShardingCatalogManager::create(
startupOpCtx->getServiceContext(),
makeShardingTaskExecutor(executor::makeNetworkInterface("AddShard-TaskExecutor")));

Grid::get(startupOpCtx.get())->setShardingInitialized();
} else if (replSettings.usingReplSets()) { // standalone replica set
if (!gFeatureFlagCatalogShard.isEnabledAndIgnoreFCV()) {
Grid::get(startupOpCtx.get())->setShardingInitialized();
}
}

if (serverGlobalParams.clusterRole == ClusterRole::None &&
replSettings.usingReplSets()) { // standalone replica set
// The keys client must use local read concern if the storage engine can't support
// majority read concern.
auto keysClientMustUseLocalReads =
Expand Down Expand Up @@ -862,10 +875,10 @@ ExitCode _initAndListen(ServiceContext* serviceContext, int listenPort) {

// Set up the logical session cache
LogicalSessionCacheServer kind = LogicalSessionCacheServer::kStandalone;
if (serverGlobalParams.clusterRole == ClusterRole::ShardServer) {
kind = LogicalSessionCacheServer::kSharded;
} else if (serverGlobalParams.clusterRole == ClusterRole::ConfigServer) {
if (serverGlobalParams.clusterRole == ClusterRole::ConfigServer) {
kind = LogicalSessionCacheServer::kConfigServer;
} else if (serverGlobalParams.clusterRole == ClusterRole::ShardServer) {
kind = LogicalSessionCacheServer::kSharded;
} else if (replSettings.usingReplSets()) {
kind = LogicalSessionCacheServer::kReplicaSet;
}
Expand Down Expand Up @@ -1207,14 +1220,21 @@ void setUpObservers(ServiceContext* serviceContext) {
if (getGlobalReplSettings().isServerless()) {
opObserverRegistry->addObserver(std::make_unique<ShardSplitDonorOpObserver>());
}
} else if (serverGlobalParams.clusterRole == ClusterRole::ConfigServer) {
opObserverRegistry->addObserver(
std::make_unique<OpObserverImpl>(std::make_unique<OplogWriterImpl>()));
}

if (serverGlobalParams.clusterRole == ClusterRole::ConfigServer) {
if (!gFeatureFlagCatalogShard.isEnabledAndIgnoreFCV()) {
opObserverRegistry->addObserver(
std::make_unique<OpObserverImpl>(std::make_unique<OplogWriterImpl>()));
}

opObserverRegistry->addObserver(std::make_unique<ConfigServerOpObserver>());
opObserverRegistry->addObserver(std::make_unique<ReshardingOpObserver>());
opObserverRegistry->addObserver(
std::make_unique<analyze_shard_key::QueryAnalysisOpObserver>());
} else {
}

if (serverGlobalParams.clusterRole == ClusterRole::None) {
opObserverRegistry->addObserver(
std::make_unique<OpObserverImpl>(std::make_unique<OplogWriterImpl>()));
opObserverRegistry->addObserver(std::make_unique<repl::TenantMigrationDonorOpObserver>());
Expand All @@ -1225,6 +1245,7 @@ void setUpObservers(ServiceContext* serviceContext) {
opObserverRegistry->addObserver(std::make_unique<ShardSplitDonorOpObserver>());
}
}

opObserverRegistry->addObserver(std::make_unique<AuthOpObserver>());
opObserverRegistry->addObserver(
std::make_unique<repl::PrimaryOnlyServiceOpObserver>(serviceContext));
Expand Down
6 changes: 5 additions & 1 deletion src/mongo/db/s/query_analysis_coordinator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@

#include "mongo/db/s/query_analysis_coordinator.h"

#include "mongo/db/catalog_shard_feature_flag_gen.h"
#include "mongo/db/dbdirectclient.h"
#include "mongo/logv2/log.h"
#include "mongo/s/analyze_shard_key_documents_gen.h"
Expand Down Expand Up @@ -184,7 +185,10 @@ void QueryAnalysisCoordinator::onStartup(OperationContext* opCtx) {
}

{
invariant(_samplers.empty());
if (!gFeatureFlagCatalogShard.isEnabledAndIgnoreFCV()) {
invariant(_samplers.empty());
}

auto minPingTime = _getMinLastPingTime();
FindCommandRequest findRequest{MongosType::ConfigNS};
findRequest.setFilter(BSON(MongosType::ping << BSON("$gte" << minPingTime)));
Expand Down

0 comments on commit affc265

Please sign in to comment.