diff options
author | Andy Schwerin <schwerin@mongodb.com> | 2017-01-15 15:43:06 -0500 |
---|---|---|
committer | Andy Schwerin <schwerin@mongodb.com> | 2017-01-15 15:44:49 -0500 |
commit | a7e74d56036e94c3e4ed11ceeb4cd43e95209aa5 (patch) | |
tree | e90d6b26cb5f1bb26ebf95a36aa93ddf60f8c45c | |
parent | be58d599fd9df085c94be3c22051f04aa3df5c13 (diff) | |
download | mongo-a7e74d56036e94c3e4ed11ceeb4cd43e95209aa5.tar.gz |
SERVER-27603 Rename mongo::inShutdown() to mongo::globalInShutdownDeprecated() for clarity.
Calling this function is deprecated because modules that consult it
cannot engage in an orderly, coordinated shutdown. Instead, such
modules tend to just stop working at some point after
mongo::shutdown() is invoked, without regard to whether modules that
depend on them have already shut down.
As such, for clarity, this patch renames the function from
mongo::inShutdown() to mongo::globalInShutdownDeprecated(). This also
helps disambiguate calls to this function from calls to individual
components' similarly named functions.
Also, remove uncalled mongo::inShutdownStrict().
25 files changed, 52 insertions, 53 deletions
diff --git a/src/mongo/client/connpool.cpp b/src/mongo/client/connpool.cpp index 7a960dc8d42..5ef2b4e72e0 100644 --- a/src/mongo/client/connpool.cpp +++ b/src/mongo/client/connpool.cpp @@ -185,7 +185,7 @@ DBConnectionPool::DBConnectionPool() _hooks(new list<DBConnectionHook*>()) {} DBClientBase* DBConnectionPool::_get(const string& ident, double socketTimeout) { - uassert(17382, "Can't use connection pool during shutdown", !inShutdown()); + uassert(17382, "Can't use connection pool during shutdown", !globalInShutdownDeprecated()); stdx::lock_guard<stdx::mutex> L(_mutex); PoolForHost& p = _pools[PoolKey(ident, socketTimeout)]; p.setMaxPoolSize(_maxPoolSize); diff --git a/src/mongo/client/dbclientcursor.cpp b/src/mongo/client/dbclientcursor.cpp index da5bb661f71..74bd272d147 100644 --- a/src/mongo/client/dbclientcursor.cpp +++ b/src/mongo/client/dbclientcursor.cpp @@ -522,7 +522,7 @@ DBClientCursor::~DBClientCursor() { void DBClientCursor::kill() { DESTRUCTOR_GUARD( - if (cursorId && _ownCursor && !inShutdown()) { + if (cursorId && _ownCursor && !globalInShutdownDeprecated()) { if (_client) { _client->killCursor(cursorId); } else { diff --git a/src/mongo/db/auth/user_cache_invalidator_job.cpp b/src/mongo/db/auth/user_cache_invalidator_job.cpp index 4e5c113c664..a9198b52fe9 100644 --- a/src/mongo/db/auth/user_cache_invalidator_job.cpp +++ b/src/mongo/db/auth/user_cache_invalidator_job.cpp @@ -112,7 +112,7 @@ UserCacheInvalidator::UserCacheInvalidator(AuthorizationManager* authzManager) : _authzManager(authzManager) {} UserCacheInvalidator::~UserCacheInvalidator() { - invariant(inShutdown()); + invariant(globalInShutdownDeprecated()); // Wait to stop running. wait(); } @@ -153,7 +153,7 @@ void UserCacheInvalidator::run() { lastInvalidationTime = now; lock.unlock(); - if (inShutdown()) { + if (globalInShutdownDeprecated()) { break; } diff --git a/src/mongo/db/catalog/cursor_manager.cpp b/src/mongo/db/catalog/cursor_manager.cpp index 8640229faa9..f6f1cf21474 100644 --- a/src/mongo/db/catalog/cursor_manager.cpp +++ b/src/mongo/db/catalog/cursor_manager.cpp @@ -297,7 +297,7 @@ int CursorManager::eraseCursorGlobalIfAuthorized(OperationContext* txn, int n, c for (int i = 0; i < n; i++) { if (eraseCursorGlobalIfAuthorized(txn, ids.readAndAdvance<LittleEndian<int64_t>>())) numDeleted++; - if (inShutdown()) + if (globalInShutdownDeprecated()) break; } return numDeleted; diff --git a/src/mongo/db/clientcursor.cpp b/src/mongo/db/clientcursor.cpp index c2f5c487d97..5dc6196b904 100644 --- a/src/mongo/db/clientcursor.cpp +++ b/src/mongo/db/clientcursor.cpp @@ -266,7 +266,7 @@ public: void run() { Client::initThread("clientcursormon"); Timer t; - while (!inShutdown()) { + while (!globalInShutdownDeprecated()) { { const ServiceContext::UniqueOperationContext txnPtr = cc().makeOperationContext(); OperationContext& txn = *txnPtr; diff --git a/src/mongo/db/range_deleter.cpp b/src/mongo/db/range_deleter.cpp index 6f574293e21..dc6e48e038d 100644 --- a/src/mongo/db/range_deleter.cpp +++ b/src/mongo/db/range_deleter.cpp @@ -415,7 +415,7 @@ void RangeDeleter::doWork() { Client::initThreadIfNotAlready("RangeDeleter"); Client* client = &cc(); - while (!inShutdown() && !stopRequested()) { + while (!globalInShutdownDeprecated() && !stopRequested()) { string errMsg; RangeDeleteEntry* nextTask = NULL; diff --git a/src/mongo/db/repl/initial_sync.cpp b/src/mongo/db/repl/initial_sync.cpp index ae4421997f6..7c138a6f96c 100644 --- a/src/mongo/db/repl/initial_sync.cpp +++ b/src/mongo/db/repl/initial_sync.cpp @@ -72,7 +72,7 @@ void InitialSync::_applyOplogUntil(OperationContext* txn, const OpTime& endOpTim auto replCoord = repl::ReplicationCoordinator::get(txn); while (!tryPopAndWaitForMore(txn, &ops, BatchLimits{})) { - if (inShutdown()) { + if (globalInShutdownDeprecated()) { return; } @@ -113,7 +113,7 @@ void InitialSync::_applyOplogUntil(OperationContext* txn, const OpTime& endOpTim replCoord->setMyLastAppliedOpTime(lastOpTime); setNewTimestamp(lastOpTime.getTimestamp()); - if (inShutdown()) { + if (globalInShutdownDeprecated()) { return; } diff --git a/src/mongo/db/repl/rs_initialsync.cpp b/src/mongo/db/repl/rs_initialsync.cpp index 990f9dd8fdf..508edcb1ade 100644 --- a/src/mongo/db/repl/rs_initialsync.cpp +++ b/src/mongo/db/repl/rs_initialsync.cpp @@ -223,7 +223,7 @@ bool _initialSyncApplyOplog(OperationContext* txn, LOG(2) << "Applying oplog entries from " << startOpTime << " until " << stopOpTime; syncer->oplogApplication(txn, stopOpTime); - if (inShutdown()) { + if (globalInShutdownDeprecated()) { return false; } } catch (const DBException&) { @@ -289,7 +289,7 @@ Status _initialSync(OperationContext* txn, BackgroundSync* bgsync) { sleepsecs(1); } - if (inShutdown()) { + if (globalInShutdownDeprecated()) { return Status(ErrorCodes::ShutdownInProgress, "shutting down"); } } @@ -552,12 +552,12 @@ void syncDoInitialSync(OperationContext* txn, } catch (const DBException& e) { error() << redact(e); // Return if in shutdown - if (inShutdown()) { + if (globalInShutdownDeprecated()) { return; } } - if (inShutdown()) { + if (globalInShutdownDeprecated()) { return; } diff --git a/src/mongo/db/s/migration_source_manager.cpp b/src/mongo/db/s/migration_source_manager.cpp index 3cca0606180..a66e6d63e72 100644 --- a/src/mongo/db/s/migration_source_manager.cpp +++ b/src/mongo/db/s/migration_source_manager.cpp @@ -359,7 +359,7 @@ Status MigrationSourceManager::commitChunkMetadataOnConfig(OperationContext* txn if ((ErrorCodes::isInterruption(status.code()) || ErrorCodes::isShutdownError(status.code()) || status == ErrorCodes::CallbackCanceled) && - inShutdown()) { + globalInShutdownDeprecated()) { // Since the server is already doing a clean shutdown, this call will just join the // previous shutdown call shutdown(waitForShutdown()); diff --git a/src/mongo/db/stats/snapshots.cpp b/src/mongo/db/stats/snapshots.cpp index c1088f4d12f..8e62134e86e 100644 --- a/src/mongo/db/stats/snapshots.cpp +++ b/src/mongo/db/stats/snapshots.cpp @@ -106,7 +106,7 @@ StatusWith<SnapshotDiff> Snapshots::computeDelta() { void StatsSnapshotThread::run() { Client::initThread("statsSnapshot"); - while (!inShutdown()) { + while (!globalInShutdownDeprecated()) { try { statsSnapshots.takeSnapshot(); } catch (std::exception& e) { diff --git a/src/mongo/db/storage/mmap_v1/data_file_sync.cpp b/src/mongo/db/storage/mmap_v1/data_file_sync.cpp index 51a091dd7f2..24be15045f0 100644 --- a/src/mongo/db/storage/mmap_v1/data_file_sync.cpp +++ b/src/mongo/db/storage/mmap_v1/data_file_sync.cpp @@ -64,7 +64,7 @@ void DataFileSync::run() { LOG(1) << "--syncdelay " << storageGlobalParams.syncdelay.load() << endl; } int time_flushing = 0; - while (!inShutdown()) { + while (!globalInShutdownDeprecated()) { _diaglog.flush(); if (storageGlobalParams.syncdelay == 0) { // in case at some point we add an option to change at runtime @@ -75,7 +75,7 @@ void DataFileSync::run() { sleepmillis( (long long)std::max(0.0, (storageGlobalParams.syncdelay * 1000) - time_flushing)); - if (inShutdown()) { + if (globalInShutdownDeprecated()) { // occasional issue trying to flush during shutdown when sleep interrupted break; } diff --git a/src/mongo/db/storage/mmap_v1/dur_journal.cpp b/src/mongo/db/storage/mmap_v1/dur_journal.cpp index 2d8e7b02fa6..e7de8b5967f 100644 --- a/src/mongo/db/storage/mmap_v1/dur_journal.cpp +++ b/src/mongo/db/storage/mmap_v1/dur_journal.cpp @@ -725,7 +725,7 @@ void Journal::removeUnneededJournalFiles() { } void Journal::_rotate(unsigned long long lsnOfCurrentJournalEntry) { - if (inShutdown() || !_curLogFile) + if (globalInShutdownDeprecated() || !_curLogFile) return; j.updateLSNFile(lsnOfCurrentJournalEntry); diff --git a/src/mongo/db/storage/mmap_v1/dur_recover.cpp b/src/mongo/db/storage/mmap_v1/dur_recover.cpp index 835264ec864..ec6b945455e 100644 --- a/src/mongo/db/storage/mmap_v1/dur_recover.cpp +++ b/src/mongo/db/storage/mmap_v1/dur_recover.cpp @@ -526,7 +526,9 @@ bool RecoveryJob::processFileBuffer(const void* p, unsigned len) { processSection((const JSectHeader*)hdr, data, dataLen, (const JSectFooter*)footer); // ctrl c check - uassert(ErrorCodes::Interrupted, "interrupted during journal recovery", !inShutdown()); + uassert(ErrorCodes::Interrupted, + "interrupted during journal recovery", + !globalInShutdownDeprecated()); } } catch (const BufReader::eof&) { if (mmapv1GlobalOptions.journalOptions & MMAPV1Options::JournalDumpJournal) diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_record_store_mongod.cpp b/src/mongo/db/storage/wiredtiger/wiredtiger_record_store_mongod.cpp index 2d4e5d25759..1d0606ee9de 100644 --- a/src/mongo/db/storage/wiredtiger/wiredtiger_record_store_mongod.cpp +++ b/src/mongo/db/storage/wiredtiger/wiredtiger_record_store_mongod.cpp @@ -117,7 +117,7 @@ public: virtual void run() { Client::initThread(_name.c_str()); - while (!inShutdown()) { + while (!globalInShutdownDeprecated()) { if (!_deleteExcessDocuments()) { sleepmillis(1000); // Back off in case there were problems deleting. } diff --git a/src/mongo/db/ttl.cpp b/src/mongo/db/ttl.cpp index 6f1bf84b872..5c9c743b021 100644 --- a/src/mongo/db/ttl.cpp +++ b/src/mongo/db/ttl.cpp @@ -86,7 +86,7 @@ public: Client::initThread(name().c_str()); AuthorizationSession::get(cc())->grantInternalAuthorization(); - while (!inShutdown()) { + while (!globalInShutdownDeprecated()) { sleepsecs(ttlMonitorSleepSecs.load()); LOG(3) << "thread awake"; diff --git a/src/mongo/s/client/shard_connection.cpp b/src/mongo/s/client/shard_connection.cpp index 490a2f4ee83..ec80fb5c5e5 100644 --- a/src/mongo/s/client/shard_connection.cpp +++ b/src/mongo/s/client/shard_connection.cpp @@ -181,7 +181,7 @@ public: if (ss->avail) { // If we're shutting down, don't want to initiate release mechanism as it is // slow, and isn't needed since all connections will be closed anyway. - if (inShutdown()) { + if (globalInShutdownDeprecated()) { if (versionManager.isVersionableCB(ss->avail)) { versionManager.resetShardVersionCB(ss->avail); } diff --git a/src/mongo/s/query/cluster_cursor_cleanup_job.cpp b/src/mongo/s/query/cluster_cursor_cleanup_job.cpp index 73de6b071f6..45fe1c44825 100644 --- a/src/mongo/s/query/cluster_cursor_cleanup_job.cpp +++ b/src/mongo/s/query/cluster_cursor_cleanup_job.cpp @@ -66,7 +66,7 @@ void ClusterCursorCleanupJob::run() { ClusterCursorManager* manager = grid.getCursorManager(); invariant(manager); - while (!inShutdown()) { + while (!globalInShutdownDeprecated()) { manager->killMortalCursorsInactiveSince(Date_t::now() - Milliseconds(cursorTimeoutMillis.load())); manager->incrementCursorsTimedOut(manager->reapZombieCursors()); diff --git a/src/mongo/s/server.cpp b/src/mongo/s/server.cpp index e80e9591497..d18e62048e8 100644 --- a/src/mongo/s/server.cpp +++ b/src/mongo/s/server.cpp @@ -271,7 +271,7 @@ static ExitCode runMongosServer() { Status status = initializeSharding(opCtx.get()); if (!status.isOK()) { if (status == ErrorCodes::CallbackCanceled) { - invariant(inShutdown()); + invariant(globalInShutdownDeprecated()); log() << "Shutdown called before mongos finished starting up"; return EXIT_CLEAN; } diff --git a/src/mongo/s/sharding_initialization.cpp b/src/mongo/s/sharding_initialization.cpp index 5bcce059ec4..a98d9b0941f 100644 --- a/src/mongo/s/sharding_initialization.cpp +++ b/src/mongo/s/sharding_initialization.cpp @@ -233,7 +233,7 @@ Status reloadShardRegistryUntilSuccess(OperationContext* txn) { return Status::OK(); } - while (!inShutdown()) { + while (!globalInShutdownDeprecated()) { auto stopStatus = txn->checkForInterruptNoAssert(); if (!stopStatus.isOK()) { return stopStatus; diff --git a/src/mongo/s/sharding_uptime_reporter.cpp b/src/mongo/s/sharding_uptime_reporter.cpp index ba5f3690822..d2d170df176 100644 --- a/src/mongo/s/sharding_uptime_reporter.cpp +++ b/src/mongo/s/sharding_uptime_reporter.cpp @@ -97,7 +97,7 @@ void ShardingUptimeReporter::startPeriodicThread() { const std::string instanceId(constructInstanceIdString()); const Timer upTimeTimer; - while (!inShutdown()) { + while (!globalInShutdownDeprecated()) { { auto txn = cc().makeOperationContext(); reportStatus(txn.get(), instanceId, upTimeTimer); diff --git a/src/mongo/util/concurrency/task.cpp b/src/mongo/util/concurrency/task.cpp index a73938a5f75..ab9c7b537bd 100644 --- a/src/mongo/util/concurrency/task.cpp +++ b/src/mongo/util/concurrency/task.cpp @@ -62,7 +62,7 @@ void Task::run() { } catch (...) { } sleepmillis(repeat); - if (inShutdown()) + if (globalInShutdownDeprecated()) break; if (repeat == 0) break; diff --git a/src/mongo/util/exit.cpp b/src/mongo/util/exit.cpp index 39ca2ec611f..53ba2dd55e1 100644 --- a/src/mongo/util/exit.cpp +++ b/src/mongo/util/exit.cpp @@ -77,14 +77,10 @@ void setShutdownFlag() { } // namespace -bool inShutdown() { +bool globalInShutdownDeprecated() { return shutdownFlag.loadRelaxed() != 0; } -bool inShutdownStrict() { - return shutdownFlag.load() != 0; -} - ExitCode waitForShutdown() { stdx::unique_lock<stdx::mutex> lk(shutdownMutex); shutdownTasksComplete.wait(lk, [] { return static_cast<bool>(shutdownExitCode); }); @@ -94,7 +90,7 @@ ExitCode waitForShutdown() { void registerShutdownTask(stdx::function<void()> task) { stdx::lock_guard<stdx::mutex> lock(shutdownMutex); - invariant(!inShutdown()); + invariant(!globalInShutdownDeprecated()); shutdownTasks.emplace(std::move(task)); } @@ -106,7 +102,7 @@ void shutdown(ExitCode code) { if (shutdownTasksInProgress) { // Someone better have called shutdown in some form already. - invariant(inShutdown()); + invariant(globalInShutdownDeprecated()); // Re-entrant calls to shutdown are not allowed. invariant(shutdownTasksThreadId != stdx::this_thread::get_id()); @@ -144,7 +140,7 @@ void shutdownNoTerminate() { { stdx::lock_guard<stdx::mutex> lock(shutdownMutex); - if (inShutdown()) + if (globalInShutdownDeprecated()) return; setShutdownFlag(); diff --git a/src/mongo/util/exit.h b/src/mongo/util/exit.h index 1aed81117a8..dd45cdddf28 100644 --- a/src/mongo/util/exit.h +++ b/src/mongo/util/exit.h @@ -35,15 +35,15 @@ namespace mongo { /** - * Quickly determines if the shutdown flag is set. May not be definitive. + * Determines if the shutdown flag is set. + * + * Calling this function is deprecated because modules that consult it + * cannot engage in an orderly, coordinated shutdown. Instead, such + * modules tend to just stop working at some point after mongo::shutdown() is + * invoked, without regard to whether modules that depend on them have + * already shut down. */ -bool inShutdown(); - -/** - * Definitively determines if the shutdown flag is set. Calling this is more expensive - * than inShutdown(). - */ -bool inShutdownStrict(); +bool globalInShutdownDeprecated(); /** * Does not return until all shutdown tasks have run. diff --git a/src/mongo/util/net/listen.cpp b/src/mongo/util/net/listen.cpp index cdde27d258d..a5017a3f67d 100644 --- a/src/mongo/util/net/listen.cpp +++ b/src/mongo/util/net/listen.cpp @@ -281,7 +281,7 @@ void Listener::initAndListen() { struct timeval maxSelectTime; // The check against _finished allows us to actually stop the listener by signalling it through // the _finished flag. - while (!inShutdown() && !_finished.load()) { + while (!globalInShutdownDeprecated() && !_finished.load()) { fd_set fds[1]; FD_ZERO(fds); @@ -303,7 +303,7 @@ void Listener::initAndListen() { continue; } #endif - if (!inShutdown()) + if (!globalInShutdownDeprecated()) log() << "select() failure: ret=" << ret << " " << errnoWithDescription(x); return; } @@ -322,10 +322,10 @@ void Listener::initAndListen() { log() << "Connection on port " << _port << " aborted"; continue; } - if (x == 0 && inShutdown()) { + if (x == 0 && globalInShutdownDeprecated()) { return; // socket closed } - if (!inShutdown()) { + if (!globalInShutdownDeprecated()) { log() << "Listener: accept() returns " << s << " " << errnoWithDescription(x); if (x == EMFILE || x == ENFILE) { // Connection still in listen queue but we can't accept it yet @@ -455,7 +455,7 @@ void Listener::initAndListen() { events[count] = ev->get(); } - while (!inShutdown()) { + while (!globalInShutdownDeprecated()) { // Turn on listening for accept-ready sockets for (size_t count = 0; count < _socks.size(); ++count) { int status = WSAEventSelect(_socks[count], events[count], FD_ACCEPT | FD_CLOSE); @@ -465,7 +465,7 @@ void Listener::initAndListen() { // We may fail to listen on the socket if it has // already been closed. If we are not in shutdown, // that is possibly interesting, so log an error. - if (!inShutdown()) { + if (!globalInShutdownDeprecated()) { error() << "Windows WSAEventSelect returned " << errnoWithDescription(mongo_errno); } @@ -538,10 +538,10 @@ void Listener::initAndListen() { log() << "Listener on port " << _port << " aborted"; continue; } - if (x == 0 && inShutdown()) { + if (x == 0 && globalInShutdownDeprecated()) { return; // socket closed } - if (!inShutdown()) { + if (!globalInShutdownDeprecated()) { log() << "Listener: accept() returns " << s << " " << errnoWithDescription(x); if (x == EMFILE || x == ENFILE) { // Connection still in listen queue but we can't accept it yet diff --git a/src/mongo/util/ntservice.cpp b/src/mongo/util/ntservice.cpp index 8044d26790d..362644e4ff8 100644 --- a/src/mongo/util/ntservice.cpp +++ b/src/mongo/util/ntservice.cpp @@ -575,12 +575,13 @@ static void serviceShutdown(const char* controlCodeName) { setThreadName("serviceShutdown"); log() << "got " << controlCodeName << " request from Windows Service Control Manager, " - << (inShutdown() ? "already in shutdown" : "will terminate after current cmd ends"); + << (globalInShutdownDeprecated() ? "already in shutdown" + : "will terminate after current cmd ends"); reportStatus(SERVICE_STOP_PENDING, kStopWaitHintMillis); // Note: This triggers _serviceCallback, ie ServiceMain, - // to stop by setting inShutdown() == true + // to stop by setting globalInShutdownDeprecated() == true shutdownNoTerminate(); // Note: we will report exit status in initService |