diff options
author | Cheahuychou Mao <cheahuychou.mao@mongodb.com> | 2020-01-28 15:54:24 -0500 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2020-01-29 04:23:11 +0000 |
commit | 5d376083d4c5e597bda2b967cfcce32874025b12 (patch) | |
tree | 983320dae845a80041e8c5a4a4c8b7e28bb24017 | |
parent | 367f47f7f19a6344039a15e3d0748508ad9c6c2c (diff) | |
download | mongo-5d376083d4c5e597bda2b967cfcce32874025b12.tar.gz |
SERVER-45437 Add readHedgingMode serverParameter
create mode 100644 src/mongo/s/mongos_server_parameters.cpp
create mode 100644 src/mongo/s/mongos_server_parameters.h
-rw-r--r-- | jstests/sharding/hedged_reads_server_parameters.js | 11 | ||||
-rw-r--r-- | src/mongo/s/SConscript | 1 | ||||
-rw-r--r-- | src/mongo/s/hedge_options_util.cpp | 2 | ||||
-rw-r--r-- | src/mongo/s/hedge_options_util_test.cpp | 22 | ||||
-rw-r--r-- | src/mongo/s/mongos_server_parameters.cpp | 48 | ||||
-rw-r--r-- | src/mongo/s/mongos_server_parameters.h | 46 | ||||
-rw-r--r-- | src/mongo/s/mongos_server_parameters.idl | 12 |
7 files changed, 137 insertions, 5 deletions
diff --git a/jstests/sharding/hedged_reads_server_parameters.js b/jstests/sharding/hedged_reads_server_parameters.js index 3c5dd089171..dab38ab6013 100644 --- a/jstests/sharding/hedged_reads_server_parameters.js +++ b/jstests/sharding/hedged_reads_server_parameters.js @@ -34,5 +34,16 @@ st.restartMongos(0, { assert.commandWorked(st.s.getDB(dbName).runCommand( {query: {count: collName}, $readPreference: {mode: "secondaryPreferred", hedge: {}}})); +// readHedgingMode "off". +st.restartMongos(0, { + restart: true, + setParameter: {readHedgingMode: "off"}, +}); + +assert.commandWorked(st.s.getDB(dbName).runCommand({ + query: {distinct: collName, key: "x"}, + $readPreference: {mode: "primaryPreferred", hedge: {}} +})); + st.stop(); })(); diff --git a/src/mongo/s/SConscript b/src/mongo/s/SConscript index ab5e0984fb6..55a58284272 100644 --- a/src/mongo/s/SConscript +++ b/src/mongo/s/SConscript @@ -413,6 +413,7 @@ env.Library( env.Library( target='mongos_server_parameters', source=[ + 'mongos_server_parameters.cpp', env.Idlc('mongos_server_parameters.idl')[0], ], LIBDEPS_PRIVATE=[ diff --git a/src/mongo/s/hedge_options_util.cpp b/src/mongo/s/hedge_options_util.cpp index 2de268c9e79..9301a416bcf 100644 --- a/src/mongo/s/hedge_options_util.cpp +++ b/src/mongo/s/hedge_options_util.cpp @@ -39,7 +39,7 @@ boost::optional<executor::RemoteCommandRequestOnAny::HedgeOptions> extractHedgeO OperationContext* opCtx, const BSONObj& cmdObj) { const auto hedgingMode = ReadPreferenceSetting::get(opCtx).hedgingMode; - if (hedgingMode && hedgingMode->getEnabled()) { + if (gReadHedgingMode == kReadHedgingModeOn && hedgingMode && hedgingMode->getEnabled()) { boost::optional<int> maxTimeMS; if (auto cmdOptionMaxTimeMSField = cmdObj[QueryRequest::cmdOptionMaxTimeMS]) { maxTimeMS = uassertStatusOK(QueryRequest::parseMaxTimeMS(cmdOptionMaxTimeMSField)); diff --git a/src/mongo/s/hedge_options_util_test.cpp b/src/mongo/s/hedge_options_util_test.cpp index 7aae8afadfe..1fd54e39082 100644 --- a/src/mongo/s/hedge_options_util_test.cpp +++ b/src/mongo/s/hedge_options_util_test.cpp @@ -104,16 +104,17 @@ protected: static inline const std::string kCollName = "testColl"; + static inline const std::string kReadHedgingModeFieldName = "readHedgingMode"; static inline const std::string kMaxTimeMSThresholdForHedgingFieldName = "maxTimeMSThresholdForHedging"; static inline const std::string kHedgingDelayPercentageFieldName = "hedgingDelayPercentage"; static inline const std::string kDefaultHedgingDelayMSFieldName = "defaultHedgingDelayMS"; static inline const BSONObj kDefaultParameters = - BSON(kMaxTimeMSThresholdForHedgingFieldName - << kMaxTimeMSThresholdForHedgingDefault << kHedgingDelayPercentageFieldName - << kHedgingDelayPercentageDefault << kDefaultHedgingDelayMSFieldName - << kDefaultHedgingDelayMSDefault); + BSON(kReadHedgingModeFieldName + << "on" << kMaxTimeMSThresholdForHedgingFieldName << gMaxTimeMSThresholdForHedging + << kHedgingDelayPercentageFieldName << gHedgingDelayPercentage + << kDefaultHedgingDelayMSFieldName << gDefaultHedgingDelayMS); private: ServiceContext::UniqueServiceContext _serviceCtx = ServiceContext::make(); @@ -225,5 +226,18 @@ TEST_F(HedgeOptionsUtilTestFixture, SetAll) { checkHedgeOptions(parameters, BSON("find" << kCollName), rspObj, Milliseconds{800}); } +TEST_F(HedgeOptionsUtilTestFixture, ReadHedgingModeOff) { + const auto parameters = + BSON(kReadHedgingModeFieldName << "off" << kMaxTimeMSThresholdForHedgingFieldName << 1000 + << kHedgingDelayPercentageFieldName << 50 + << kDefaultHedgingDelayMSFieldName << 800); + const auto rspObj = BSON("mode" + << "nearest" + << "hedge" << BSONObj()); + + checkHedgeOptions(parameters, BSON("find" << kCollName << "maxTimeMS" << 500), rspObj); + checkHedgeOptions(parameters, BSON("find" << kCollName), rspObj); +} + } // namespace } // namespace mongo diff --git a/src/mongo/s/mongos_server_parameters.cpp b/src/mongo/s/mongos_server_parameters.cpp new file mode 100644 index 00000000000..de9d5507598 --- /dev/null +++ b/src/mongo/s/mongos_server_parameters.cpp @@ -0,0 +1,48 @@ +/** + * Copyright (C) 2020-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/s/mongos_server_parameters.h" + +#include "mongo/util/str.h" + +namespace mongo { + +/** + * Validation callback for setParameter 'readHedgingMode'. + */ +Status validateReadHedgingMode(const std::string& mode) { + if (mode != kReadHedgingModeOn && mode != kReadHedgingModeOff) { + return {ErrorCodes::BadValue, + str::stream() << "readHedgingMode must be either \"" << kReadHedgingModeOn + << "\" or \"" << kReadHedgingModeOff << "\""}; + } + return Status::OK(); +} + +} // namespace mongo diff --git a/src/mongo/s/mongos_server_parameters.h b/src/mongo/s/mongos_server_parameters.h new file mode 100644 index 00000000000..9c2a580278b --- /dev/null +++ b/src/mongo/s/mongos_server_parameters.h @@ -0,0 +1,46 @@ +/** + * Copyright (C) 2020-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 + +#include "mongo/platform/basic.h" + +#include "mongo/base/status.h" + +namespace mongo { + +constexpr auto kReadHedgingModeOn = "on"; +constexpr auto kReadHedgingModeOff = "off"; + +/** + * Validation callback for setParameter 'readHedgingMode'. + */ +Status validateReadHedgingMode(const std::string& mode); + +} // namespace mongo diff --git a/src/mongo/s/mongos_server_parameters.idl b/src/mongo/s/mongos_server_parameters.idl index 1724d0e13ba..aaac5f4d2dc 100644 --- a/src/mongo/s/mongos_server_parameters.idl +++ b/src/mongo/s/mongos_server_parameters.idl @@ -29,6 +29,8 @@ global: cpp_namespace: "mongo" + cpp_includes: + - "mongo/s/mongos_server_parameters.h" imports: - "mongo/idl/basic_types.idl" @@ -58,6 +60,16 @@ server_parameters: cpp_varname: "gWarmMinConnectionsInShardingTaskExecutorPoolOnStartupWaitMS" default: 2000 # 2secs + readHedgingMode: + description: >- + Enables hedged reads. + set_at: [ startup ] + cpp_vartype: std::string + cpp_varname: "gReadHedgingMode" + default: "on" + validator: + callback: "validateReadHedgingMode" + maxTimeMSThresholdForHedging: description: >- The upper threshold for the expected running time of an operation (maxTimeMS) |