diff options
author | Andrew Morrow <acm@mongodb.com> | 2016-03-11 14:34:47 -0500 |
---|---|---|
committer | Andrew Morrow <acm@mongodb.com> | 2016-03-21 22:55:32 -0400 |
commit | 4d6dd3b4359dc3cc8145beb10e54f84353689351 (patch) | |
tree | d2ca8c518ef2064854d5e9c1584fd89eab31d9e6 /src/mongo/db/instance.cpp | |
parent | 20ca6518797b67206d1f23d097c61c78a3ad8810 (diff) | |
download | mongo-4d6dd3b4359dc3cc8145beb10e54f84353689351.tar.gz |
SERVER-23103 Unify exit handling
Diffstat (limited to 'src/mongo/db/instance.cpp')
-rw-r--r-- | src/mongo/db/instance.cpp | 129 |
1 files changed, 0 insertions, 129 deletions
diff --git a/src/mongo/db/instance.cpp b/src/mongo/db/instance.cpp index 96bcf7d64ad..59f13ce1957 100644 --- a/src/mongo/db/instance.cpp +++ b/src/mongo/db/instance.cpp @@ -1223,135 +1223,6 @@ void receivedInsert(OperationContext* txn, const NamespaceString& nsString, Mess _receivedInsert(txn, nsString, ns, multi, keepGoing, op, false); } -static AtomicUInt32 shutdownInProgress(0); - -bool inShutdown() { - return shutdownInProgress.loadRelaxed() != 0; -} - -bool inShutdownStrict() { - return shutdownInProgress.load() != 0; -} - -static void shutdownServer() { - log(LogComponent::kNetwork) << "shutdown: going to close listening sockets..." << endl; - ListeningSockets::get()->closeAll(); - - log(LogComponent::kNetwork) << "shutdown: going to flush diaglog..." << endl; - _diaglog.flush(); - - /* must do this before unmapping mem or you may get a seg fault */ - log(LogComponent::kNetwork) << "shutdown: going to close sockets..." << endl; - stdx::thread close_socket_thread(stdx::bind(MessagingPort::closeAllSockets, 0)); - close_socket_thread.detach(); - - // We drop the scope cache because leak sanitizer can't see across the - // thread we use for proxying MozJS requests. Dropping the cache cleans up - // the memory and makes leak sanitizer happy. - ScriptEngine::dropScopeCache(); - - getGlobalServiceContext()->shutdownGlobalStorageEngineCleanly(); -} - -// shutdownLock -// -// Protects: -// Ensures shutdown is single threaded. -// Lock Ordering: -// No restrictions -stdx::mutex shutdownLock; - -void signalShutdown() { - // Notify all threads shutdown has started - shutdownInProgress.fetchAndAdd(1); -} - -void exitCleanly(ExitCode code) { - // Notify all threads shutdown has started - shutdownInProgress.fetchAndAdd(1); - - // Grab the shutdown lock to prevent concurrent callers - stdx::lock_guard<stdx::mutex> lockguard(shutdownLock); - - // Shutdown Full-Time Data Capture - stopFTDC(); - - // Global storage engine may not be started in all cases before we exit - if (getGlobalServiceContext()->getGlobalStorageEngine() == NULL) { - dbexit(code); // returns only under a windows service - invariant(code == EXIT_WINDOWS_SERVICE_STOP); - return; - } - - getGlobalServiceContext()->setKillAllOperations(); - - repl::getGlobalReplicationCoordinator()->shutdown(); - - Client& client = cc(); - ServiceContext::UniqueOperationContext uniqueTxn; - OperationContext* txn = client.getOperationContext(); - if (!txn) { - uniqueTxn = client.makeOperationContext(); - txn = uniqueTxn.get(); - } - - ShardingState::get(txn)->shutDown(txn); - - // We should always be able to acquire the global lock at shutdown. - // - // TODO: This call chain uses the locker directly, because we do not want to start an - // operation context, which also instantiates a recovery unit. Also, using the - // lockGlobalBegin/lockGlobalComplete sequence, we avoid taking the flush lock. This will - // all go away if we start acquiring the global/flush lock as part of ScopedTransaction. - // - // For a Windows service, dbexit does not call exit(), so we must leak the lock outside - // of this function to prevent any operations from running that need a lock. - // - DefaultLockerImpl* globalLocker = new DefaultLockerImpl(); - LockResult result = globalLocker->lockGlobalBegin(MODE_X); - if (result == LOCK_WAITING) { - result = globalLocker->lockGlobalComplete(UINT_MAX); - } - - invariant(LOCK_OK == result); - - log(LogComponent::kControl) << "now exiting" << endl; - - // Execute the graceful shutdown tasks, such as flushing the outstanding journal - // and data files, close sockets, etc. - try { - shutdownServer(); - } catch (const DBException& ex) { - severe() << "shutdown failed with DBException " << ex; - std::terminate(); - } catch (const std::exception& ex) { - severe() << "shutdown failed with std::exception: " << ex.what(); - std::terminate(); - } catch (...) { - severe() << "shutdown failed with exception"; - std::terminate(); - } - - dbexit(code); -} - -NOINLINE_DECL void dbexit(ExitCode rc, const char* why) { - audit::logShutdown(&cc()); - - log(LogComponent::kControl) << "dbexit: " << why << " rc: " << rc; - -#ifdef _WIN32 - // Windows Service Controller wants to be told when we are down, - // so don't call quickExit() yet, or say "really exiting now" - // - if (rc == EXIT_WINDOWS_SERVICE_STOP) { - return; - } -#endif - - quickExit(rc); -} - // ----- BEGIN Diaglog ----- DiagLog::DiagLog() : f(0), level(0) {} |