diff options
author | Mark Benvenuto <mark.benvenuto@mongodb.com> | 2015-06-20 00:22:50 -0400 |
---|---|---|
committer | Mark Benvenuto <mark.benvenuto@mongodb.com> | 2015-06-20 10:56:02 -0400 |
commit | 9c2ed42daa8fbbef4a919c21ec564e2db55e8d60 (patch) | |
tree | 3814f79c10d7b490948d8cb7b112ac1dd41ceff1 /src/mongo/db/service_context_d.cpp | |
parent | 01965cf52bce6976637ecb8f4a622aeb05ab256a (diff) | |
download | mongo-9c2ed42daa8fbbef4a919c21ec564e2db55e8d60.tar.gz |
SERVER-18579: Clang-Format - reformat code, no comment reflow
Diffstat (limited to 'src/mongo/db/service_context_d.cpp')
-rw-r--r-- | src/mongo/db/service_context_d.cpp | 400 |
1 files changed, 197 insertions, 203 deletions
diff --git a/src/mongo/db/service_context_d.cpp b/src/mongo/db/service_context_d.cpp index f02423a9e1a..7fd76d14580 100644 --- a/src/mongo/db/service_context_d.cpp +++ b/src/mongo/db/service_context_d.cpp @@ -53,254 +53,248 @@ namespace mongo { - MONGO_INITIALIZER(SetGlobalEnvironment)(InitializerContext* context) { - setGlobalServiceContext(stdx::make_unique<ServiceContextMongoD>()); - return Status::OK(); - } - - ServiceContextMongoD::ServiceContextMongoD() - : _globalKill(false), - _storageEngine(NULL) { } - - ServiceContextMongoD::~ServiceContextMongoD() { - - } - - StorageEngine* ServiceContextMongoD::getGlobalStorageEngine() { - // We don't check that globalStorageEngine is not-NULL here intentionally. We can encounter - // an error before it's initialized and proceed to exitCleanly which is equipped to deal - // with a NULL storage engine. - return _storageEngine; - } - - extern bool _supportsDocLocking; - - void ServiceContextMongoD::initializeGlobalStorageEngine() { - // This should be set once. - invariant(!_storageEngine); - - const std::string dbpath = storageGlobalParams.dbpath; - if (auto existingStorageEngine = StorageEngineMetadata::getStorageEngineForPath(dbpath)) { - if (storageGlobalParams.engineSetByUser) { - // Verify that the name of the user-supplied storage engine matches the contents of - // the metadata file. - const StorageEngine::Factory* factory = mapFindWithDefault( - _storageFactories, - storageGlobalParams.engine, - static_cast<const StorageEngine::Factory*>(nullptr)); - - if (factory) { - uassert(28662, str::stream() - << "Cannot start server. Detected data files in " << dbpath << " created by" - << " the '" << *existingStorageEngine << "' storage engine, but the" - << " specified storage engine was '" << factory->getCanonicalName() << "'.", +MONGO_INITIALIZER(SetGlobalEnvironment)(InitializerContext* context) { + setGlobalServiceContext(stdx::make_unique<ServiceContextMongoD>()); + return Status::OK(); +} + +ServiceContextMongoD::ServiceContextMongoD() : _globalKill(false), _storageEngine(NULL) {} + +ServiceContextMongoD::~ServiceContextMongoD() {} + +StorageEngine* ServiceContextMongoD::getGlobalStorageEngine() { + // We don't check that globalStorageEngine is not-NULL here intentionally. We can encounter + // an error before it's initialized and proceed to exitCleanly which is equipped to deal + // with a NULL storage engine. + return _storageEngine; +} + +extern bool _supportsDocLocking; + +void ServiceContextMongoD::initializeGlobalStorageEngine() { + // This should be set once. + invariant(!_storageEngine); + + const std::string dbpath = storageGlobalParams.dbpath; + if (auto existingStorageEngine = StorageEngineMetadata::getStorageEngineForPath(dbpath)) { + if (storageGlobalParams.engineSetByUser) { + // Verify that the name of the user-supplied storage engine matches the contents of + // the metadata file. + const StorageEngine::Factory* factory = + mapFindWithDefault(_storageFactories, + storageGlobalParams.engine, + static_cast<const StorageEngine::Factory*>(nullptr)); + + if (factory) { + uassert(28662, + str::stream() + << "Cannot start server. Detected data files in " << dbpath + << " created by" + << " the '" << *existingStorageEngine << "' storage engine, but the" + << " specified storage engine was '" << factory->getCanonicalName() + << "'.", factory->getCanonicalName() == *existingStorageEngine); - } - } - else { - // Otherwise set the active storage engine as the contents of the metadata file. - log() << "Detected data files in " << dbpath << " created by the '" - << *existingStorageEngine << "' storage engine, so setting the active" - << " storage engine to '" << *existingStorageEngine << "'."; - storageGlobalParams.engine = *existingStorageEngine; } + } else { + // Otherwise set the active storage engine as the contents of the metadata file. + log() << "Detected data files in " << dbpath << " created by the '" + << *existingStorageEngine << "' storage engine, so setting the active" + << " storage engine to '" << *existingStorageEngine << "'."; + storageGlobalParams.engine = *existingStorageEngine; } - else if (!storageGlobalParams.engineSetByUser) { - // Ensure the default storage engine is available with this build of mongod. - uassert(28663, str::stream() - << "Cannot start server. The default storage engine '" << storageGlobalParams.engine - << "' is not available with this build of mongod. Please specify a different" - << " storage engine explicitly, e.g. --storageEngine=mmapv1.", + } else if (!storageGlobalParams.engineSetByUser) { + // Ensure the default storage engine is available with this build of mongod. + uassert(28663, + str::stream() + << "Cannot start server. The default storage engine '" + << storageGlobalParams.engine + << "' is not available with this build of mongod. Please specify a different" + << " storage engine explicitly, e.g. --storageEngine=mmapv1.", isRegisteredStorageEngine(storageGlobalParams.engine)); - } + } - const StorageEngine::Factory* factory = _storageFactories[storageGlobalParams.engine]; + const StorageEngine::Factory* factory = _storageFactories[storageGlobalParams.engine]; - uassert(18656, str::stream() - << "Cannot start server with an unknown storage engine: " << storageGlobalParams.engine, + uassert(18656, + str::stream() << "Cannot start server with an unknown storage engine: " + << storageGlobalParams.engine, factory); - std::unique_ptr<StorageEngineMetadata> metadata = StorageEngineMetadata::forPath(dbpath); + std::unique_ptr<StorageEngineMetadata> metadata = StorageEngineMetadata::forPath(dbpath); - // Validate options in metadata against current startup options. - if (metadata.get()) { - uassertStatusOK(factory->validateMetadata(*metadata, storageGlobalParams)); - } + // Validate options in metadata against current startup options. + if (metadata.get()) { + uassertStatusOK(factory->validateMetadata(*metadata, storageGlobalParams)); + } - try { - _lockFile.reset(new StorageEngineLockFile(storageGlobalParams.dbpath)); - } - catch (const std::exception& ex) { - uassert(28596, str::stream() - << "Unable to determine status of lock file in the data directory " - << storageGlobalParams.dbpath << ": " << ex.what(), + try { + _lockFile.reset(new StorageEngineLockFile(storageGlobalParams.dbpath)); + } catch (const std::exception& ex) { + uassert(28596, + str::stream() << "Unable to determine status of lock file in the data directory " + << storageGlobalParams.dbpath << ": " << ex.what(), false); - } - if (_lockFile->createdByUncleanShutdown()) { - warning() << "Detected unclean shutdown - " - << _lockFile->getFilespec() << " is not empty."; - } - uassertStatusOK(_lockFile->open()); - - ScopeGuard guard = MakeGuard(&StorageEngineLockFile::close, _lockFile.get()); - _storageEngine = factory->create(storageGlobalParams, *_lockFile); - _storageEngine->finishInit(); - uassertStatusOK(_lockFile->writePid()); - - // Write a new metadata file if it is not present. - if (!metadata.get()) { - metadata.reset(new StorageEngineMetadata(storageGlobalParams.dbpath)); - metadata->setStorageEngine(factory->getCanonicalName().toString()); - metadata->setStorageEngineOptions(factory->createMetadataOptions(storageGlobalParams)); - uassertStatusOK(metadata->write()); - } + } + if (_lockFile->createdByUncleanShutdown()) { + warning() << "Detected unclean shutdown - " << _lockFile->getFilespec() << " is not empty."; + } + uassertStatusOK(_lockFile->open()); + + ScopeGuard guard = MakeGuard(&StorageEngineLockFile::close, _lockFile.get()); + _storageEngine = factory->create(storageGlobalParams, *_lockFile); + _storageEngine->finishInit(); + uassertStatusOK(_lockFile->writePid()); + + // Write a new metadata file if it is not present. + if (!metadata.get()) { + metadata.reset(new StorageEngineMetadata(storageGlobalParams.dbpath)); + metadata->setStorageEngine(factory->getCanonicalName().toString()); + metadata->setStorageEngineOptions(factory->createMetadataOptions(storageGlobalParams)); + uassertStatusOK(metadata->write()); + } - guard.Dismiss(); + guard.Dismiss(); - _supportsDocLocking = _storageEngine->supportsDocLocking(); - } + _supportsDocLocking = _storageEngine->supportsDocLocking(); +} - void ServiceContextMongoD::shutdownGlobalStorageEngineCleanly() { - invariant(_storageEngine); - invariant(_lockFile.get()); - _storageEngine->cleanShutdown(); - _lockFile->clearPidAndUnlock(); - } +void ServiceContextMongoD::shutdownGlobalStorageEngineCleanly() { + invariant(_storageEngine); + invariant(_lockFile.get()); + _storageEngine->cleanShutdown(); + _lockFile->clearPidAndUnlock(); +} - void ServiceContextMongoD::registerStorageEngine(const std::string& name, - const StorageEngine::Factory* factory) { - // No double-registering. - invariant(0 == _storageFactories.count(name)); +void ServiceContextMongoD::registerStorageEngine(const std::string& name, + const StorageEngine::Factory* factory) { + // No double-registering. + invariant(0 == _storageFactories.count(name)); - // Some sanity checks: the factory must exist, - invariant(factory); + // Some sanity checks: the factory must exist, + invariant(factory); - // and all factories should be added before we pick a storage engine. - invariant(NULL == _storageEngine); + // and all factories should be added before we pick a storage engine. + invariant(NULL == _storageEngine); - _storageFactories[name] = factory; - } + _storageFactories[name] = factory; +} - bool ServiceContextMongoD::isRegisteredStorageEngine(const std::string& name) { - return _storageFactories.count(name); - } +bool ServiceContextMongoD::isRegisteredStorageEngine(const std::string& name) { + return _storageFactories.count(name); +} - StorageFactoriesIterator* ServiceContextMongoD::makeStorageFactoriesIterator() { - return new StorageFactoriesIteratorMongoD(_storageFactories.begin(), - _storageFactories.end()); - } +StorageFactoriesIterator* ServiceContextMongoD::makeStorageFactoriesIterator() { + return new StorageFactoriesIteratorMongoD(_storageFactories.begin(), _storageFactories.end()); +} - StorageFactoriesIteratorMongoD::StorageFactoriesIteratorMongoD( - const ServiceContextMongoD::FactoryMap::const_iterator& begin, - const ServiceContextMongoD::FactoryMap::const_iterator& end) : - _curr(begin), _end(end) { - } +StorageFactoriesIteratorMongoD::StorageFactoriesIteratorMongoD( + const ServiceContextMongoD::FactoryMap::const_iterator& begin, + const ServiceContextMongoD::FactoryMap::const_iterator& end) + : _curr(begin), _end(end) {} - bool StorageFactoriesIteratorMongoD::more() const { - return _curr != _end; - } +bool StorageFactoriesIteratorMongoD::more() const { + return _curr != _end; +} - const StorageEngine::Factory* StorageFactoriesIteratorMongoD::next() { - return _curr++->second; - } +const StorageEngine::Factory* StorageFactoriesIteratorMongoD::next() { + return _curr++->second; +} - void ServiceContextMongoD::setKillAllOperations() { - stdx::lock_guard<stdx::mutex> clientLock(_mutex); - _globalKill = true; - for (const auto listener : _killOpListeners) { - try { - listener->interruptAll(); - } - catch (...) { - std::terminate(); - } +void ServiceContextMongoD::setKillAllOperations() { + stdx::lock_guard<stdx::mutex> clientLock(_mutex); + _globalKill = true; + for (const auto listener : _killOpListeners) { + try { + listener->interruptAll(); + } catch (...) { + std::terminate(); } } +} - bool ServiceContextMongoD::getKillAllOperations() { - return _globalKill; - } +bool ServiceContextMongoD::getKillAllOperations() { + return _globalKill; +} - bool ServiceContextMongoD::_killOperationsAssociatedWithClientAndOpId_inlock( - Client* client, unsigned int opId) { - OperationContext* opCtx = client->getOperationContext(); - if (!opCtx) { - return false; - } - if (opCtx->getOpID() != opId) { - return false; - } - _killOperation_inlock(opCtx); - return true; +bool ServiceContextMongoD::_killOperationsAssociatedWithClientAndOpId_inlock(Client* client, + unsigned int opId) { + OperationContext* opCtx = client->getOperationContext(); + if (!opCtx) { + return false; + } + if (opCtx->getOpID() != opId) { + return false; } + _killOperation_inlock(opCtx); + return true; +} - void ServiceContextMongoD::_killOperation_inlock(OperationContext* opCtx) { - opCtx->markKilled(); +void ServiceContextMongoD::_killOperation_inlock(OperationContext* opCtx) { + opCtx->markKilled(); - for (const auto listener : _killOpListeners) { - try { - listener->interrupt(opCtx->getOpID()); - } - catch (...) { - std::terminate(); - } + for (const auto listener : _killOpListeners) { + try { + listener->interrupt(opCtx->getOpID()); + } catch (...) { + std::terminate(); } } - - bool ServiceContextMongoD::killOperation(unsigned int opId) { - for (LockedClientsCursor cursor(this); Client* client = cursor.next();) { - stdx::lock_guard<Client> lk(*client); - bool found = _killOperationsAssociatedWithClientAndOpId_inlock(client, opId); - if (found) { - return true; - } +} + +bool ServiceContextMongoD::killOperation(unsigned int opId) { + for (LockedClientsCursor cursor(this); Client* client = cursor.next();) { + stdx::lock_guard<Client> lk(*client); + bool found = _killOperationsAssociatedWithClientAndOpId_inlock(client, opId); + if (found) { + return true; } - - return false; } - void ServiceContextMongoD::killAllUserOperations(const OperationContext* txn) { - for (LockedClientsCursor cursor(this); Client* client = cursor.next();) { - if (!client->isFromUserConnection()) { - // Don't kill system operations. - continue; - } + return false; +} - stdx::lock_guard<Client> lk(*client); - OperationContext* toKill = client->getOperationContext(); - if (!toKill) { - continue; - } +void ServiceContextMongoD::killAllUserOperations(const OperationContext* txn) { + for (LockedClientsCursor cursor(this); Client* client = cursor.next();) { + if (!client->isFromUserConnection()) { + // Don't kill system operations. + continue; + } - if (toKill->getOpID() == txn->getOpID()) { - // Don't kill ourself. - continue; - } + stdx::lock_guard<Client> lk(*client); + OperationContext* toKill = client->getOperationContext(); + if (!toKill) { + continue; + } - _killOperation_inlock(toKill); + if (toKill->getOpID() == txn->getOpID()) { + // Don't kill ourself. + continue; } - } - void ServiceContextMongoD::unsetKillAllOperations() { - _globalKill = false; + _killOperation_inlock(toKill); } +} - void ServiceContextMongoD::registerKillOpListener(KillOpListenerInterface* listener) { - stdx::lock_guard<stdx::mutex> clientLock(_mutex); - _killOpListeners.push_back(listener); - } +void ServiceContextMongoD::unsetKillAllOperations() { + _globalKill = false; +} - std::unique_ptr<OperationContext> ServiceContextMongoD::_newOpCtx(Client* client) { - invariant(&cc() == client); - return stdx::make_unique<OperationContextImpl>(); - } +void ServiceContextMongoD::registerKillOpListener(KillOpListenerInterface* listener) { + stdx::lock_guard<stdx::mutex> clientLock(_mutex); + _killOpListeners.push_back(listener); +} - void ServiceContextMongoD::setOpObserver(std::unique_ptr<OpObserver> opObserver) { - _opObserver.reset(opObserver.get()); - } +std::unique_ptr<OperationContext> ServiceContextMongoD::_newOpCtx(Client* client) { + invariant(&cc() == client); + return stdx::make_unique<OperationContextImpl>(); +} - OpObserver* ServiceContextMongoD::getOpObserver() { - return _opObserver.get(); - } +void ServiceContextMongoD::setOpObserver(std::unique_ptr<OpObserver> opObserver) { + _opObserver.reset(opObserver.get()); +} + +OpObserver* ServiceContextMongoD::getOpObserver() { + return _opObserver.get(); +} } // namespace mongo |