diff options
author | George Wangensteen <george.wangensteen@mongodb.com> | 2021-01-12 23:44:35 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2021-02-08 20:24:26 +0000 |
commit | 6c57358e4156ae4291f24fce1cf22ffc54f4dbb0 (patch) | |
tree | 51e642b6929019ca8da818599c5ec72d18abfa1a | |
parent | ecd41f8b3bfe2154921cbcede9040d535a46e0c5 (diff) | |
download | mongo-6c57358e4156ae4291f24fce1cf22ffc54f4dbb0.tar.gz |
SERVER-53394 Make ShardingTaskExecutorPoolReplicaSetMatching default to disabled for mongod
(cherry picked from commit ac99b5cf6202e2941220a1f5f56b8223af1841e9)
12 files changed, 106 insertions, 2 deletions
diff --git a/buildscripts/resmokeconfig/suites/sharding_last_stable_mongos_and_mixed_shards.yml b/buildscripts/resmokeconfig/suites/sharding_last_stable_mongos_and_mixed_shards.yml index 2cd6843cb66..020cac625db 100644 --- a/buildscripts/resmokeconfig/suites/sharding_last_stable_mongos_and_mixed_shards.yml +++ b/buildscripts/resmokeconfig/suites/sharding_last_stable_mongos_and_mixed_shards.yml @@ -173,6 +173,8 @@ selector: - jstests/sharding/ismaster.js # Uses the enableShardedIndexConsistencyCheck parameter which does not exist on 4.0. - jstests/sharding/kill_pinned_cursor.js + # Uses the ShardingTaskExecutorPoolReplicaSetMatching parameter which does not exist on 4.0. + - jstests/sharding/sharding_task_executor_pool_matching_policy.js executor: config: shell_options: diff --git a/buildscripts/resmokeconfig/suites/sharding_rs_matching_disabled.yml b/buildscripts/resmokeconfig/suites/sharding_rs_matching_disabled.yml index f159ca35e52..e687680e55b 100644 --- a/buildscripts/resmokeconfig/suites/sharding_rs_matching_disabled.yml +++ b/buildscripts/resmokeconfig/suites/sharding_rs_matching_disabled.yml @@ -3,6 +3,9 @@ test_kind: js_test selector: roots: - jstests/sharding/*.js + exclude_files: + # Skip tests that set the matching policy internally. + - jstests/sharding/sharding_task_executor_pool_matching_policy.js executor: config: diff --git a/buildscripts/resmokeconfig/suites/sharding_rs_matching_match_busiest_node.yml b/buildscripts/resmokeconfig/suites/sharding_rs_matching_match_busiest_node.yml index 5aefdbbe4ec..68ad82ff1d8 100644 --- a/buildscripts/resmokeconfig/suites/sharding_rs_matching_match_busiest_node.yml +++ b/buildscripts/resmokeconfig/suites/sharding_rs_matching_match_busiest_node.yml @@ -3,6 +3,9 @@ test_kind: js_test selector: roots: - jstests/sharding/*.js + exclude_files: + # Skip tests that set the matching policy internally. + - jstests/sharding/sharding_task_executor_pool_matching_policy.js executor: config: diff --git a/etc/backports_required_for_multiversion_tests.yml b/etc/backports_required_for_multiversion_tests.yml index be5c138cf31..d752f7a2f73 100644 --- a/etc/backports_required_for_multiversion_tests.yml +++ b/etc/backports_required_for_multiversion_tests.yml @@ -92,6 +92,8 @@ all: test_file: jstests/sharding/change_stream_empty_apply_ops.js - ticket: SERVER-43904 test_file: jstests/replsets/election_handoff_skips_unelectable_nodes.js + - ticket: SERVER-53394 + test_file: jstests/sharding/sharding_task_executor_pool_matching_policy.js # Tests that should only be excluded from particular suites should be listed under that suite. suites: diff --git a/jstests/sharding/sharding_task_executor_pool_matching_policy.js b/jstests/sharding/sharding_task_executor_pool_matching_policy.js new file mode 100644 index 00000000000..bb7341825af --- /dev/null +++ b/jstests/sharding/sharding_task_executor_pool_matching_policy.js @@ -0,0 +1,55 @@ +// Tests that the ShardingTaskExecutorPoolReplicaSetMatchingPolicy is correctly set when the default +// "automatic" value is used for the ShardingTaskExecutorPoolReplicaSetMatching parameter (on +// mongos, "matchPrimaryNode" should be set; on mongod, the policy should be "disabled"). + +(function() { +"use strict"; + +// Helper function to check the matching policy of a node, given the output of the connPoolStats +// command run against the node and the expected policy. +function checkSTEPReplicaSetMatchingPolicy(connPoolStats, expectedPolicy) { + assert("replicaSetMatchingStrategy" in connPoolStats); + let nodePolicy = connPoolStats["replicaSetMatchingStrategy"]; + assert.eq(nodePolicy, expectedPolicy); +} + +// Helper function that checks, given a connection to a mongo{s, d}, that the output value returned +// by the "getParameter" command for the parameter "ShardingTaskExecutorPoolReplicaSetMatching" +// is "automatic". +function checkGetParameterOutputIsAuto(dbConn) { + const getParameterCommand = {getParameter: 1}; + getParameterCommand["ShardingTaskExecutorPoolReplicaSetMatching"] = 1; + const result = assert.commandWorked(dbConn.adminCommand(getParameterCommand)); + const value = result["ShardingTaskExecutorPoolReplicaSetMatching"]; + assert.eq(value, "automatic"); +} + +// Setup test fixture; get connection to mongos and each mongod. +let paramsDoc = { + mongosOptions: {setParameter: {ShardingTaskExecutorPoolReplicaSetMatching: "automatic"}}, + shardOptions: {setParameter: {ShardingTaskExecutorPoolReplicaSetMatching: "automatic"}} +}; +let st = new ShardingTest({shards: 2, mongos: 1, other: paramsDoc}); +let mongos = st.s; +let mongod = st.shard0; +let otherMongod = st.shard1; + +// Check that each connection currently has policy value "automatic" +checkGetParameterOutputIsAuto(mongos); +checkGetParameterOutputIsAuto(mongod); +checkGetParameterOutputIsAuto(otherMongod); + +// Build connPoolStats command for each mongod and mongos; ensure they run without error. +let mongosStats = mongos.adminCommand({connPoolStats: 1}); +let mongodStats = mongod.adminCommand({connPoolStats: 1}); +let otherMongodStats = otherMongod.adminCommand({connPoolStats: 1}); +assert.commandWorked(mongosStats); +assert.commandWorked(mongodStats); +assert.commandWorked(otherMongodStats); + +// Ensure the CPS contain the correct output (described in header comment for this test). +checkSTEPReplicaSetMatchingPolicy(mongosStats, "matchPrimaryNode"); +checkSTEPReplicaSetMatchingPolicy(mongodStats, "disabled"); +checkSTEPReplicaSetMatchingPolicy(otherMongodStats, "disabled"); +st.stop(); +})(); diff --git a/src/mongo/executor/connection_pool.cpp b/src/mongo/executor/connection_pool.cpp index 4b04c42a3ea..f812c8abc98 100644 --- a/src/mongo/executor/connection_pool.cpp +++ b/src/mongo/executor/connection_pool.cpp @@ -186,6 +186,8 @@ public: return "LimitController"_sd; } + void updateConnectionPoolStats(ConnectionPoolStats* cps) const override {} + protected: struct PoolData { HostAndPort host; @@ -557,6 +559,7 @@ SemiFuture<ConnectionPool::ConnectionHandle> ConnectionPool::get(const HostAndPo void ConnectionPool::appendConnectionStats(ConnectionPoolStats* stats) const { stdx::lock_guard lk(_mutex); + _controller->updateConnectionPoolStats(stats); for (const auto& kv : _pools) { HostAndPort host = kv.first; diff --git a/src/mongo/executor/connection_pool.h b/src/mongo/executor/connection_pool.h index d2f009d6859..750f045b2c0 100644 --- a/src/mongo/executor/connection_pool.h +++ b/src/mongo/executor/connection_pool.h @@ -472,6 +472,8 @@ public: return _pool; } + virtual void updateConnectionPoolStats([[maybe_unused]] ConnectionPoolStats* cps) const = 0; + protected: ConnectionPool* _pool = nullptr; }; diff --git a/src/mongo/executor/connection_pool_stats.cpp b/src/mongo/executor/connection_pool_stats.cpp index 31da4d38f96..5664d06ffd0 100644 --- a/src/mongo/executor/connection_pool_stats.cpp +++ b/src/mongo/executor/connection_pool_stats.cpp @@ -99,6 +99,10 @@ void ConnectionPoolStats::appendToBSON(mongo::BSONObjBuilder& result, bool forFT } { + if (strategy) { + result.append("replicaSetMatchingStrategy", matchingStrategyToString(*strategy)); + } + BSONObjBuilder poolBuilder(result.subobjStart("pools")); for (const auto& pool : statsByPool) { BSONObjBuilder poolInfo(poolBuilder.subobjStart(pool.first)); diff --git a/src/mongo/executor/connection_pool_stats.h b/src/mongo/executor/connection_pool_stats.h index bfa9a771ac2..3f9235040eb 100644 --- a/src/mongo/executor/connection_pool_stats.h +++ b/src/mongo/executor/connection_pool_stats.h @@ -29,6 +29,7 @@ #pragma once +#include "mongo/s/sharding_task_executor_pool_controller.h" #include "mongo/stdx/unordered_map.h" #include "mongo/util/net/hostandport.h" @@ -66,6 +67,7 @@ struct ConnectionPoolStats { size_t totalAvailable = 0u; size_t totalCreated = 0u; size_t totalRefreshing = 0u; + boost::optional<ShardingTaskExecutorPoolController::MatchingStrategy> strategy; using StatsByHost = std::map<HostAndPort, ConnectionStatsPer>; diff --git a/src/mongo/s/sharding_task_executor_pool.idl b/src/mongo/s/sharding_task_executor_pool.idl index 4a036162971..361ad6606ff 100644 --- a/src/mongo/s/sharding_task_executor_pool.idl +++ b/src/mongo/s/sharding_task_executor_pool.idl @@ -90,4 +90,4 @@ server_parameters: set_at: [ startup, runtime ] cpp_varname: "ShardingTaskExecutorPoolController::gParameters.matchingStrategyString" on_update: "ShardingTaskExecutorPoolController::onUpdateMatchingStrategy" - default: "matchPrimaryNode" + default: "automatic" # matchPrimaryNode on mongos; disabled on mongod diff --git a/src/mongo/s/sharding_task_executor_pool_controller.cpp b/src/mongo/s/sharding_task_executor_pool_controller.cpp index cc7b2197f48..8853f87b7df 100644 --- a/src/mongo/s/sharding_task_executor_pool_controller.cpp +++ b/src/mongo/s/sharding_task_executor_pool_controller.cpp @@ -32,6 +32,8 @@ #include "mongo/platform/basic.h" #include "mongo/client/replica_set_monitor.h" +#include "mongo/executor/connection_pool_stats.h" +#include "mongo/s/is_mongos.h" #include "mongo/s/sharding_task_executor_pool_controller.h" #include "mongo/util/log.h" @@ -83,7 +85,13 @@ Status ShardingTaskExecutorPoolController::validatePendingTimeout(const int& pen Status ShardingTaskExecutorPoolController::onUpdateMatchingStrategy(const std::string& str) { // TODO Fix up after SERVER-40224 - if (str == "disabled") { + if (str == "automatic") { + if (isMongos()) { + gParameters.matchingStrategy.store(MatchingStrategy::kMatchPrimaryNode); + } else { + gParameters.matchingStrategy.store(MatchingStrategy::kDisabled); + } + } else if (str == "disabled") { gParameters.matchingStrategy.store(MatchingStrategy::kDisabled); } else if (str == "matchPrimaryNode") { gParameters.matchingStrategy.store(MatchingStrategy::kMatchPrimaryNode); @@ -312,4 +320,9 @@ Milliseconds ShardingTaskExecutorPoolController::toRefreshTimeout() const { return Milliseconds{gParameters.toRefreshTimeoutMS.load()}; } +void ShardingTaskExecutorPoolController::updateConnectionPoolStats( + executor::ConnectionPoolStats* cps) const { + cps->strategy = gParameters.matchingStrategy.load(); +} + } // namespace mongo diff --git a/src/mongo/s/sharding_task_executor_pool_controller.h b/src/mongo/s/sharding_task_executor_pool_controller.h index 718c2b0cd0a..4cee10bd9f6 100644 --- a/src/mongo/s/sharding_task_executor_pool_controller.h +++ b/src/mongo/s/sharding_task_executor_pool_controller.h @@ -77,6 +77,19 @@ public: kMatchBusiestNode, }; + friend StringData matchingStrategyToString(MatchingStrategy strategy) { + switch (strategy) { + case ShardingTaskExecutorPoolController::MatchingStrategy::kMatchPrimaryNode: + return "matchPrimaryNode"_sd; + case ShardingTaskExecutorPoolController::MatchingStrategy::kMatchBusiestNode: + return "matchBusiestNode"_sd; + case ShardingTaskExecutorPoolController::MatchingStrategy::kDisabled: + return "disabled"_sd; + default: + MONGO_UNREACHABLE; + } + } + class Parameters { public: AtomicWord<int> minConnections; @@ -129,6 +142,8 @@ public: return "ShardingTaskExecutorPoolController"_sd; } + void updateConnectionPoolStats(executor::ConnectionPoolStats* cps) const override; + private: void _addGroup(WithLock, const ReplicaSetChangeNotifier::State& state); void _removeGroup(WithLock, const std::string& key); |