void ServiceContextMongoDTest::setUp() { Client::initThread(getThreadName()); auto const serviceContext = getServiceContext(); auto logicalClock = stdx::make_unique<LogicalClock>(serviceContext); LogicalClock::set(serviceContext, std::move(logicalClock)); if (!serviceContext->getGlobalStorageEngine()) { // When using the "ephemeralForTest" storage engine, it is fine for the temporary directory // to go away after the global storage engine is initialized. unittest::TempDir tempDir("service_context_d_test_fixture"); storageGlobalParams.dbpath = tempDir.path(); storageGlobalParams.engine = "ephemeralForTest"; storageGlobalParams.engineSetByUser = true; checked_cast<ServiceContextMongoD*>(serviceContext)->createLockFile(); serviceContext->initializeGlobalStorageEngine(); serviceContext->setOpObserver(stdx::make_unique<OpObserverNoop>()); } // Set up UUID Catalog observer. This is necessary because the Collection destructor contains an // invariant to ensure the UUID corresponding to that Collection object is no longer associated // with that Collection object in the UUIDCatalog. UUIDs may be registered in the UUIDCatalog // directly in certain code paths, but they can only be removed from the UUIDCatalog via a // UUIDCatalogObserver. It is therefore necessary to install the observer to ensure the // invariant in the Collection destructor is not triggered. auto observerRegistry = stdx::make_unique<OpObserverRegistry>(); observerRegistry->addObserver(stdx::make_unique<UUIDCatalogObserver>()); serviceContext->setOpObserver(std::unique_ptr<OpObserver>(observerRegistry.release())); }
std::unique_ptr<OperationContext> ServiceContextMongoD::_newOpCtx(Client* client, unsigned opId) { invariant(&cc() == client); auto opCtx = stdx::make_unique<OperationContext>(client, opId); if (isMMAPV1()) { opCtx->setLockState(stdx::make_unique<MMAPV1LockerImpl>()); } else { opCtx->setLockState(stdx::make_unique<DefaultLockerImpl>()); } opCtx->setRecoveryUnit(getGlobalStorageEngine()->newRecoveryUnit(), OperationContext::kNotInUnitOfWork); return opCtx; }