diff options
author | Gregory Wlodarek <gregory.wlodarek@mongodb.com> | 2020-11-12 18:23:34 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2020-11-13 01:13:53 +0000 |
commit | 185000ad894d5cb95a3c946158712054db57cb7a (patch) | |
tree | 274e6317aaea9af33aa6160e11e1e57325c4a195 /src/mongo | |
parent | 911538668252d9885fe3d3859175f2711fb064bc (diff) | |
download | mongo-185000ad894d5cb95a3c946158712054db57cb7a.tar.gz |
SERVER-48221 Shut down ftdc after storage engine
Diffstat (limited to 'src/mongo')
-rw-r--r-- | src/mongo/db/ftdc/controller.cpp | 2 | ||||
-rw-r--r-- | src/mongo/db/ftdc/util.h | 2 | ||||
-rw-r--r-- | src/mongo/db/mongod_main.cpp | 19 | ||||
-rw-r--r-- | src/mongo/db/repl/replication_coordinator_impl.cpp | 4 | ||||
-rw-r--r-- | src/mongo/db/service_context.cpp | 8 | ||||
-rw-r--r-- | src/mongo/db/service_context.h | 5 | ||||
-rw-r--r-- | src/mongo/db/storage/wiredtiger/oplog_stones_server_status_section.cpp | 11 |
7 files changed, 39 insertions, 12 deletions
diff --git a/src/mongo/db/ftdc/controller.cpp b/src/mongo/db/ftdc/controller.cpp index 4486ec7e345..907186b076b 100644 --- a/src/mongo/db/ftdc/controller.cpp +++ b/src/mongo/db/ftdc/controller.cpp @@ -191,7 +191,7 @@ void FTDCController::stop() { void FTDCController::doLoop() noexcept { // Note: All exceptions thrown in this loop are considered process fatal. The default terminate // is used to provide a good stack trace of the issue. - Client::initThread("ftdc"); + Client::initThread(kFTDCThreadName); Client* client = &cc(); // Update config diff --git a/src/mongo/db/ftdc/util.h b/src/mongo/db/ftdc/util.h index 4d47c610559..428a1c48a27 100644 --- a/src/mongo/db/ftdc/util.h +++ b/src/mongo/db/ftdc/util.h @@ -39,6 +39,8 @@ namespace mongo { +constexpr StringData kFTDCThreadName = "ftdc"_sd; + /** * Utilities for inflating and deflating BSON documents and metric arrays */ diff --git a/src/mongo/db/mongod_main.cpp b/src/mongo/db/mongod_main.cpp index d90aa62c09d..09863d97363 100644 --- a/src/mongo/db/mongod_main.cpp +++ b/src/mongo/db/mongod_main.cpp @@ -80,6 +80,7 @@ #include "mongo/db/fcv_op_observer.h" #include "mongo/db/free_mon/free_mon_mongod.h" #include "mongo/db/ftdc/ftdc_mongod.h" +#include "mongo/db/ftdc/util.h" #include "mongo/db/global_settings.h" #include "mongo/db/index/index_access_method_factory_impl.h" #include "mongo/db/index_builds_coordinator_mongod.h" @@ -1215,11 +1216,13 @@ void shutdownTask(const ShutdownTaskArgs& shutdownArgs) { repl::ReplicationStateTransitionLockGuard rstl( opCtx, MODE_X, repl::ReplicationStateTransitionLockGuard::EnqueueOnly()); - // Kill all operations. And, makes all newly created opCtx to be immediately interrupted. - // After this point, the opCtx will have been marked as killed and will not be usable other - // than to kill all transactions directly below. + // Kill all operations except FTDC to continue gathering metrics. This makes all newly + // created opCtx to be immediately interrupted. After this point, the opCtx will have been + // marked as killed and will not be usable other than to kill all transactions directly + // below. LOGV2_OPTIONS(4784912, {LogComponent::kDefault}, "Killing all operations for shutdown"); - serviceContext->setKillAllOperations(); + const std::set<std::string> excludedClients = {std::string(kFTDCThreadName)}; + serviceContext->setKillAllOperations(excludedClients); if (MONGO_unlikely(pauseWhileKillingOperationsAtShutdown.shouldFail())) { LOGV2_OPTIONS(4701700, @@ -1323,10 +1326,6 @@ void shutdownTask(const ShutdownTaskArgs& shutdownArgs) { LOGV2(4784925, "Shutting down free monitoring"); stopFreeMonitoring(); - // Shutdown Full-Time Data Capture - LOGV2_OPTIONS(4784926, {LogComponent::kFTDC}, "Shutting down full-time data capture"); - stopMongoDFTDC(); - LOGV2(4784927, "Shutting down the HealthLog"); HealthLog::get(serviceContext).shutdown(); @@ -1356,6 +1355,10 @@ void shutdownTask(const ShutdownTaskArgs& shutdownArgs) { LOGV2_OPTIONS(4784931, {LogComponent::kDefault}, "Dropping the scope cache for shutdown"); ScriptEngine::dropScopeCache(); + // Shutdown Full-Time Data Capture + LOGV2_OPTIONS(4784926, {LogComponent::kFTDC}, "Shutting down full-time data capture"); + stopMongoDFTDC(); + LOGV2(20565, "Now exiting"); audit::logShutdown(client); diff --git a/src/mongo/db/repl/replication_coordinator_impl.cpp b/src/mongo/db/repl/replication_coordinator_impl.cpp index 65676f1704d..e6e14253d46 100644 --- a/src/mongo/db/repl/replication_coordinator_impl.cpp +++ b/src/mongo/db/repl/replication_coordinator_impl.cpp @@ -3000,6 +3000,10 @@ Status ReplicationCoordinatorImpl::processReplSetGetStatus( ReplicationMetrics::get(getServiceContext()).getElectionParticipantMetricsBSON(); stdx::lock_guard<Latch> lk(_mutex); + if (_inShutdown) { + return Status(ErrorCodes::ShutdownInProgress, "shutdown in progress"); + } + Status result(ErrorCodes::InternalError, "didn't set status in prepareStatusResponse"); _topCoord->prepareStatusResponse( TopologyCoordinator::ReplSetStatusArgs{ diff --git a/src/mongo/db/service_context.cpp b/src/mongo/db/service_context.cpp index 4e01b46c3b4..c8a6a6f60bd 100644 --- a/src/mongo/db/service_context.cpp +++ b/src/mongo/db/service_context.cpp @@ -313,7 +313,7 @@ Client* ServiceContext::LockedClientsCursor::next() { return result; } -void ServiceContext::setKillAllOperations() { +void ServiceContext::setKillAllOperations(const std::set<std::string>& excludedClients) { stdx::lock_guard<Latch> clientLock(_mutex); // Ensure that all newly created operation contexts will immediately be in the interrupted state @@ -323,6 +323,12 @@ void ServiceContext::setKillAllOperations() { // Interrupt all active operations for (auto&& client : _clients) { stdx::lock_guard<Client> lk(*client); + + // Do not kill operations from the excluded clients. + if (excludedClients.find(client->desc()) != excludedClients.end()) { + continue; + } + auto opCtxToKill = client->getOperationContext(); if (opCtxToKill) { killOperation(lk, opCtxToKill, ErrorCodes::InterruptedAtShutdown); diff --git a/src/mongo/db/service_context.h b/src/mongo/db/service_context.h index f59d31ddd49..4b4156a78bf 100644 --- a/src/mongo/db/service_context.h +++ b/src/mongo/db/service_context.h @@ -405,9 +405,10 @@ public: // /** - * Signal all OperationContext(s) that they have been killed. + * Signal all OperationContext(s) that they have been killed except the ones belonging to the + * excluded clients. */ - void setKillAllOperations(); + void setKillAllOperations(const std::set<std::string>& excludedClients = {}); /** * Reset the operation kill state after a killAllOperations. diff --git a/src/mongo/db/storage/wiredtiger/oplog_stones_server_status_section.cpp b/src/mongo/db/storage/wiredtiger/oplog_stones_server_status_section.cpp index e92d6b169e2..b496e931afb 100644 --- a/src/mongo/db/storage/wiredtiger/oplog_stones_server_status_section.cpp +++ b/src/mongo/db/storage/wiredtiger/oplog_stones_server_status_section.cpp @@ -27,12 +27,15 @@ * it in the license file. */ +#define MONGO_LOGV2_DEFAULT_COMPONENT ::mongo::logv2::LogComponent::kFTDC + #include "mongo/platform/basic.h" #include "mongo/db/catalog/database_holder.h" #include "mongo/db/commands/server_status.h" #include "mongo/db/db_raii.h" #include "mongo/db/namespace_string.h" +#include "mongo/logv2/log.h" namespace mongo { class OplogStonesServerStatusSection : public ServerStatusSection { @@ -54,6 +57,14 @@ public: if (!opCtx->getServiceContext()->getStorageEngine()->supportsOplogStones()) { return builder.obj(); } + + Lock::GlobalLock lk( + opCtx, LockMode::MODE_IS, Date_t::now(), Lock::InterruptBehavior::kLeaveUnlocked); + if (!lk.isLocked()) { + LOGV2_DEBUG(4822100, 2, "Failed to retrieve oplogTruncation statistics"); + return BSONObj(); + } + AutoGetOplog oplogRead(opCtx, OplogAccessMode::kRead); const auto& oplog = oplogRead.getCollection(); if (oplog) { |