diff options
author | Jack Mulrow <jack.mulrow@mongodb.com> | 2020-01-21 20:50:37 +0000 |
---|---|---|
committer | evergreen <evergreen@mongodb.com> | 2020-01-21 20:50:37 +0000 |
commit | 9c638e3cb001a4dc9fcf869d2602c504439c2aef (patch) | |
tree | 5e9ad8f321c148607968b980daca2233af5b0e53 /src/mongo/db | |
parent | 685afc7262c35f71cc04ceb0819a3a90f06c95bb (diff) | |
download | mongo-9c638e3cb001a4dc9fcf869d2602c504439c2aef.tar.gz |
SERVER-43832 Expose readConcern and writeConcern defaults in serverStatus
Diffstat (limited to 'src/mongo/db')
-rw-r--r-- | src/mongo/db/commands/SConscript | 2 | ||||
-rw-r--r-- | src/mongo/db/commands/read_write_concern_defaults_server_status.cpp | 60 | ||||
-rw-r--r-- | src/mongo/db/commands/rwc_defaults_commands.cpp | 4 | ||||
-rw-r--r-- | src/mongo/db/ftdc/ftdc_mongod.cpp | 8 | ||||
-rw-r--r-- | src/mongo/db/ftdc/ftdc_mongos.cpp | 7 | ||||
-rw-r--r-- | src/mongo/db/ftdc/ftdc_server.cpp | 4 | ||||
-rw-r--r-- | src/mongo/db/rw_concern_default.idl | 4 | ||||
-rw-r--r-- | src/mongo/db/s/SConscript | 1 | ||||
-rw-r--r-- | src/mongo/db/s/balancer/migration_manager_test.cpp | 7 |
9 files changed, 94 insertions, 3 deletions
diff --git a/src/mongo/db/commands/SConscript b/src/mongo/db/commands/SConscript index 7e6f19b0286..d6903eeeec2 100644 --- a/src/mongo/db/commands/SConscript +++ b/src/mongo/db/commands/SConscript @@ -369,6 +369,7 @@ env.Library( "mr.cpp", "oplog_application_checks.cpp", "oplog_note.cpp", + 'read_write_concern_defaults_server_status.cpp', "resize_oplog.cpp", "restart_catalog_command.cpp", 'rwc_defaults_commands.cpp', @@ -423,6 +424,7 @@ env.Library( 'mongod_fcv', 'mongod_fsync', 'profile_common', + 'server_status', 'servers', 'set_index_commit_quorum_idl', 'shell_protocol', 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 new file mode 100644 index 00000000000..6f2cfc6f8b5 --- /dev/null +++ b/src/mongo/db/commands/read_write_concern_defaults_server_status.cpp @@ -0,0 +1,60 @@ +/** + * 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/platform/basic.h" + +#include "mongo/db/commands/server_status.h" +#include "mongo/db/read_write_concern_defaults.h" +#include "mongo/db/repl/replication_coordinator.h" + +namespace mongo { +namespace { + +class ReadWriteConcernDefaultsServerStatus final : public ServerStatusSection { +public: + ReadWriteConcernDefaultsServerStatus() : ServerStatusSection("defaultRWConcern") {} + + bool includeByDefault() const override { + return serverGlobalParams.clusterRole != ClusterRole::ShardServer; + } + + BSONObj generateSection(OperationContext* opCtx, + const BSONElement& configElement) const override { + if (serverGlobalParams.clusterRole == ClusterRole::ShardServer || + !repl::ReplicationCoordinator::get(opCtx)->isReplEnabled()) { + return {}; + } + + return ReadWriteConcernDefaults::get(opCtx).getDefault(opCtx).toBSON(); + } + +} defaultRWConcernServerStatus; + +} // namespace +} // namespace mongo diff --git a/src/mongo/db/commands/rwc_defaults_commands.cpp b/src/mongo/db/commands/rwc_defaults_commands.cpp index 848ee832504..b4ada0db3ec 100644 --- a/src/mongo/db/commands/rwc_defaults_commands.cpp +++ b/src/mongo/db/commands/rwc_defaults_commands.cpp @@ -164,7 +164,9 @@ public: auto& rwcDefaults = ReadWriteConcernDefaults::get(opCtx->getServiceContext()); if (request().getInMemory() && *request().getInMemory()) { - return rwcDefaults.getDefault(opCtx); + auto rwc = rwcDefaults.getDefault(opCtx); + rwc.setInMemory(true); + return rwc; } // Force a refresh to find the most recent defaults, then return them. diff --git a/src/mongo/db/ftdc/ftdc_mongod.cpp b/src/mongo/db/ftdc/ftdc_mongod.cpp index 73e598ec410..e53b423f0bb 100644 --- a/src/mongo/db/ftdc/ftdc_mongod.cpp +++ b/src/mongo/db/ftdc/ftdc_mongod.cpp @@ -57,6 +57,14 @@ void registerMongoDCollectors(FTDCController* controller) { "local", BSON("collStats" << "oplog.rs"))); + if (serverGlobalParams.clusterRole != ClusterRole::ShardServer) { + // GetDefaultRWConcern + controller->addOnRotateCollector(std::make_unique<FTDCSimpleInternalCommandCollector>( + "getDefaultRWConcern", + "getDefaultRWConcern", + "", + BSON("getDefaultRWConcern" << 1 << "inMemory" << true))); + } } } diff --git a/src/mongo/db/ftdc/ftdc_mongos.cpp b/src/mongo/db/ftdc/ftdc_mongos.cpp index ef1cc40924a..e45c8031d6e 100644 --- a/src/mongo/db/ftdc/ftdc_mongos.cpp +++ b/src/mongo/db/ftdc/ftdc_mongos.cpp @@ -87,6 +87,13 @@ public: void registerMongoSCollectors(FTDCController* controller) { // PoolStats controller->addPeriodicCollector(std::make_unique<ConnPoolStatsCollector>()); + + // GetDefaultRWConcern + controller->addOnRotateCollector(std::make_unique<FTDCSimpleInternalCommandCollector>( + "getDefaultRWConcern", + "getDefaultRWConcern", + "", + BSON("getDefaultRWConcern" << 1 << "inMemory" << true))); } void startMongoSFTDC() { diff --git a/src/mongo/db/ftdc/ftdc_server.cpp b/src/mongo/db/ftdc/ftdc_server.cpp index fc081316701..fdb2171707f 100644 --- a/src/mongo/db/ftdc/ftdc_server.cpp +++ b/src/mongo/db/ftdc/ftdc_server.cpp @@ -228,8 +228,8 @@ void startFTDC(boost::filesystem::path& path, "serverStatus", "serverStatus", "", - BSON("serverStatus" << 1 << "tcMalloc" << true << "sharding" << false << "timing" - << false))); + BSON("serverStatus" << 1 << "tcMalloc" << true << "sharding" << false << "timing" << false + << "defaultRWConcern" << false))); registerCollectors(controller.get()); diff --git a/src/mongo/db/rw_concern_default.idl b/src/mongo/db/rw_concern_default.idl index 94aca23c7b9..5ff0b997b2a 100644 --- a/src/mongo/db/rw_concern_default.idl +++ b/src/mongo/db/rw_concern_default.idl @@ -60,3 +60,7 @@ structs: description: "The wallclock time when this node updated its understanding of the default read or write concern" type: date optional: true + inMemory: + description: "Whether these defaults were from the inMemory cache" + type: bool + optional: true diff --git a/src/mongo/db/s/SConscript b/src/mongo/db/s/SConscript index 823a76b04a2..029f80d5451 100644 --- a/src/mongo/db/s/SConscript +++ b/src/mongo/db/s/SConscript @@ -359,6 +359,7 @@ env.CppUnitTest( ], LIBDEPS=[ '$BUILD_DIR/mongo/db/auth/authmocks', + '$BUILD_DIR/mongo/db/read_write_concern_defaults_mock', '$BUILD_DIR/mongo/db/repl/replication_info', '$BUILD_DIR/mongo/s/config_server_test_fixture', '$BUILD_DIR/mongo/util/version_impl', diff --git a/src/mongo/db/s/balancer/migration_manager_test.cpp b/src/mongo/db/s/balancer/migration_manager_test.cpp index 74c6e0168a1..c0d4032034d 100644 --- a/src/mongo/db/s/balancer/migration_manager_test.cpp +++ b/src/mongo/db/s/balancer/migration_manager_test.cpp @@ -32,6 +32,8 @@ #include <memory> #include "mongo/db/commands.h" +#include "mongo/db/read_write_concern_defaults.h" +#include "mongo/db/read_write_concern_defaults_cache_lookup_mock.h" #include "mongo/db/s/balancer/migration_manager.h" #include "mongo/db/s/balancer/migration_test_fixture.h" #include "mongo/db/s/config/sharding_catalog_manager.h" @@ -50,6 +52,10 @@ protected: _migrationManager = std::make_unique<MigrationManager>(getServiceContext()); _migrationManager->startRecoveryAndAcquireDistLocks(operationContext()); _migrationManager->finishRecovery(operationContext(), 0, kDefaultSecondaryThrottle); + + // Necessary because the migration manager may take a dist lock, which calls serverStatus + // and will attempt to return the latest read write concern defaults. + ReadWriteConcernDefaults::create(getServiceContext(), _lookupMock.getFetchDefaultsFn()); } void tearDown() override { @@ -95,6 +101,7 @@ protected: } std::unique_ptr<MigrationManager> _migrationManager; + ReadWriteConcernDefaultsLookupMock _lookupMock; }; TEST_F(MigrationManagerTest, OneCollectionTwoMigrations) { |