Exemple #1
0
    bool WriteBatchExecutor::ExecInsertsState::_lockAndCheckImpl(WriteOpResult* result) {
        if (hasLock()) {
            txn->getCurOp()->enter(_context.get());
            return true;
        }

        invariant(!_context.get());
        _writeLock.reset(new Lock::DBWrite(txn->lockState(), request->getNS()));
        if (!checkIsMasterForDatabase(request->getNS(), result)) {
            return false;
        }
        if (!checkShardVersion(txn, &shardingState, *request, result)) {
            return false;
        }
        if (!checkIndexConstraints(txn, &shardingState, *request, result)) {
            return false;
        }
        _context.reset(new Client::Context(request->getNS(),
                                           false /* don't check version */));
        Database* database = _context->db();
        dassert(database);
        _collection = database->getCollection(txn, request->getTargetingNS());
        if (!_collection) {
            // Implicitly create if it doesn't exist
            _collection = database->createCollection(txn, request->getTargetingNS());
            if (!_collection) {
                result->setError(
                        toWriteError(Status(ErrorCodes::InternalError,
                                            "could not create collection " +
                                            request->getTargetingNS())));
                return false;
            }
        }
        return true;
    }
Exemple #2
0
QWSLock::~QWSLock()
{
#ifndef QT_NO_QWS_SIGNALHANDLER
    QWSSignalHandler::instance()->removeWSLock(this);
#endif

    if (semId != -1) {
#ifndef QT_POSIX_IPC
        qt_semun semval;
        semval.val = 0;
        semctl(semId, 0, IPC_RMID, semval);
        semId = -1;
#else
        // emulate the SEM_UNDO behavior for the BackingStore lock
        while (hasLock(BackingStore))
            unlock(BackingStore);

        QByteArray pfx = "/qwslock_" + QByteArray::number(semId, 16) + '_';
        QByteArray keys[3] = { pfx + "BackingStore", pfx + "Communication", pfx + "RegionEvent" };
        for (int i = 0; i < 3; ++i) {
            if (sems[i] != SEM_FAILED) {
                sem_close(sems[i]);
                sems[i] = SEM_FAILED;
            }
            if (owned)
                sem_unlink(keys[i].constData());
        }
#endif
    }
}
Exemple #3
0
    bool WriteBatchExecutor::ExecInsertsState::_lockAndCheckImpl(WriteOpResult* result) {
        if (hasLock()) {
            txn->getCurOp()->enter(_context.get());
            return true;
        }

        invariant(!_context.get());
        _writeLock.reset(new Lock::DBLock(txn->lockState(),
                                          nsToDatabase(request->getNS()),
                                          newlm::MODE_X));
        if (!checkIsMasterForDatabase(request->getNS(), result)) {
            return false;
        }
        if (!checkShardVersion(txn, &shardingState, *request, result)) {
            return false;
        }
        if (!checkIndexConstraints(txn, &shardingState, *request, result)) {
            return false;
        }

        _context.reset(new Client::Context(txn, request->getNS(), false));

        Database* database = _context->db();
        dassert(database);
        _collection = database->getCollection(txn, request->getTargetingNS());
        if (!_collection) {
            WriteUnitOfWork wunit (txn);
            // Implicitly create if it doesn't exist
            _collection = database->createCollection(txn, request->getTargetingNS());
            if (!_collection) {
                result->setError(
                        toWriteError(Status(ErrorCodes::InternalError,
                                            "could not create collection " +
                                            request->getTargetingNS())));
                return false;
            }
            repl::logOp(txn,
                        "c",
                        (database->name() + ".$cmd").c_str(),
                        BSON("create" << nsToCollectionSubstring(request->getTargetingNS())));
            wunit.commit();
        }
        return true;
    }
Exemple #4
0
void NetInfo::adquireLock(const NetInfo* ni) {
    pthread_mutex_lock(&mutex);
    while (hasLock(ni)) pthread_cond_wait(&condVar, &mutex);
    locks.push_back(ni);
    pthread_mutex_unlock(&mutex);
}