summaryrefslogtreecommitdiff
path: root/src/mongo
diff options
context:
space:
mode:
authorKshitij Gupta <kshitij.gupta@mongodb.com>2022-12-16 20:18:48 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2022-12-16 21:23:07 +0000
commita2c7f46e2cc57b25d0d334376b901ed9f3988071 (patch)
tree2e4bee0b8c2dd2695d27176d7d7bfb012196f8a4 /src/mongo
parentd2f91feb2e43823c165b1e25a5bfa7d53a81e997 (diff)
downloadmongo-a2c7f46e2cc57b25d0d334376b901ed9f3988071.tar.gz
SERVER-71959: Modify usages of ClusterRole::
Diffstat (limited to 'src/mongo')
-rw-r--r--src/mongo/db/cluster_role.cpp13
-rw-r--r--src/mongo/db/cluster_role.h9
-rw-r--r--src/mongo/db/commands/feature_compatibility_version.cpp2
-rw-r--r--src/mongo/db/commands/internal_rename_if_options_and_indexes_match_cmd.cpp3
-rw-r--r--src/mongo/db/commands/parameters.cpp3
-rw-r--r--src/mongo/db/commands/read_write_concern_defaults_server_status.cpp2
-rw-r--r--src/mongo/db/ftdc/ftdc_mongod.cpp2
-rw-r--r--src/mongo/db/s/analyze_shard_key_cmd.cpp3
-rw-r--r--src/mongo/db/s/analyze_shard_key_cmd_util.cpp2
-rw-r--r--src/mongo/db/s/configure_query_analyzer_cmd.cpp2
-rw-r--r--src/mongo/db/s/sharding_state.cpp12
-rw-r--r--src/mongo/db/s/user_writes_recoverable_critical_section_service.cpp3
-rw-r--r--src/mongo/db/server_options_test.cpp16
-rw-r--r--src/mongo/db/service_entry_point_common.cpp6
-rw-r--r--src/mongo/db/write_concern.cpp5
15 files changed, 62 insertions, 21 deletions
diff --git a/src/mongo/db/cluster_role.cpp b/src/mongo/db/cluster_role.cpp
index 108eff0b325..370207f7325 100644
--- a/src/mongo/db/cluster_role.cpp
+++ b/src/mongo/db/cluster_role.cpp
@@ -41,4 +41,17 @@ bool ClusterRole::operator==(const ClusterRole& other) const {
return _value == other._value;
}
+
+bool ClusterRole::isShardRole() {
+ return _value == ClusterRole::ShardServer ||
+ (gFeatureFlagCatalogShard.isEnabledAndIgnoreFCV() && _value == ClusterRole::ConfigServer);
+}
+
+bool ClusterRole::isExclusivelyShardRole() {
+ return _value == ClusterRole::ShardServer;
+}
+
+bool ClusterRole::isExclusivelyConfigSvrRole() {
+ return _value == ClusterRole::ConfigServer && !gFeatureFlagCatalogShard.isEnabledAndIgnoreFCV();
+}
} // namespace mongo
diff --git a/src/mongo/db/cluster_role.h b/src/mongo/db/cluster_role.h
index a947d0cae9a..c5fde6472f5 100644
--- a/src/mongo/db/cluster_role.h
+++ b/src/mongo/db/cluster_role.h
@@ -57,6 +57,15 @@ public:
return !ClusterRole::operator==(other);
}
+ // Returns true if this mongod was started with --shardsvr or --configsvr in a catalog shard
+ // topology, false otherwise.
+ bool isShardRole();
+ // Returns true if this mongod was started with --shardsvr, false otherwise.
+ bool isExclusivelyShardRole();
+ // Returns true if this mongod was started with --configServer in a non-catalog shard topology,
+ // false otherwise.
+ bool isExclusivelyConfigSvrRole();
+
private:
Value _value;
};
diff --git a/src/mongo/db/commands/feature_compatibility_version.cpp b/src/mongo/db/commands/feature_compatibility_version.cpp
index c47fc23b532..dfa4471bacf 100644
--- a/src/mongo/db/commands/feature_compatibility_version.cpp
+++ b/src/mongo/db/commands/feature_compatibility_version.cpp
@@ -366,7 +366,7 @@ void FeatureCompatibilityVersion::setIfCleanStartup(OperationContext* opCtx,
// featureCompatibilityVersion is the downgrade version, so that it can be safely added to a
// downgrade version cluster. The config server will run setFeatureCompatibilityVersion as part
// of addShard.
- const bool storeUpgradeVersion = serverGlobalParams.clusterRole != ClusterRole::ShardServer;
+ const bool storeUpgradeVersion = !serverGlobalParams.clusterRole.isExclusivelyShardRole();
UnreplicatedWritesBlock unreplicatedWritesBlock(opCtx);
NamespaceString nss(NamespaceString::kServerConfigurationNamespace);
diff --git a/src/mongo/db/commands/internal_rename_if_options_and_indexes_match_cmd.cpp b/src/mongo/db/commands/internal_rename_if_options_and_indexes_match_cmd.cpp
index 5ef20f823f0..b9121334588 100644
--- a/src/mongo/db/commands/internal_rename_if_options_and_indexes_match_cmd.cpp
+++ b/src/mongo/db/commands/internal_rename_if_options_and_indexes_match_cmd.cpp
@@ -70,7 +70,8 @@ public:
std::list<BSONObj>(originalIndexes.begin(), originalIndexes.end());
const auto& collectionOptions = thisRequest.getCollectionOptions();
- if (serverGlobalParams.clusterRole != ClusterRole::ShardServer) {
+ if (serverGlobalParams.clusterRole == ClusterRole::None ||
+ serverGlobalParams.clusterRole.isExclusivelyConfigSvrRole()) {
// No need to acquire additional locks in a non-sharded environment
_internalRun(opCtx, fromNss, toNss, indexList, collectionOptions);
return;
diff --git a/src/mongo/db/commands/parameters.cpp b/src/mongo/db/commands/parameters.cpp
index ba905af0848..b906f79b1fd 100644
--- a/src/mongo/db/commands/parameters.cpp
+++ b/src/mongo/db/commands/parameters.cpp
@@ -389,8 +389,7 @@ public:
str::stream()
<< "Cannot set parameter requireApiVersion=true on a shard or config server",
parameterName != "requireApiVersion" || !parameter.trueValue() ||
- (serverGlobalParams.clusterRole != ClusterRole::ConfigServer &&
- serverGlobalParams.clusterRole != ClusterRole::ShardServer));
+ (serverGlobalParams.clusterRole == ClusterRole::None));
auto oldValueObj = ([&] {
BSONObjBuilder bb;
diff --git a/src/mongo/db/commands/read_write_concern_defaults_server_status.cpp b/src/mongo/db/commands/read_write_concern_defaults_server_status.cpp
index 16f3d6d0235..459bd2532b0 100644
--- a/src/mongo/db/commands/read_write_concern_defaults_server_status.cpp
+++ b/src/mongo/db/commands/read_write_concern_defaults_server_status.cpp
@@ -42,7 +42,7 @@ public:
ReadWriteConcernDefaultsServerStatus() : ServerStatusSection("defaultRWConcern") {}
bool includeByDefault() const override {
- return serverGlobalParams.clusterRole != ClusterRole::ShardServer;
+ return !serverGlobalParams.clusterRole.isExclusivelyShardRole();
}
BSONObj generateSection(OperationContext* opCtx,
diff --git a/src/mongo/db/ftdc/ftdc_mongod.cpp b/src/mongo/db/ftdc/ftdc_mongod.cpp
index 20a435ecb68..7b4b4468d25 100644
--- a/src/mongo/db/ftdc/ftdc_mongod.cpp
+++ b/src/mongo/db/ftdc/ftdc_mongod.cpp
@@ -124,7 +124,7 @@ void registerMongoDCollectors(FTDCController* controller) {
<< BSON_ARRAY(BSON("$collStats" << BSON(
"storageStats" << BSON(
"waitForLock" << false << "numericOnly" << true)))))));
- if (serverGlobalParams.clusterRole != ClusterRole::ShardServer) {
+ if (!serverGlobalParams.clusterRole.isExclusivelyShardRole()) {
// GetDefaultRWConcern
controller->addOnRotateCollector(std::make_unique<FTDCSimpleInternalCommandCollector>(
"getDefaultRWConcern",
diff --git a/src/mongo/db/s/analyze_shard_key_cmd.cpp b/src/mongo/db/s/analyze_shard_key_cmd.cpp
index 79764cc01cc..1ad0442dd27 100644
--- a/src/mongo/db/s/analyze_shard_key_cmd.cpp
+++ b/src/mongo/db/s/analyze_shard_key_cmd.cpp
@@ -70,7 +70,8 @@ public:
Response typedRun(OperationContext* opCtx) {
uassert(ErrorCodes::IllegalOperation,
"analyzeShardKey command is not supported on a configsvr mongod",
- serverGlobalParams.clusterRole != ClusterRole::ConfigServer);
+ serverGlobalParams.clusterRole == ClusterRole::None ||
+ serverGlobalParams.clusterRole.isShardRole());
const auto& nss = ns();
const auto& key = request().getKey();
diff --git a/src/mongo/db/s/analyze_shard_key_cmd_util.cpp b/src/mongo/db/s/analyze_shard_key_cmd_util.cpp
index e7a46b9021a..b714d85817e 100644
--- a/src/mongo/db/s/analyze_shard_key_cmd_util.cpp
+++ b/src/mongo/db/s/analyze_shard_key_cmd_util.cpp
@@ -416,7 +416,7 @@ MonotonicityTypeEnum calculateMonotonicity(OperationContext* opCtx,
*/
boost::optional<int64_t> getNumOrphanDocuments(OperationContext* opCtx,
const NamespaceString& nss) {
- if (serverGlobalParams.clusterRole != ClusterRole::ShardServer) {
+ if (!serverGlobalParams.clusterRole.isShardRole()) {
return boost::none;
}
diff --git a/src/mongo/db/s/configure_query_analyzer_cmd.cpp b/src/mongo/db/s/configure_query_analyzer_cmd.cpp
index 73f8441c1db..5bcd779f1c2 100644
--- a/src/mongo/db/s/configure_query_analyzer_cmd.cpp
+++ b/src/mongo/db/s/configure_query_analyzer_cmd.cpp
@@ -61,7 +61,7 @@ public:
Response typedRun(OperationContext* opCtx) {
uassert(ErrorCodes::IllegalOperation,
"configQueryAnalyzer command is not supported on a shardsvr mongod",
- serverGlobalParams.clusterRole != ClusterRole::ShardServer);
+ !serverGlobalParams.clusterRole.isExclusivelyShardRole());
const auto& nss = ns();
const auto mode = request().getMode();
diff --git a/src/mongo/db/s/sharding_state.cpp b/src/mongo/db/s/sharding_state.cpp
index 920ecb37f61..7ffcbcd2ff2 100644
--- a/src/mongo/db/s/sharding_state.cpp
+++ b/src/mongo/db/s/sharding_state.cpp
@@ -96,16 +96,18 @@ bool ShardingState::enabled() const {
}
Status ShardingState::canAcceptShardedCommands() const {
- if (serverGlobalParams.clusterRole != ClusterRole::ShardServer) {
+ if (!serverGlobalParams.clusterRole.isShardRole()) {
return {ErrorCodes::NoShardingEnabled,
- "Cannot accept sharding commands if not started with --shardsvr"};
- } else if (!enabled()) {
+ "Cannot accept sharding commands if node does not have shard role"};
+ }
+
+ if (!enabled()) {
return {ErrorCodes::ShardingStateNotInitialized,
"Cannot accept sharding commands if sharding state has not "
"been initialized with a shardIdentity document"};
- } else {
- return Status::OK();
}
+
+ return Status::OK();
}
ShardId ShardingState::shardId() {
diff --git a/src/mongo/db/s/user_writes_recoverable_critical_section_service.cpp b/src/mongo/db/s/user_writes_recoverable_critical_section_service.cpp
index be1cc7c2375..798671a3f3d 100644
--- a/src/mongo/db/s/user_writes_recoverable_critical_section_service.cpp
+++ b/src/mongo/db/s/user_writes_recoverable_critical_section_service.cpp
@@ -172,7 +172,8 @@ const ReplicaSetAwareServiceRegistry::Registerer<UserWritesRecoverableCriticalSe
"UserWritesRecoverableCriticalSectionService");
bool UserWritesRecoverableCriticalSectionService::shouldRegisterReplicaSetAwareService() const {
- return serverGlobalParams.clusterRole != ClusterRole::ConfigServer;
+ return serverGlobalParams.clusterRole == ClusterRole::None ||
+ serverGlobalParams.clusterRole.isShardRole();
}
void UserWritesRecoverableCriticalSectionService::
diff --git a/src/mongo/db/server_options_test.cpp b/src/mongo/db/server_options_test.cpp
index 3f7ad515a79..02e73f381d0 100644
--- a/src/mongo/db/server_options_test.cpp
+++ b/src/mongo/db/server_options_test.cpp
@@ -720,6 +720,14 @@ TEST(ClusterRole, Equality) {
ASSERT_TRUE(ClusterRole(ClusterRole::ShardServer) != ClusterRole::ConfigServer);
ASSERT_TRUE(ClusterRole(ClusterRole::ShardServer) == ClusterRole::ShardServer);
+ ASSERT_TRUE(ClusterRole(ClusterRole::ShardServer).isShardRole());
+ ASSERT_FALSE(ClusterRole(ClusterRole::ConfigServer).isShardRole());
+
+ ASSERT_TRUE(ClusterRole(ClusterRole::ShardServer).isExclusivelyShardRole());
+ ASSERT_FALSE(ClusterRole(ClusterRole::ConfigServer).isExclusivelyShardRole());
+
+ ASSERT_TRUE(ClusterRole(ClusterRole::ConfigServer).isExclusivelyConfigSvrRole());
+
RAIIServerParameterControllerForTest controller("featureFlagCatalogShard", true);
ASSERT_TRUE(ClusterRole(ClusterRole::None) == ClusterRole::None);
@@ -733,6 +741,14 @@ TEST(ClusterRole, Equality) {
ASSERT_TRUE(ClusterRole(ClusterRole::ShardServer) != ClusterRole::None);
ASSERT_TRUE(ClusterRole(ClusterRole::ShardServer) != ClusterRole::ConfigServer);
ASSERT_TRUE(ClusterRole(ClusterRole::ShardServer) == ClusterRole::ShardServer);
+
+ ASSERT_TRUE(ClusterRole(ClusterRole::ShardServer).isShardRole());
+ ASSERT_TRUE(ClusterRole(ClusterRole::ConfigServer).isShardRole());
+
+ ASSERT_TRUE(ClusterRole(ClusterRole::ShardServer).isExclusivelyShardRole());
+ ASSERT_FALSE(ClusterRole(ClusterRole::ConfigServer).isExclusivelyShardRole());
+
+ ASSERT_FALSE(ClusterRole(ClusterRole::ConfigServer).isExclusivelyConfigSvrRole());
}
#if !defined(_WIN32) && !(defined(__APPLE__) && TARGET_OS_TV)
diff --git a/src/mongo/db/service_entry_point_common.cpp b/src/mongo/db/service_entry_point_common.cpp
index bf358ead21f..d4b0c5b99fc 100644
--- a/src/mongo/db/service_entry_point_common.cpp
+++ b/src/mongo/db/service_entry_point_common.cpp
@@ -1790,7 +1790,7 @@ Future<void> ExecCommandDatabase::_commandExec() {
auto opCtx = _execContext->getOpCtx();
if (!opCtx->getClient()->isInDirectClient() &&
- serverGlobalParams.clusterRole != ClusterRole::ConfigServer &&
+ !serverGlobalParams.clusterRole.isExclusivelyConfigSvrRole() &&
!_refreshedDatabase) {
auto sce = s.extraInfo<StaleDbRoutingVersion>();
invariant(sce);
@@ -1822,7 +1822,7 @@ Future<void> ExecCommandDatabase::_commandExec() {
ShardingStatistics::get(opCtx).countStaleConfigErrors.addAndFetch(1);
if (!opCtx->getClient()->isInDirectClient() &&
- serverGlobalParams.clusterRole != ClusterRole::ConfigServer &&
+ !serverGlobalParams.clusterRole.isExclusivelyConfigSvrRole() &&
!_refreshedCollection) {
if (auto sce = s.extraInfo<StaleConfigInfo>()) {
bool inCriticalSection = sce->getCriticalSectionSignal().has_value();
@@ -1870,7 +1870,7 @@ Future<void> ExecCommandDatabase::_commandExec() {
.onError<ErrorCodes::ShardCannotRefreshDueToLocksHeld>([this](Status s) -> Future<void> {
// This exception can never happen on the config server. Config servers can't receive
// SSV either, because they never have commands with shardVersion sent.
- invariant(serverGlobalParams.clusterRole != ClusterRole::ConfigServer);
+ invariant(!serverGlobalParams.clusterRole.isExclusivelyConfigSvrRole());
auto opCtx = _execContext->getOpCtx();
if (!opCtx->getClient()->isInDirectClient() && !_refreshedCatalogCache) {
diff --git a/src/mongo/db/write_concern.cpp b/src/mongo/db/write_concern.cpp
index f6caaad89d0..0c6f9f252f7 100644
--- a/src/mongo/db/write_concern.cpp
+++ b/src/mongo/db/write_concern.cpp
@@ -96,8 +96,7 @@ StatusWith<WriteConcernOptions> extractWriteConcern(OperationContext* opCtx,
writeConcern = ([&]() {
// WriteConcern defaults can only be applied on regular replica set members. Operations
// received by shard and config servers should always have WC explicitly specified.
- if (serverGlobalParams.clusterRole != ClusterRole::ShardServer &&
- serverGlobalParams.clusterRole != ClusterRole::ConfigServer &&
+ if (serverGlobalParams.clusterRole == ClusterRole::None &&
repl::ReplicationCoordinator::get(opCtx)->isReplEnabled() &&
(!opCtx->inMultiDocumentTransaction() ||
isTransactionCommand(cmdObj.firstElementFieldName())) &&
@@ -143,7 +142,7 @@ StatusWith<WriteConcernOptions> extractWriteConcern(OperationContext* opCtx,
}
if (!clientSuppliedWriteConcern &&
- serverGlobalParams.clusterRole == ClusterRole::ConfigServer &&
+ serverGlobalParams.clusterRole.isExclusivelyConfigSvrRole() &&
!opCtx->getClient()->isInDirectClient() &&
(opCtx->getClient()->session() &&
(opCtx->getClient()->session()->getTags() & transport::Session::kInternalClient)) &&