Пример #1
0
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;
}
ServiceContext::UniqueOperationContext ServiceContext::makeOperationContext(Client* client) {
    auto opCtx = std::make_unique<OperationContext>(client, _nextOpId.fetchAndAdd(1));
    onCreate(opCtx.get(), _clientObservers);
    if (!opCtx->lockState()) {
        opCtx->setLockState(std::make_unique<LockerNoop>());
    }
    if (!opCtx->recoveryUnit()) {
        opCtx->setRecoveryUnit(std::make_unique<RecoveryUnitNoop>(),
                               WriteUnitOfWork::RecoveryUnitState::kNotInUnitOfWork);
    }
    {
        stdx::lock_guard<Client> lk(*client);
        client->setOperationContext(opCtx.get());
    }
    return UniqueOperationContext(opCtx.release());
};