summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoan Bruguera Micó (at MongoDB) <joan.bruguera-mico@mongodb.com>2024-08-14 13:17:35 +0000
committerMongoDB Bot <mongo-bot@mongodb.com>2024-08-14 14:05:40 +0000
commitf3fa519bd0c83ed9558dedfa72dbee2c26453dcb (patch)
treefeab6de1d6a12a8101fffcddb997ae8fd6565b61
parent68e649e692c78a0349169029aa9d4d8070042539 (diff)
SERVER-93033 Sharding cluster parameters cannot be accessed via MongoS (#26107)
GitOrigin-RevId: 65ad2fff60e3f8d34a5dd47fb25bb36a0ee92f0a
-rw-r--r--jstests/libs/cluster_server_parameter_utils.js48
-rw-r--r--jstests/noPassthrough/cluster_server_parameter_refresher.js4
-rw-r--r--src/mongo/db/SConscript1
-rw-r--r--src/mongo/db/direct_connection_util.cpp2
-rw-r--r--src/mongo/db/replica_set_endpoint_sharding_state.cpp2
-rw-r--r--src/mongo/db/replica_set_endpoint_sharding_state_test.cpp2
-rw-r--r--src/mongo/db/replica_set_endpoint_test_fixture.cpp2
-rw-r--r--src/mongo/db/replica_set_endpoint_test_fixture.h2
-rw-r--r--src/mongo/db/s/SConscript11
-rw-r--r--src/mongo/db/s/config/sharding_catalog_manager_shard_operations.cpp2
-rw-r--r--src/mongo/db/s/resharding/resharding_coordinator_test.cpp2
-rw-r--r--src/mongo/db/s/sharding_ddl_coordinator_service.cpp2
-rw-r--r--src/mongo/db/s/sharding_ddl_util.cpp2
-rw-r--r--src/mongo/db/s/shardsvr_reshard_collection_command.cpp2
-rw-r--r--src/mongo/db/service_entry_point_common.cpp2
-rw-r--r--src/mongo/s/SConscript2
-rw-r--r--src/mongo/s/catalog/sharding_catalog_client_impl.cpp2
-rw-r--r--src/mongo/s/catalog/sharding_catalog_client_read_preference_test.cpp2
-rw-r--r--src/mongo/s/sharding_cluster_parameters.idl (renamed from src/mongo/db/s/sharding_cluster_parameters.idl)0
19 files changed, 59 insertions, 33 deletions
diff --git a/jstests/libs/cluster_server_parameter_utils.js b/jstests/libs/cluster_server_parameter_utils.js
index 4f84d5f42a6..2a531240530 100644
--- a/jstests/libs/cluster_server_parameter_utils.js
+++ b/jstests/libs/cluster_server_parameter_utils.js
@@ -5,15 +5,20 @@
* If it's test-only, add its definition to kTestOnlyClusterParameters.
* Otherwise, add to kNonTestOnlyClusterParameters.
* The keyname will be the name of the cluster-wide server parameter,
- * it's value will be an object with at least three keys named:
+ * its value will be an object with at least two keys named:
* * 'default': Properties to expect on an unset CWSP
* * 'testValues': List of two other valid values of the CWSP to set for testing purposes
- * An additional property 'featureFlag' may also be set if the
- * parameter depends on a featureFlag.
- * Use the name of the featureFlag if it is required in
- * order to consider the parameter.
- * Prefix the name with a bang '!' if it is only considered
- * when the featureFlag is disabled.
+ *
+ * An additional property 'featureFlag' may also be set if the parameter depends on a featureFlag.
+ * Use the name of the featureFlag if it is required in order to consider the parameter.
+ * Prefix the name with a bang '!' if it is only considered when the featureFlag is disabled.
+ *
+ * Analogously, the 'setParameters', 'serverless' and 'standaloneIncompatible' properties may
+ * be set to specify that the scenarios under which a parameter can be validated.
+ *
+ * CWSPs with the 'isSetInternally' property are set by the cluster itself, and generally not by
+ * the user. We don't set them nor check their value from generic tests, as we can not assume that
+ * they will remain at a given value. However, we check that they exist, i.e. that we can get them.
*/
import {FeatureFlagUtil} from "jstests/libs/feature_flag_util.js";
@@ -47,6 +52,20 @@ export const kNonTestOnlyClusterParameters = {
setParameters: {'multitenancySupport': true},
serverless: true,
standaloneIncompatible: false,
+ },
+ addOrRemoveShardInProgress: {
+ default: {inProgress: false},
+ testValues: [{inProgress: true}, {inProgress: false}],
+ isSetInternally: true,
+ },
+ shardedClusterCardinalityForDirectConns: {
+ default: {hasTwoOrMoreShards: false},
+ testValues: [{hasTwoOrMoreShards: true}, {hasTwoOrMoreShards: false}],
+ isSetInternally: true,
+ },
+ configServerReadPreferenceForCatalogQueries: {
+ default: {mustAlwaysUseNearest: false},
+ testValues: [{mustAlwaysUseNearest: true}, {mustAlwaysUseNearest: false}],
}
};
@@ -77,6 +96,9 @@ export const kAllClusterParameters =
export const kAllClusterParameterNames = Object.keys(kAllClusterParameters);
+export const kAllClusterParameterSetInternallyNames =
+ kAllClusterParameterNames.filter(name => kAllClusterParameters[name].isSetInternally);
+
export const kAllClusterParameterDefaults = kAllClusterParameterNames.map(
(name) => Object.assign({_id: name}, kAllClusterParameters[name].default));
@@ -175,6 +197,12 @@ export function runSetClusterParameter(conn, update, tenantId) {
if (!considerParameter(paramName, conn)) {
return;
}
+ if (kAllClusterParameterSetInternallyNames.includes(paramName)) {
+ // Skip setting parameters used internally by the cluster,
+ // as this may break the cluster in ways generic tests aren't prepared to handle.
+ return;
+ }
+
let updateCopy = Object.assign({}, update);
delete updateCopy._id;
delete updateCopy.clusterParameterTime;
@@ -245,6 +273,12 @@ export function runGetClusterParameterNode(conn,
return false;
}
+ if (kAllClusterParameterSetInternallyNames.includes(expectedClusterParameters[i]._id)) {
+ // Skip validation of parameters used internally by the cluster,
+ // as their values could change for reasons outside the control of the tests.
+ continue;
+ }
+
if (bsonWoCompare(expectedClusterParameters[i], actual[id]) !== 0) {
jsTest.log('Server parameter mismatch on node: ' + conn.host + '\n' +
'Expected: ' + tojson(expectedClusterParameters[i]) + '\n' +
diff --git a/jstests/noPassthrough/cluster_server_parameter_refresher.js b/jstests/noPassthrough/cluster_server_parameter_refresher.js
index 08f26929eae..cb496c5767a 100644
--- a/jstests/noPassthrough/cluster_server_parameter_refresher.js
+++ b/jstests/noPassthrough/cluster_server_parameter_refresher.js
@@ -11,6 +11,7 @@
*/
import {
kAllClusterParameterDefaults,
+ kAllClusterParameterSetInternallyNames,
runGetClusterParameterSharded
} from "jstests/libs/cluster_server_parameter_utils.js";
import {TwoPhaseDropCollectionTest} from "jstests/replsets/libs/two_phase_drops.js";
@@ -51,6 +52,9 @@ function runTest(st, startupRefreshIntervalMS) {
if (obj.id === kRefreshLogId) {
let cpd = obj.attr.clusterParameterDocuments[0].updatedParameters;
+ // We may observe updates to parameters done by MongoDB itself; exclude them
+ cpd = cpd.filter(
+ elem => !kAllClusterParameterSetInternallyNames.includes(elem._id));
cpd.sort(bsonWoCompare);
if (bsonWoCompare(cpd, expectedLogged) === 0) {
return true;
diff --git a/src/mongo/db/SConscript b/src/mongo/db/SConscript
index 8d4058d685a..a131b6f9216 100644
--- a/src/mongo/db/SConscript
+++ b/src/mongo/db/SConscript
@@ -1080,7 +1080,6 @@ env.CppUnitTest(
'commands_test_example',
'repl/replmocks',
's/sharding_catalog_manager',
- 's/sharding_cluster_parameters_idl',
'service_context_d_test_fixture',
'shard_role_api',
],
diff --git a/src/mongo/db/direct_connection_util.cpp b/src/mongo/db/direct_connection_util.cpp
index 8932db114cd..eb4b4eb5ce0 100644
--- a/src/mongo/db/direct_connection_util.cpp
+++ b/src/mongo/db/direct_connection_util.cpp
@@ -33,9 +33,9 @@
#include "mongo/db/auth/authorization_session.h"
#include "mongo/db/curop.h"
#include "mongo/db/s/sharding_api_d_params_gen.h"
-#include "mongo/db/s/sharding_cluster_parameters_gen.h"
#include "mongo/db/s/sharding_statistics.h"
#include "mongo/logv2/log.h"
+#include "mongo/s/sharding_cluster_parameters_gen.h"
#include "mongo/s/sharding_feature_flags_gen.h"
#include "mongo/s/sharding_state.h"
diff --git a/src/mongo/db/replica_set_endpoint_sharding_state.cpp b/src/mongo/db/replica_set_endpoint_sharding_state.cpp
index ecc690b5757..50cd1e583cb 100644
--- a/src/mongo/db/replica_set_endpoint_sharding_state.cpp
+++ b/src/mongo/db/replica_set_endpoint_sharding_state.cpp
@@ -29,7 +29,7 @@
#include "mongo/db/replica_set_endpoint_sharding_state.h"
#include "mongo/db/multitenancy_gen.h"
-#include "mongo/db/s/sharding_cluster_parameters_gen.h"
+#include "mongo/s/sharding_cluster_parameters_gen.h"
#include "mongo/s/sharding_feature_flags_gen.h"
#define MONGO_LOGV2_DEFAULT_COMPONENT ::mongo::logv2::LogComponent::kSharding
diff --git a/src/mongo/db/replica_set_endpoint_sharding_state_test.cpp b/src/mongo/db/replica_set_endpoint_sharding_state_test.cpp
index 99826a8166a..2d301c39c9a 100644
--- a/src/mongo/db/replica_set_endpoint_sharding_state_test.cpp
+++ b/src/mongo/db/replica_set_endpoint_sharding_state_test.cpp
@@ -31,9 +31,9 @@
#include "mongo/db/auth/authz_manager_external_state_mock.h"
#include "mongo/db/replica_set_endpoint_test_fixture.h"
-#include "mongo/db/s/sharding_cluster_parameters_gen.h"
#include "mongo/db/service_context_d_test_fixture.h"
#include "mongo/idl/server_parameter_test_util.h"
+#include "mongo/s/sharding_cluster_parameters_gen.h"
#include "mongo/unittest/death_test.h"
namespace mongo {
diff --git a/src/mongo/db/replica_set_endpoint_test_fixture.cpp b/src/mongo/db/replica_set_endpoint_test_fixture.cpp
index 69b01a7b696..01d8d0505c1 100644
--- a/src/mongo/db/replica_set_endpoint_test_fixture.cpp
+++ b/src/mongo/db/replica_set_endpoint_test_fixture.cpp
@@ -29,7 +29,7 @@
#include "mongo/db/replica_set_endpoint_test_fixture.h"
-#include "mongo/db/s/sharding_cluster_parameters_gen.h"
+#include "mongo/s/sharding_cluster_parameters_gen.h"
#define MONGO_LOGV2_DEFAULT_COMPONENT ::mongo::logv2::LogComponent::kTest
diff --git a/src/mongo/db/replica_set_endpoint_test_fixture.h b/src/mongo/db/replica_set_endpoint_test_fixture.h
index ed8be17b424..551658a25b1 100644
--- a/src/mongo/db/replica_set_endpoint_test_fixture.h
+++ b/src/mongo/db/replica_set_endpoint_test_fixture.h
@@ -29,7 +29,7 @@
#pragma once
-#include "mongo/db/s/sharding_cluster_parameters_gen.h"
+#include "mongo/s/sharding_cluster_parameters_gen.h"
#include "mongo/unittest/unittest.h"
namespace mongo {
diff --git a/src/mongo/db/s/SConscript b/src/mongo/db/s/SConscript
index 52514dd23bc..d3e795a2bfe 100644
--- a/src/mongo/db/s/SConscript
+++ b/src/mongo/db/s/SConscript
@@ -402,7 +402,6 @@ env.Library(
'$BUILD_DIR/mongo/util/pcre_wrapper',
'forwardable_operation_metadata',
'resharding_server_parameters_idl',
- 'sharding_cluster_parameters_idl',
'sharding_logging',
'user_writes_recoverable_critical_section',
],
@@ -735,15 +734,6 @@ env.Library(
LIBDEPS_PRIVATE=["$BUILD_DIR/mongo/db/server_base"],
)
-env.Library(
- target="sharding_cluster_parameters_idl",
- source=["sharding_cluster_parameters.idl"],
- LIBDEPS_PRIVATE=[
- "$BUILD_DIR/mongo/db/server_base",
- "$BUILD_DIR/mongo/idl/cluster_server_parameter",
- ],
-)
-
env.CppUnitTest(
target='shard_server_op_observer_test',
source=[
@@ -954,7 +944,6 @@ env.CppUnitTest(
'$BUILD_DIR/mongo/idl/cluster_server_parameter_common',
'$BUILD_DIR/mongo/util/version_impl',
'config_server_test_fixture',
- 'sharding_cluster_parameters_idl',
'sharding_commands_d',
],
)
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 9aae7dce6e0..3383cd05fdc 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
@@ -102,7 +102,6 @@
#include "mongo/db/s/add_shard_util.h"
#include "mongo/db/s/config/sharding_catalog_manager.h"
#include "mongo/db/s/range_deletion_task_gen.h"
-#include "mongo/db/s/sharding_cluster_parameters_gen.h"
#include "mongo/db/s/sharding_config_server_parameters_gen.h"
#include "mongo/db/s/sharding_ddl_util.h"
#include "mongo/db/s/sharding_logging.h"
@@ -145,6 +144,7 @@
#include "mongo/s/request_types/sharded_ddl_commands_gen.h"
#include "mongo/s/request_types/shardsvr_join_ddl_coordinators_request_gen.h"
#include "mongo/s/request_types/shardsvr_join_migrations_request_gen.h"
+#include "mongo/s/sharding_cluster_parameters_gen.h"
#include "mongo/s/sharding_feature_flags_gen.h"
#include "mongo/s/sharding_state.h"
#include "mongo/s/write_ops/batched_command_response.h"
diff --git a/src/mongo/db/s/resharding/resharding_coordinator_test.cpp b/src/mongo/db/s/resharding/resharding_coordinator_test.cpp
index c40ba728388..d1a2b7ed186 100644
--- a/src/mongo/db/s/resharding/resharding_coordinator_test.cpp
+++ b/src/mongo/db/s/resharding/resharding_coordinator_test.cpp
@@ -63,7 +63,6 @@
#include "mongo/db/s/resharding/resharding_coordinator_service.h"
#include "mongo/db/s/resharding/resharding_metrics.h"
#include "mongo/db/s/resharding/resharding_util.h"
-#include "mongo/db/s/sharding_cluster_parameters_gen.h"
#include "mongo/db/s/transaction_coordinator_service.h"
#include "mongo/db/service_context.h"
#include "mongo/db/session/logical_session_cache.h"
@@ -82,6 +81,7 @@
#include "mongo/s/resharding/common_types_gen.h"
#include "mongo/s/resharding/type_collection_fields_gen.h"
#include "mongo/s/shard_key_pattern.h"
+#include "mongo/s/sharding_cluster_parameters_gen.h"
#include "mongo/unittest/assert.h"
#include "mongo/unittest/bson_test_util.h"
#include "mongo/unittest/framework.h"
diff --git a/src/mongo/db/s/sharding_ddl_coordinator_service.cpp b/src/mongo/db/s/sharding_ddl_coordinator_service.cpp
index 5750aa99615..276c4c707b6 100644
--- a/src/mongo/db/s/sharding_ddl_coordinator_service.cpp
+++ b/src/mongo/db/s/sharding_ddl_coordinator_service.cpp
@@ -69,7 +69,6 @@
#include "mongo/db/s/rename_collection_coordinator.h"
#include "mongo/db/s/reshard_collection_coordinator.h"
#include "mongo/db/s/set_allow_migrations_coordinator.h"
-#include "mongo/db/s/sharding_cluster_parameters_gen.h"
#include "mongo/db/s/sharding_ddl_coordinator.h"
#include "mongo/db/s/untrack_unsplittable_collection_coordinator.h"
#include "mongo/logv2/log.h"
@@ -77,6 +76,7 @@
#include "mongo/logv2/log_component.h"
#include "mongo/logv2/redaction.h"
#include "mongo/s/database_version.h"
+#include "mongo/s/sharding_cluster_parameters_gen.h"
#include "mongo/util/assert_util.h"
#include "mongo/util/fail_point.h"
#include "mongo/util/future_impl.h"
diff --git a/src/mongo/db/s/sharding_ddl_util.cpp b/src/mongo/db/s/sharding_ddl_util.cpp
index 8557976fe0f..08081f90f95 100644
--- a/src/mongo/db/s/sharding_ddl_util.cpp
+++ b/src/mongo/db/s/sharding_ddl_util.cpp
@@ -74,7 +74,6 @@
#include "mongo/db/resource_yielder.h"
#include "mongo/db/s/config/initial_split_policy.h"
#include "mongo/db/s/remove_tags_gen.h"
-#include "mongo/db/s/sharding_cluster_parameters_gen.h"
#include "mongo/db/s/sharding_logging.h"
#include "mongo/db/server_options.h"
#include "mongo/db/service_context.h"
@@ -102,6 +101,7 @@
#include "mongo/s/grid.h"
#include "mongo/s/request_types/set_allow_migrations_gen.h"
#include "mongo/s/shard_key_pattern.h"
+#include "mongo/s/sharding_cluster_parameters_gen.h"
#include "mongo/s/sharding_feature_flags_gen.h"
#include "mongo/s/write_ops/batched_command_request.h"
#include "mongo/s/write_ops/batched_command_response.h"
diff --git a/src/mongo/db/s/shardsvr_reshard_collection_command.cpp b/src/mongo/db/s/shardsvr_reshard_collection_command.cpp
index 86c73918229..e2fe072f808 100644
--- a/src/mongo/db/s/shardsvr_reshard_collection_command.cpp
+++ b/src/mongo/db/s/shardsvr_reshard_collection_command.cpp
@@ -45,7 +45,6 @@
#include "mongo/db/s/reshard_collection_coordinator.h"
#include "mongo/db/s/reshard_collection_coordinator_document_gen.h"
#include "mongo/db/s/resharding/resharding_util.h"
-#include "mongo/db/s/sharding_cluster_parameters_gen.h"
#include "mongo/db/s/sharding_ddl_coordinator_gen.h"
#include "mongo/db/s/sharding_ddl_coordinator_service.h"
#include "mongo/db/service_context.h"
@@ -53,6 +52,7 @@
#include "mongo/s/cluster_ddl.h"
#include "mongo/s/request_types/sharded_ddl_commands_gen.h"
#include "mongo/s/resharding/resharding_feature_flag_gen.h"
+#include "mongo/s/sharding_cluster_parameters_gen.h"
#include "mongo/s/sharding_state.h"
#include "mongo/util/assert_util.h"
#include "mongo/util/future.h"
diff --git a/src/mongo/db/service_entry_point_common.cpp b/src/mongo/db/service_entry_point_common.cpp
index e272d01a93d..82ab65fb84d 100644
--- a/src/mongo/db/service_entry_point_common.cpp
+++ b/src/mongo/db/service_entry_point_common.cpp
@@ -111,7 +111,6 @@
#include "mongo/db/repl/tenant_migration_access_blocker_util.h"
#include "mongo/db/request_execution_context.h"
#include "mongo/db/s/operation_sharding_state.h"
-#include "mongo/db/s/sharding_cluster_parameters_gen.h"
#include "mongo/db/s/sharding_statistics.h"
#include "mongo/db/s/transaction_coordinator_factory.h"
#include "mongo/db/server_feature_flags_gen.h"
@@ -160,6 +159,7 @@
#include "mongo/s/query_analysis_sampler.h"
#include "mongo/s/shard_cannot_refresh_due_to_locks_held_exception.h"
#include "mongo/s/shard_version.h"
+#include "mongo/s/sharding_cluster_parameters_gen.h"
#include "mongo/s/sharding_feature_flags_gen.h"
#include "mongo/s/sharding_state.h"
#include "mongo/s/stale_exception.h"
diff --git a/src/mongo/s/SConscript b/src/mongo/s/SConscript
index 27b30d3b552..293041cd614 100644
--- a/src/mongo/s/SConscript
+++ b/src/mongo/s/SConscript
@@ -290,6 +290,7 @@ env.Library(
'shard_cannot_refresh_due_to_locks_held_exception.cpp',
'shard_key_pattern.cpp',
'shard_version_factory.cpp',
+ 'sharding_cluster_parameters.idl',
'sharding_feature_flags.cpp',
'sharding_feature_flags.idl',
'stale_exception.cpp',
@@ -740,7 +741,6 @@ env.CppUnitTest(
'$BUILD_DIR/mongo/db/pipeline/process_interface/mongos_process_interface_factory',
'$BUILD_DIR/mongo/db/query/query_test_service_context',
'$BUILD_DIR/mongo/db/repl/replmocks',
- '$BUILD_DIR/mongo/db/s/sharding_cluster_parameters_idl',
'$BUILD_DIR/mongo/db/service_context_non_d',
'$BUILD_DIR/mongo/db/timeseries/timeseries_conversion_util',
'$BUILD_DIR/mongo/db/timeseries/timeseries_options',
diff --git a/src/mongo/s/catalog/sharding_catalog_client_impl.cpp b/src/mongo/s/catalog/sharding_catalog_client_impl.cpp
index 41e286fbacb..eec262752e9 100644
--- a/src/mongo/s/catalog/sharding_catalog_client_impl.cpp
+++ b/src/mongo/s/catalog/sharding_catalog_client_impl.cpp
@@ -73,7 +73,6 @@
#include "mongo/db/pipeline/pipeline.h"
#include "mongo/db/repl/optime.h"
#include "mongo/db/repl/read_concern_args.h"
-#include "mongo/db/s/sharding_cluster_parameters_gen.h"
#include "mongo/db/server_options.h"
#include "mongo/db/vector_clock.h"
#include "mongo/idl/idl_parser.h"
@@ -93,6 +92,7 @@
#include "mongo/s/client/shard_registry.h"
#include "mongo/s/database_version.h"
#include "mongo/s/grid.h"
+#include "mongo/s/sharding_cluster_parameters_gen.h"
#include "mongo/s/write_ops/batched_command_request.h"
#include "mongo/s/write_ops/batched_command_response.h"
#include "mongo/util/assert_util.h"
diff --git a/src/mongo/s/catalog/sharding_catalog_client_read_preference_test.cpp b/src/mongo/s/catalog/sharding_catalog_client_read_preference_test.cpp
index e87f308e208..ed87c51b65b 100644
--- a/src/mongo/s/catalog/sharding_catalog_client_read_preference_test.cpp
+++ b/src/mongo/s/catalog/sharding_catalog_client_read_preference_test.cpp
@@ -35,7 +35,6 @@
#include "mongo/db/commands.h"
#include "mongo/db/query/find_command.h"
#include "mongo/db/query/query_request_helper.h"
-#include "mongo/db/s/sharding_cluster_parameters_gen.h"
#include "mongo/executor/network_test_env.h"
#include "mongo/executor/remote_command_request.h"
#include "mongo/idl/cluster_server_parameter_gen.h"
@@ -43,6 +42,7 @@
#include "mongo/rpc/metadata/repl_set_metadata.h"
#include "mongo/rpc/op_msg.h"
#include "mongo/s/catalog/sharding_catalog_client.h"
+#include "mongo/s/sharding_cluster_parameters_gen.h"
#include "mongo/s/sharding_mongos_test_fixture.h"
#include "mongo/unittest/assert.h"
#include "mongo/unittest/bson_test_util.h"
diff --git a/src/mongo/db/s/sharding_cluster_parameters.idl b/src/mongo/s/sharding_cluster_parameters.idl
index b0b24f5578f..b0b24f5578f 100644
--- a/src/mongo/db/s/sharding_cluster_parameters.idl
+++ b/src/mongo/s/sharding_cluster_parameters.idl