summaryrefslogtreecommitdiff
path: root/src/mongo/db/mongod_main.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/mongo/db/mongod_main.cpp')
-rw-r--r--src/mongo/db/mongod_main.cpp477
1 files changed, 88 insertions, 389 deletions
diff --git a/src/mongo/db/mongod_main.cpp b/src/mongo/db/mongod_main.cpp
index 4f46f4ceb71..52a9c4651d6 100644
--- a/src/mongo/db/mongod_main.cpp
+++ b/src/mongo/db/mongod_main.cpp
@@ -74,6 +74,7 @@
#include "mongo/db/concurrency/flow_control_ticketholder.h"
#include "mongo/db/concurrency/lock_state.h"
#include "mongo/db/concurrency/replication_state_transition_lock_guard.h"
+#include "mongo/db/concurrency/write_conflict_exception.h"
#include "mongo/db/db_raii.h"
#include "mongo/db/dbdirectclient.h"
#include "mongo/db/dbhelpers.h"
@@ -81,9 +82,11 @@
#include "mongo/db/exec/working_set_common.h"
#include "mongo/db/fcv_op_observer.h"
#include "mongo/db/fle_crud.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"
#include "mongo/db/index_names.h"
#include "mongo/db/initialize_server_global_state.h"
@@ -102,7 +105,6 @@
#include "mongo/db/logical_time_validator.h"
#include "mongo/db/mirror_maestro.h"
#include "mongo/db/mongod_options.h"
-#include "mongo/db/mongod_options_storage_gen.h"
#include "mongo/db/namespace_string.h"
#include "mongo/db/op_observer_impl.h"
#include "mongo/db/op_observer_registry.h"
@@ -232,10 +234,6 @@
#include <sys/file.h>
#endif
-#ifdef __linux__
-#include <sys/prctl.h>
-#endif
-
namespace mongo {
using logv2::LogComponent;
@@ -351,38 +349,11 @@ void registerPrimaryOnlyServices(ServiceContext* serviceContext) {
MONGO_FAIL_POINT_DEFINE(shutdownAtStartup);
-void logMongodStartupTimeElapsedStatistics(ServiceContext* serviceContext,
- Date_t beginInitAndListen,
- BSONObjBuilder* startupTimeElapsedBuilder,
- BSONObjBuilder* startupInfoBuilder,
- StorageEngine::LastShutdownState lastShutdownState) {
- mongo::Milliseconds elapsedInitAndListen =
- serviceContext->getFastClockSource()->now() - beginInitAndListen;
- startupTimeElapsedBuilder->append("_initAndListen total elapsed time",
- elapsedInitAndListen.toString());
- startupInfoBuilder->append("Startup from clean shutdown?",
- lastShutdownState == StorageEngine::LastShutdownState::kClean);
- startupInfoBuilder->append("Statistics", startupTimeElapsedBuilder->obj());
- LOGV2_INFO(8423403,
- "mongod startup complete",
- "Summary of time elapsed"_attr = startupInfoBuilder->obj());
-}
-
-// Important:
-// _initAndListen among its other tasks initializes the storage subsystem.
-// File Copy Based Initial Sync will restart the storage subsystem and may need to repeat some
-// of the initialization steps within. If you add or change any of these steps, make sure
-// any necessary changes are also made to File Copy Based Initial Sync.
ExitCode _initAndListen(ServiceContext* serviceContext, int listenPort) {
Client::initThread("initandlisten");
serviceContext->setFastClockSource(FastClockSourceFactory::create(Milliseconds(10)));
- BSONObjBuilder startupTimeElapsedBuilder;
- BSONObjBuilder startupInfoBuilder;
-
- Date_t beginInitAndListen = serviceContext->getFastClockSource()->now();
-
DBDirectClientFactory::get(serviceContext).registerImplementation([](OperationContext* opCtx) {
return std::unique_ptr<DBClientBase>(new DBDirectClient(opCtx));
});
@@ -426,9 +397,6 @@ ExitCode _initAndListen(ServiceContext* serviceContext, int listenPort) {
#endif
if (!storageGlobalParams.repair) {
- TimeElapsedBuilderScopedTimer scopedTimer(serviceContext->getFastClockSource(),
- "Transport layer setup",
- &startupTimeElapsedBuilder);
auto tl =
transport::TransportLayerManager::createWithConfig(&serverGlobalParams, serviceContext);
auto res = tl->setup();
@@ -447,34 +415,16 @@ ExitCode _initAndListen(ServiceContext* serviceContext, int listenPort) {
serviceContext, repl::ReplicationCoordinator::get(serviceContext)));
// If a crash occurred during file-copy based initial sync, we may need to finish or clean up.
- {
- TimeElapsedBuilderScopedTimer scopedTimer(serviceContext->getFastClockSource(),
- "Run initial syncer crash recovery",
- &startupTimeElapsedBuilder);
- repl::InitialSyncerFactory::get(serviceContext)->runCrashRecovery();
- }
+ repl::InitialSyncerFactory::get(serviceContext)->runCrashRecovery();
// Creating the operation context before initializing the storage engine allows the storage
// engine initialization to make use of the lock manager. As the storage engine is not yet
// initialized, a noop recovery unit is used until the initialization is complete.
auto startupOpCtx = serviceContext->makeOperationContext(&cc());
- auto lastShutdownState = initializeStorageEngine(
- startupOpCtx.get(), StorageEngineInitFlags{}, &startupTimeElapsedBuilder);
+ auto lastShutdownState = initializeStorageEngine(startupOpCtx.get(), StorageEngineInitFlags{});
StorageControl::startStorageControls(serviceContext);
- ScopeGuard logStartupStats([serviceContext,
- beginInitAndListen,
- &startupTimeElapsedBuilder,
- &startupInfoBuilder,
- lastShutdownState] {
- logMongodStartupTimeElapsedStatistics(serviceContext,
- beginInitAndListen,
- &startupTimeElapsedBuilder,
- &startupInfoBuilder,
- lastShutdownState);
- });
-
#ifdef MONGO_CONFIG_WIREDTIGER_ENABLED
if (EncryptionHooks::get(serviceContext)->restartRequired()) {
exitCleanly(EXIT_CLEAN);
@@ -533,12 +483,6 @@ ExitCode _initAndListen(ServiceContext* serviceContext, int listenPort) {
exitCleanly(EXIT_BADOPTIONS);
}
- if (gAllowDocumentsGreaterThanMaxUserSize && replSettings.usingReplSets()) {
- LOGV2_ERROR(8472200,
- "allowDocumentsGreaterThanMaxUserSize can only be used in standalone mode");
- exitCleanly(EXIT_BADOPTIONS);
- }
-
logMongodStartupWarnings(storageGlobalParams, serverGlobalParams, serviceContext);
{
@@ -555,8 +499,7 @@ ExitCode _initAndListen(ServiceContext* serviceContext, int listenPort) {
startWatchdog(serviceContext);
try {
- startup_recovery::repairAndRecoverDatabases(
- startupOpCtx.get(), lastShutdownState, &startupTimeElapsedBuilder);
+ startup_recovery::repairAndRecoverDatabases(startupOpCtx.get(), lastShutdownState);
} catch (const ExceptionFor<ErrorCodes::MustDowngrade>& error) {
LOGV2_FATAL_OPTIONS(
20573,
@@ -602,16 +545,10 @@ ExitCode _initAndListen(ServiceContext* serviceContext, int listenPort) {
}
// Start up health log writer thread.
- HealthLogInterface::set(serviceContext, std::make_unique<HealthLog>());
- HealthLogInterface::get(startupOpCtx.get())->startup();
+ HealthLog::get(startupOpCtx.get()).startup();
auto const globalAuthzManager = AuthorizationManager::get(serviceContext);
- {
- TimeElapsedBuilderScopedTimer scopedTimer(serviceContext->getFastClockSource(),
- "Build user and roles graph",
- &startupTimeElapsedBuilder);
- uassertStatusOK(globalAuthzManager->initialize(startupOpCtx.get()));
- }
+ uassertStatusOK(globalAuthzManager->initialize(startupOpCtx.get()));
if (audit::initializeManager) {
audit::initializeManager(startupOpCtx.get());
@@ -621,7 +558,7 @@ ExitCode _initAndListen(ServiceContext* serviceContext, int listenPort) {
srand((unsigned)(curTimeMicros64()) ^ (unsigned(uintptr_t(&startupOpCtx))));
if (globalAuthzManager->shouldValidateAuthSchemaOnStartup()) {
- Status status = verifySystemIndexes(startupOpCtx.get(), &startupTimeElapsedBuilder);
+ Status status = verifySystemIndexes(startupOpCtx.get());
if (!status.isOK()) {
LOGV2_WARNING(20538,
"Unable to verify system indexes: {error}",
@@ -682,14 +619,7 @@ ExitCode _initAndListen(ServiceContext* serviceContext, int listenPort) {
"** This mode should only be used to manually repair corrupted auth data");
}
- {
- TimeElapsedBuilderScopedTimer scopedTimer(
- serviceContext->getFastClockSource(),
- "Set up the background thread pool responsible for "
- "waiting for opTimes to be majority committed",
- &startupTimeElapsedBuilder);
- WaitForMajorityService::get(serviceContext).startup(serviceContext);
- }
+ WaitForMajorityService::get(serviceContext).startup(serviceContext);
// This function may take the global lock.
auto shardingInitialized = ShardingInitializationMongoD::get(startupOpCtx.get())
@@ -715,7 +645,7 @@ ExitCode _initAndListen(ServiceContext* serviceContext, int listenPort) {
"Error loading read and write concern defaults at startup",
"error"_attr = redact(ex));
}
- readWriteConcernDefaultsMongodStartupChecks(startupOpCtx.get(), replSettings.usingReplSets());
+ readWriteConcernDefaultsMongodStartupChecks(startupOpCtx.get());
// Perform replication recovery for queryable backup mode if needed.
if (storageGlobalParams.readOnly) {
@@ -738,10 +668,6 @@ ExitCode _initAndListen(ServiceContext* serviceContext, int listenPort) {
uassert(ErrorCodes::BadValue,
str::stream() << "Cannot use queryableBackupMode in a replica set",
!replCoord->isReplEnabled());
- TimeElapsedBuilderScopedTimer scopedTimer(
- serviceContext->getFastClockSource(),
- "Start up the replication coordinator for queryable backup mode",
- &startupTimeElapsedBuilder);
replCoord->startup(startupOpCtx.get(), lastShutdownState);
}
@@ -751,6 +677,8 @@ ExitCode _initAndListen(ServiceContext* serviceContext, int listenPort) {
logStartup(startupOpCtx.get());
}
+ startFreeMonitoring(serviceContext);
+
auto replCoord = repl::ReplicationCoordinator::get(startupOpCtx.get());
invariant(replCoord);
@@ -762,11 +690,6 @@ ExitCode _initAndListen(ServiceContext* serviceContext, int listenPort) {
}
}
} else if (serverGlobalParams.clusterRole == ClusterRole::ConfigServer) {
- TimeElapsedBuilderScopedTimer scopedTimer(
- serviceContext->getFastClockSource(),
- "Initialize the sharding components for a config server",
- &startupTimeElapsedBuilder);
-
initializeGlobalShardingStateForMongoD(
startupOpCtx.get(), ShardId::kConfigServerId, ConnectionString::forLocal());
@@ -775,22 +698,7 @@ ExitCode _initAndListen(ServiceContext* serviceContext, int listenPort) {
makeShardingTaskExecutor(executor::makeNetworkInterface("AddShard-TaskExecutor")));
Grid::get(startupOpCtx.get())->setShardingInitialized();
- }
-
- if (replSettings.usingReplSets() &&
- (serverGlobalParams.clusterRole == ClusterRole::None ||
- !Grid::get(startupOpCtx.get())->isShardingInitialized())) {
- // If this is a mongod in a standalone replica set or a shardsvr replica set that has
- // not initialized its sharding identity, start up the cluster time keys manager with a
- // local/direct keys client. The keys client must use local read concern if the storage
- // engine can't support majority read concern. If this is a mongod in a configsvr or
- // shardsvr replica set that has initialized its sharding identity, the keys manager is
- // by design initialized separately with a sharded keys client when the sharding state
- // is initialized.
- TimeElapsedBuilderScopedTimer scopedTimer(
- serviceContext->getFastClockSource(),
- "Start up cluster time keys manager with a local/direct keys client",
- &startupTimeElapsedBuilder);
+ } else if (replSettings.usingReplSets()) { // standalone replica set
auto keysCollectionClient = std::make_unique<KeysCollectionClientDirect>();
auto keyManager = std::make_shared<KeysCollectionManager>(
KeysCollectionManager::kKeyManagerPurposeString,
@@ -800,19 +708,11 @@ ExitCode _initAndListen(ServiceContext* serviceContext, int listenPort) {
LogicalTimeValidator::set(startupOpCtx->getServiceContext(),
std::make_unique<LogicalTimeValidator>(keyManager));
- }
- if (replSettings.usingReplSets() && serverGlobalParams.clusterRole == ClusterRole::None) {
ReplicaSetNodeProcessInterface::getReplicaSetNodeExecutor(serviceContext)->startup();
}
- {
- TimeElapsedBuilderScopedTimer scopedTimer(serviceContext->getFastClockSource(),
- "Start up the replication coordinator",
- &startupTimeElapsedBuilder);
- replCoord->startup(startupOpCtx.get(), lastShutdownState);
- }
-
+ replCoord->startup(startupOpCtx.get(), lastShutdownState);
// 'getOldestActiveTimestamp', which is called in the background by the checkpoint thread,
// requires a read on 'config.transactions' at the stableTimestamp. If this read occurs
// while applying prepared transactions at the end of replication recovery, it's possible to
@@ -843,9 +743,6 @@ ExitCode _initAndListen(ServiceContext* serviceContext, int listenPort) {
}
if (replSettings.usingReplSets()) {
- TimeElapsedBuilderScopedTimer scopedTimer(serviceContext->getFastClockSource(),
- "Create an oplog view for tenant migrations",
- &startupTimeElapsedBuilder);
Lock::GlobalWrite lk(startupOpCtx.get());
OldClientContext ctx(startupOpCtx.get(), NamespaceString::kRsOplogNamespace.ns());
tenant_migration_util::createOplogViewForTenantMigrations(startupOpCtx.get(), ctx.db());
@@ -876,14 +773,6 @@ ExitCode _initAndListen(ServiceContext* serviceContext, int listenPort) {
LOGV2_WARNING(4747501, "Not starting periodic jobs as shutdown is in progress");
// Shutdown has already started before initialization is complete. Wait for the
// shutdown task to complete and return.
-
- logStartupStats.dismiss();
- logMongodStartupTimeElapsedStatistics(serviceContext,
- beginInitAndListen,
- &startupTimeElapsedBuilder,
- &startupInfoBuilder,
- lastShutdownState);
-
MONGO_IDLE_THREAD_BLOCK;
return waitForShutdown();
}
@@ -926,9 +815,6 @@ ExitCode _initAndListen(ServiceContext* serviceContext, int listenPort) {
}
if (!storageGlobalParams.repair) {
- TimeElapsedBuilderScopedTimer scopedTimer(serviceContext->getFastClockSource(),
- "Start transport layer",
- &startupTimeElapsedBuilder);
start = serviceContext->getTransportLayer()->start();
if (!start.isOK()) {
LOGV2_ERROR(20572,
@@ -955,13 +841,6 @@ ExitCode _initAndListen(ServiceContext* serviceContext, int listenPort) {
exitCleanly(EXIT_CLEAN);
}
- logStartupStats.dismiss();
- logMongodStartupTimeElapsedStatistics(serviceContext,
- beginInitAndListen,
- &startupTimeElapsedBuilder,
- &startupInfoBuilder,
- lastShutdownState);
-
MONGO_IDLE_THREAD_BLOCK;
return waitForShutdown();
}
@@ -1136,6 +1015,7 @@ void setUpCollectionShardingState(ServiceContext* serviceContext) {
void setUpCatalog(ServiceContext* serviceContext) {
DatabaseHolder::set(serviceContext, std::make_unique<DatabaseHolderImpl>());
+ IndexAccessMethodFactory::set(serviceContext, std::make_unique<IndexAccessMethodFactoryImpl>());
Collection::Factory::set(serviceContext, std::make_unique<CollectionImpl::FactoryImpl>());
}
@@ -1251,6 +1131,8 @@ void setUpObservers(ServiceContext* serviceContext) {
opObserverRegistry->addObserver(std::make_unique<ClusterServerParameterOpObserver>());
}
+ setupFreeMonitoringOpObserver(opObserverRegistry.get());
+
if (audit::opObserverRegistrar) {
audit::opObserverRegistrar(opObserverRegistry.get());
}
@@ -1269,20 +1151,6 @@ MONGO_INITIALIZER_GENERAL(setSSLManagerType, (), ("SSLManager"))
#define __has_feature(x) 0
#endif
-void logShutdownTimeElapsedStatistics(ServiceContext* serviceContext,
- Date_t beginShutdownTask,
- BSONObjBuilder* shutdownTimeElapsedBuilder,
- BSONObjBuilder* shutdownInfoBuilder) {
- mongo::Milliseconds elapsedInitAndListen =
- serviceContext->getFastClockSource()->now() - beginShutdownTask;
- shutdownTimeElapsedBuilder->append("shutdownTask total elapsed time",
- elapsedInitAndListen.toString());
- shutdownInfoBuilder->append("Statistics", shutdownTimeElapsedBuilder->obj());
- LOGV2_INFO(8423404,
- "mongod shutdown complete",
- "Summary of time elapsed"_attr = shutdownInfoBuilder->obj());
-}
-
// NOTE: This function may be called at any time after registerShutdownTask is called below. It
// must not depend on the prior execution of mongo initializers or the existence of threads.
void shutdownTask(const ShutdownTaskArgs& shutdownArgs) {
@@ -1307,40 +1175,20 @@ void shutdownTask(const ShutdownTaskArgs& shutdownArgs) {
hangBeforeShutdown.pauseWhileSet();
}
- BSONObjBuilder shutdownTimeElapsedBuilder;
- BSONObjBuilder shutdownInfoBuilder;
-
- Date_t beginShutdownTask = serviceContext->getFastClockSource()->now();
- ScopeGuard logShutdownStats(
- [serviceContext, beginShutdownTask, &shutdownTimeElapsedBuilder, &shutdownInfoBuilder] {
- logShutdownTimeElapsedStatistics(serviceContext,
- beginShutdownTask,
- &shutdownTimeElapsedBuilder,
- &shutdownInfoBuilder);
- });
-
// If we don't have shutdownArgs, we're shutting down from a signal, or other clean shutdown
// path.
//
// In that case, do a default step down, still shutting down if stepDown fails.
if (auto replCoord = repl::ReplicationCoordinator::get(serviceContext);
replCoord && !shutdownArgs.isUserInitiated) {
- {
- TimeElapsedBuilderScopedTimer scopedTimer(serviceContext->getFastClockSource(),
- "Enter terminal shutdown",
- &shutdownTimeElapsedBuilder);
- replCoord->enterTerminalShutdown();
- }
+ replCoord->enterTerminalShutdown();
ServiceContext::UniqueOperationContext uniqueOpCtx;
OperationContext* opCtx = client->getOperationContext();
if (!opCtx) {
uniqueOpCtx = client->makeOperationContext();
opCtx = uniqueOpCtx.get();
}
- TimeElapsedBuilderScopedTimer scopedTimer(
- serviceContext->getFastClockSource(),
- "Step down the replication coordinator for shutdown",
- &shutdownTimeElapsedBuilder);
+
const auto forceShutdown = true;
auto stepDownStartTime = opCtx->getServiceContext()->getPreciseClockSource()->now();
// stepDown should never return an error during force shutdown.
@@ -1355,104 +1203,62 @@ void shutdownTask(const ShutdownTaskArgs& shutdownArgs) {
(opCtx->getServiceContext()->getPreciseClockSource()->now() - stepDownStartTime));
}
- {
- TimeElapsedBuilderScopedTimer scopedTimer(serviceContext->getFastClockSource(),
- "Time spent in quiesce mode",
- &shutdownTimeElapsedBuilder);
- if (auto replCoord = repl::ReplicationCoordinator::get(serviceContext);
- replCoord && replCoord->enterQuiesceModeIfSecondary(shutdownTimeout)) {
- ServiceContext::UniqueOperationContext uniqueOpCtx;
- OperationContext* opCtx = client->getOperationContext();
- if (!opCtx) {
- uniqueOpCtx = client->makeOperationContext();
- opCtx = uniqueOpCtx.get();
- }
- if (MONGO_unlikely(hangDuringQuiesceMode.shouldFail())) {
- LOGV2_OPTIONS(4695101,
- {LogComponent::kReplication},
- "hangDuringQuiesceMode failpoint enabled");
- hangDuringQuiesceMode.pauseWhileSet(opCtx);
- }
-
- LOGV2_OPTIONS(4695102,
- {LogComponent::kReplication},
- "Entering quiesce mode for shutdown",
- "quiesceTime"_attr = shutdownTimeout);
- opCtx->sleepFor(shutdownTimeout);
+ if (auto replCoord = repl::ReplicationCoordinator::get(serviceContext);
+ replCoord && replCoord->enterQuiesceModeIfSecondary(shutdownTimeout)) {
+ ServiceContext::UniqueOperationContext uniqueOpCtx;
+ OperationContext* opCtx = client->getOperationContext();
+ if (!opCtx) {
+ uniqueOpCtx = client->makeOperationContext();
+ opCtx = uniqueOpCtx.get();
+ }
+ if (MONGO_unlikely(hangDuringQuiesceMode.shouldFail())) {
LOGV2_OPTIONS(
- 4695103, {LogComponent::kReplication}, "Exiting quiesce mode for shutdown");
+ 4695101, {LogComponent::kReplication}, "hangDuringQuiesceMode failpoint enabled");
+ hangDuringQuiesceMode.pauseWhileSet(opCtx);
}
- }
-
- {
- TimeElapsedBuilderScopedTimer scopedTimer(serviceContext->getFastClockSource(),
- "Shut down FLE Crud subsystem",
- &shutdownTimeElapsedBuilder);
- LOGV2_OPTIONS(6371601, {LogComponent::kDefault}, "Shutting down the FLE Crud thread pool");
- stopFLECrud();
+ LOGV2_OPTIONS(4695102,
+ {LogComponent::kReplication},
+ "Entering quiesce mode for shutdown",
+ "quiesceTime"_attr = shutdownTimeout);
+ opCtx->sleepFor(shutdownTimeout);
+ LOGV2_OPTIONS(4695103, {LogComponent::kReplication}, "Exiting quiesce mode for shutdown");
}
- {
- TimeElapsedBuilderScopedTimer scopedTimer(serviceContext->getFastClockSource(),
- "Shut down MirrorMaestro",
- &shutdownTimeElapsedBuilder);
- LOGV2_OPTIONS(4784901, {LogComponent::kCommand}, "Shutting down the MirrorMaestro");
- MirrorMaestro::shutdown(serviceContext);
- }
+ LOGV2_OPTIONS(6371601, {LogComponent::kDefault}, "Shutting down the FLE Crud thread pool");
+ stopFLECrud();
- {
- TimeElapsedBuilderScopedTimer scopedTimer(serviceContext->getFastClockSource(),
- "Shut down WaitForMajorityService",
- &shutdownTimeElapsedBuilder);
- LOGV2_OPTIONS(
- 4784902, {LogComponent::kSharding}, "Shutting down the WaitForMajorityService");
- WaitForMajorityService::get(serviceContext).shutDown();
- }
+ LOGV2_OPTIONS(4784901, {LogComponent::kCommand}, "Shutting down the MirrorMaestro");
+ MirrorMaestro::shutdown(serviceContext);
+
+ LOGV2_OPTIONS(4784902, {LogComponent::kSharding}, "Shutting down the WaitForMajorityService");
+ WaitForMajorityService::get(serviceContext).shutDown();
// Join the logical session cache before the transport layer.
if (auto lsc = LogicalSessionCache::get(serviceContext)) {
- TimeElapsedBuilderScopedTimer scopedTimer(serviceContext->getFastClockSource(),
- "Shut down the logical session cache",
- &shutdownTimeElapsedBuilder);
LOGV2(4784903, "Shutting down the LogicalSessionCache");
lsc->joinOnShutDown();
}
// Shutdown the TransportLayer so that new connections aren't accepted
if (auto tl = serviceContext->getTransportLayer()) {
- TimeElapsedBuilderScopedTimer scopedTimer(serviceContext->getFastClockSource(),
- "Shut down the transport layer",
- &shutdownTimeElapsedBuilder);
LOGV2_OPTIONS(
20562, {LogComponent::kNetwork}, "Shutdown: going to close listening sockets");
tl->shutdown();
}
// Shut down the global dbclient pool so callers stop waiting for connections.
- {
- TimeElapsedBuilderScopedTimer scopedTimer(serviceContext->getFastClockSource(),
- "Shut down the global connection pool",
- &shutdownTimeElapsedBuilder);
- LOGV2_OPTIONS(
- 4784905, {LogComponent::kNetwork}, "Shutting down the global connection pool");
- globalConnPool.shutdown();
- }
+ LOGV2_OPTIONS(4784905, {LogComponent::kNetwork}, "Shutting down the global connection pool");
+ globalConnPool.shutdown();
// Inform Flow Control to stop gating writes on ticket admission. This must be done before the
// Periodic Runner is shut down (see SERVER-41751).
if (auto flowControlTicketholder = FlowControlTicketholder::get(serviceContext)) {
- TimeElapsedBuilderScopedTimer scopedTimer(serviceContext->getFastClockSource(),
- "Shut down the flow control ticket holder",
- &shutdownTimeElapsedBuilder);
LOGV2(4784906, "Shutting down the FlowControlTicketholder");
flowControlTicketholder->setInShutdown();
}
if (auto exec = ReplicaSetNodeProcessInterface::getReplicaSetNodeExecutor(serviceContext)) {
- TimeElapsedBuilderScopedTimer scopedTimer(serviceContext->getFastClockSource(),
- "Shut down the replica set node executor",
- &shutdownTimeElapsedBuilder);
LOGV2_OPTIONS(
4784907, {LogComponent::kReplication}, "Shutting down the replica set node executor");
exec->shutdown();
@@ -1471,23 +1277,16 @@ void shutdownTask(const ShutdownTaskArgs& shutdownArgs) {
uniqueOpCtx = client->makeOperationContext();
opCtx = uniqueOpCtx.get();
}
- {
- stdx::lock_guard lg(*client);
- opCtx->setIsExecutingShutdown();
- }
+ opCtx->setIsExecutingShutdown();
// This can wait a long time while we drain the secondary's apply queue, especially if
// it is building an index.
LOGV2_OPTIONS(
4784909, {LogComponent::kReplication}, "Shutting down the ReplicationCoordinator");
- repl::ReplicationCoordinator::get(serviceContext)
- ->shutdown(opCtx, &shutdownTimeElapsedBuilder);
+ repl::ReplicationCoordinator::get(serviceContext)->shutdown(opCtx);
// Terminate the index consistency check.
if (serverGlobalParams.clusterRole == ClusterRole::ConfigServer) {
- TimeElapsedBuilderScopedTimer scopedTimer(serviceContext->getFastClockSource(),
- "Shut down the index consistency checker",
- &shutdownTimeElapsedBuilder);
LOGV2_OPTIONS(4784904,
{LogComponent::kSharding},
"Shutting down the PeriodicShardedIndexConsistencyChecker");
@@ -1512,53 +1311,32 @@ void shutdownTask(const ShutdownTaskArgs& shutdownArgs) {
// 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");
- {
- const std::set<std::string> excludedClients = {std::string(kFTDCThreadName)};
- TimeElapsedBuilderScopedTimer scopedTimer(serviceContext->getFastClockSource(),
- "Kill all operations for shutdown",
- &shutdownTimeElapsedBuilder);
- serviceContext->setKillAllOperations(excludedClients);
-
- if (MONGO_unlikely(pauseWhileKillingOperationsAtShutdown.shouldFail())) {
- LOGV2_OPTIONS(4701700,
- {LogComponent::kDefault},
- "pauseWhileKillingOperationsAtShutdown failpoint enabled");
- sleepsecs(1);
- }
- }
-
- {
- // Clear tenant migration access blockers after killing all operation contexts to ensure
- // that no operation context cancellation token continuation holds the last reference to
- // the TenantMigrationAccessBlockerExecutor.
- TimeElapsedBuilderScopedTimer scopedTimer(
- serviceContext->getFastClockSource(),
- "Shut down all tenant migration access blockers on global shutdown",
- &shutdownTimeElapsedBuilder);
- LOGV2_OPTIONS(5093807,
- {LogComponent::kTenantMigration},
- "Shutting down all TenantMigrationAccessBlockers on global shutdown");
- TenantMigrationAccessBlockerRegistry::get(serviceContext).shutDown();
+ const std::set<std::string> excludedClients = {std::string(kFTDCThreadName)};
+ serviceContext->setKillAllOperations(excludedClients);
+
+ // Clear tenant migration access blockers after killing all operation contexts to ensure
+ // that no operation context cancellation token continuation holds the last reference to the
+ // TenantMigrationAccessBlockerExecutor.
+ LOGV2_OPTIONS(5093807,
+ {LogComponent::kTenantMigration},
+ "Shutting down all TenantMigrationAccessBlockers on global shutdown");
+ TenantMigrationAccessBlockerRegistry::get(serviceContext).shutDown();
+
+ if (MONGO_unlikely(pauseWhileKillingOperationsAtShutdown.shouldFail())) {
+ LOGV2_OPTIONS(4701700,
+ {LogComponent::kDefault},
+ "pauseWhileKillingOperationsAtShutdown failpoint enabled");
+ sleepsecs(1);
}
// Destroy all stashed transaction resources, in order to release locks.
- {
- TimeElapsedBuilderScopedTimer scopedTimer(serviceContext->getFastClockSource(),
- "Shut down all open transactions",
- &shutdownTimeElapsedBuilder);
- LOGV2_OPTIONS(4784913, {LogComponent::kCommand}, "Shutting down all open transactions");
- killSessionsLocalShutdownAllTransactions(opCtx);
- }
+ LOGV2_OPTIONS(4784913, {LogComponent::kCommand}, "Shutting down all open transactions");
+ killSessionsLocalShutdownAllTransactions(opCtx);
- {
- TimeElapsedBuilderScopedTimer scopedTimer(serviceContext->getFastClockSource(),
- "Acquire the RSTL for shutdown",
- &shutdownTimeElapsedBuilder);
- LOGV2_OPTIONS(4784914,
- {LogComponent::kReplication},
- "Acquiring the ReplicationStateTransitionLock for shutdown");
- rstl.waitForLockUntil(Date_t::max());
- }
+ LOGV2_OPTIONS(4784914,
+ {LogComponent::kReplication},
+ "Acquiring the ReplicationStateTransitionLock for shutdown");
+ rstl.waitForLockUntil(Date_t::max());
// Release the rstl before waiting for the index build threads to join as index build
// reacquires rstl in uninterruptible lock guard to finish their cleanup process.
@@ -1566,83 +1344,38 @@ void shutdownTask(const ShutdownTaskArgs& shutdownArgs) {
// Shuts down the thread pool and waits for index builds to finish.
// Depends on setKillAllOperations() above to interrupt the index build operations.
- {
- TimeElapsedBuilderScopedTimer scopedTimer(
- serviceContext->getFastClockSource(),
- "Shut down the IndexBuildsCoordinator and wait for index builds to finish",
- &shutdownTimeElapsedBuilder);
- LOGV2_OPTIONS(
- 4784915, {LogComponent::kIndex}, "Shutting down the IndexBuildsCoordinator");
- IndexBuildsCoordinator::get(serviceContext)->shutdown(opCtx);
- }
+ LOGV2_OPTIONS(4784915, {LogComponent::kIndex}, "Shutting down the IndexBuildsCoordinator");
+ IndexBuildsCoordinator::get(serviceContext)->shutdown(opCtx);
}
- {
- TimeElapsedBuilderScopedTimer scopedTimer(serviceContext->getFastClockSource(),
- "Shut down the replica set monitor",
- &shutdownTimeElapsedBuilder);
- LOGV2_OPTIONS(4784918, {LogComponent::kNetwork}, "Shutting down the ReplicaSetMonitor");
- ReplicaSetMonitor::shutdown();
- }
+ LOGV2_OPTIONS(4784918, {LogComponent::kNetwork}, "Shutting down the ReplicaSetMonitor");
+ ReplicaSetMonitor::shutdown();
if (auto sr = Grid::get(serviceContext)->shardRegistry()) {
- TimeElapsedBuilderScopedTimer scopedTimer(serviceContext->getFastClockSource(),
- "Shut down the shard registry",
- &shutdownTimeElapsedBuilder);
LOGV2_OPTIONS(4784919, {LogComponent::kSharding}, "Shutting down the shard registry");
sr->shutdown();
}
if (ShardingState::get(serviceContext)->enabled()) {
- TimeElapsedBuilderScopedTimer scopedTimer(serviceContext->getFastClockSource(),
- "Shut down the transaction coordinator service",
- &shutdownTimeElapsedBuilder);
TransactionCoordinatorService::get(serviceContext)->shutdown();
}
// Validator shutdown must be called after setKillAllOperations is called. Otherwise, this can
// deadlock.
if (auto validator = LogicalTimeValidator::get(serviceContext)) {
- TimeElapsedBuilderScopedTimer scopedTimer(serviceContext->getFastClockSource(),
- "Shut down the logical time validator",
- &shutdownTimeElapsedBuilder);
LOGV2_OPTIONS(
4784920, {LogComponent::kReplication}, "Shutting down the LogicalTimeValidator");
validator->shutDown();
}
- if (TestingProctor::instance().isEnabled()) {
- if (auto pool = Grid::get(serviceContext)->getExecutorPool()) {
- TimeElapsedBuilderScopedTimer scopedTimer(serviceContext->getFastClockSource(),
- "Shut down the executor pool",
- &shutdownTimeElapsedBuilder);
- LOGV2_OPTIONS(6773200, {LogComponent::kSharding}, "Shutting down the ExecutorPool");
- pool->shutdownAndJoin();
- }
- }
-
// The migrationutil executor must be shut down before shutting down the CatalogCacheLoader.
// Otherwise, it may try to schedule work on the CatalogCacheLoader and fail.
LOGV2_OPTIONS(4784921, {LogComponent::kSharding}, "Shutting down the MigrationUtilExecutor");
auto migrationUtilExecutor = migrationutil::getMigrationUtilExecutor(serviceContext);
- {
- TimeElapsedBuilderScopedTimer scopedTimer(serviceContext->getFastClockSource(),
- "Shut down the migration util executor",
- &shutdownTimeElapsedBuilder);
- migrationUtilExecutor->shutdown();
- migrationUtilExecutor->join();
- }
-
- if (Grid::get(serviceContext)->isShardingInitialized()) {
- // The CatalogCache must be shuted down before shutting down the CatalogCacheLoader as the
- // CatalogCache may try to schedule work on CatalogCacheLoader and fail.
- TimeElapsedBuilderScopedTimer scopedTimer(
- serviceContext->getFastClockSource(),
- "Shut down the catalog cache and catalog cache loader",
- &shutdownTimeElapsedBuilder);
- LOGV2_OPTIONS(6773201, {LogComponent::kSharding}, "Shutting down the CatalogCache");
- Grid::get(serviceContext)->catalogCache()->shutDownAndJoin();
+ migrationUtilExecutor->shutdown();
+ migrationUtilExecutor->join();
+ if (ShardingState::get(serviceContext)->enabled()) {
LOGV2_OPTIONS(4784922, {LogComponent::kSharding}, "Shutting down the CatalogCacheLoader");
CatalogCacheLoader::get(serviceContext).shutDown();
}
@@ -1650,36 +1383,24 @@ void shutdownTask(const ShutdownTaskArgs& shutdownArgs) {
// Shutdown the Service Entry Point and its sessions and give it a grace period to complete.
if (auto sep = serviceContext->getServiceEntryPoint()) {
LOGV2_OPTIONS(4784923, {LogComponent::kCommand}, "Shutting down the ServiceEntryPoint");
- if (!sep->shutdown(Seconds(30))) {
+ if (!sep->shutdown(Seconds(10))) {
LOGV2_OPTIONS(20563,
{LogComponent::kNetwork},
"Service entry point did not shutdown within the time limit");
}
}
- if (auto* healthLog = HealthLogInterface::get(serviceContext)) {
- TimeElapsedBuilderScopedTimer scopedTimer(serviceContext->getFastClockSource(),
- "Shut down the health log",
- &shutdownTimeElapsedBuilder);
- LOGV2(4784927, "Shutting down the HealthLog");
- healthLog->shutdown();
- }
+ LOGV2(4784925, "Shutting down free monitoring");
+ stopFreeMonitoring();
- {
- TimeElapsedBuilderScopedTimer scopedTimer(serviceContext->getFastClockSource(),
- "Shut down the TTL monitor",
- &shutdownTimeElapsedBuilder);
- LOGV2(4784928, "Shutting down the TTL monitor");
- shutdownTTLMonitor(serviceContext);
- }
+ LOGV2(4784927, "Shutting down the HealthLog");
+ HealthLog::get(serviceContext).shutdown();
- {
- TimeElapsedBuilderScopedTimer scopedTimer(serviceContext->getFastClockSource(),
- "Shut down expired pre-images remover",
- &shutdownTimeElapsedBuilder);
- LOGV2(6278511, "Shutting down the Change Stream Expired Pre-images Remover");
- shutdownChangeStreamExpiredPreImagesRemover(serviceContext);
- }
+ LOGV2(4784928, "Shutting down the TTL monitor");
+ shutdownTTLMonitor(serviceContext);
+
+ LOGV2(6278511, "Shutting down the Change Stream Expired Pre-images Remover");
+ shutdownChangeStreamExpiredPreImagesRemover(serviceContext);
// We should always be able to acquire the global lock at shutdown.
// An OperationContext is not necessary to call lockGlobal() during shutdown, as it's only used
@@ -1694,9 +1415,6 @@ void shutdownTask(const ShutdownTaskArgs& shutdownArgs) {
// Global storage engine may not be started in all cases before we exit
if (serviceContext->getStorageEngine()) {
- TimeElapsedBuilderScopedTimer scopedTimer(serviceContext->getFastClockSource(),
- "Shut down the storage engine",
- &shutdownTimeElapsedBuilder);
LOGV2(4784930, "Shutting down the storage engine");
shutdownGlobalStorageEngineCleanly(serviceContext);
}
@@ -1708,12 +1426,7 @@ void shutdownTask(const ShutdownTaskArgs& shutdownArgs) {
ScriptEngine::dropScopeCache();
// Shutdown Full-Time Data Capture
- {
- TimeElapsedBuilderScopedTimer scopedTimer(serviceContext->getFastClockSource(),
- "Shut down full-time data capture",
- &shutdownTimeElapsedBuilder);
- stopMongoDFTDC();
- }
+ stopMongoDFTDC();
LOGV2(20565, "Now exiting");
@@ -1735,18 +1448,6 @@ void shutdownTask(const ShutdownTaskArgs& shutdownArgs) {
#endif
}
-void disableMongodTHPUnderTestingEnvironment() {
-#ifdef __linux__
- if (TestingProctor::instance().isEnabled()) {
- if (prctl(PR_SET_THP_DISABLE, 1, 0, 0, 0) == -1) {
- LOGV2_WARNING(8751800, "Could not disable THP on mongod");
- } else {
- LOGV2_INFO(8751801, "Successfully disabled THP on mongod");
- }
- }
-#endif
-}
-
} // namespace
int mongod_main(int argc, char* argv[]) {
@@ -1769,8 +1470,6 @@ int mongod_main(int argc, char* argv[]) {
quickExit(EXIT_FAILURE);
}
- disableMongodTHPUnderTestingEnvironment();
-
auto* service = [] {
try {
auto serviceContextHolder = ServiceContext::make();