当前位置: 首页>>代码示例>>C++>>正文


C++ dbHolder函数代码示例

本文整理汇总了C++中dbHolder函数的典型用法代码示例。如果您正苦于以下问题:C++ dbHolder函数的具体用法?C++ dbHolder怎么用?C++ dbHolder使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了dbHolder函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: _dbLock

AutoGetOrCreateDb::AutoGetOrCreateDb(OperationContext* opCtx, StringData ns, LockMode mode)
    : _dbLock(opCtx, ns, mode), _db(dbHolder().get(opCtx, ns)) {
    invariant(mode == MODE_IX || mode == MODE_X);
    _justCreated = false;
    // If the database didn't exist, relock in MODE_X
    if (_db == NULL) {
        if (mode != MODE_X) {
            _dbLock.relockWithMode(MODE_X);
        }
        _db = dbHolder().openDb(opCtx, ns);
        _justCreated = true;
    }
}
开发者ID:mpobrien,项目名称:mongo,代码行数:13,代码来源:db_raii.cpp

示例2: profile

void profile(OperationContext* txn, const Client& c, int op, CurOp& currentOp) {
    // initialize with 1kb to start, to avoid realloc later
    // doing this outside the dblock to improve performance
    BufBuilder profileBufBuilder(1024);

    try {
        // NOTE: It's kind of weird that we lock the op's namespace, but have to for now since
        // we're sometimes inside the lock already
        Lock::DBWrite lk( currentOp.getNS() );
        if (dbHolder()._isLoaded(nsToDatabase(currentOp.getNS()), storageGlobalParams.dbpath)) {
            Client::Context cx(currentOp.getNS(), storageGlobalParams.dbpath, false);
            _profile(txn, c, cx.db(),
                     currentOp, profileBufBuilder);
        }
        else {
            mongo::log() << "note: not profiling because db went away - probably a close on: "
                         << currentOp.getNS() << endl;
        }
    }
    catch (const AssertionException& assertionEx) {
        warning() << "Caught Assertion while trying to profile " << opToString(op)
                  << " against " << currentOp.getNS()
                  << ": " << assertionEx.toString() << endl;
    }
}
开发者ID:jewkesy,项目名称:mongo,代码行数:25,代码来源:introspect.cpp

示例3: getGlobalEnvironment

    /*static*/
    string Database::duplicateUncasedName(const string &name, set< string > *duplicates) {
        if ( duplicates ) {
            duplicates->clear();
        }

        vector<string> others;
        StorageEngine* storageEngine = getGlobalEnvironment()->getGlobalStorageEngine();
        storageEngine->listDatabases(&others);

        set<string> allShortNames;
        dbHolder().getAllShortNames(allShortNames);

        others.insert( others.end(), allShortNames.begin(), allShortNames.end() );

        for ( unsigned i=0; i<others.size(); i++ ) {

            if ( strcasecmp( others[i].c_str() , name.c_str() ) )
                continue;

            if ( strcmp( others[i].c_str() , name.c_str() ) == 0 )
                continue;

            if ( duplicates ) {
                duplicates->insert( others[i] );
            } else {
                return others[i];
            }
        }
        if ( duplicates ) {
            return duplicates->empty() ? "" : *duplicates->begin();
        }
        return "";
    }
开发者ID:maxkeller,项目名称:mongo,代码行数:34,代码来源:database.cpp

示例4: dropAllDatabasesExceptLocal

void dropAllDatabasesExceptLocal(OperationContext* txn) {
    ScopedTransaction transaction(txn, MODE_X);
    Lock::GlobalWrite lk(txn->lockState());

    vector<string> n;
    StorageEngine* storageEngine = getGlobalServiceContext()->getGlobalStorageEngine();
    storageEngine->listDatabases(&n);

    if (n.size() == 0)
        return;
    log() << "dropAllDatabasesExceptLocal " << n.size();

    repl::getGlobalReplicationCoordinator()->dropAllSnapshots();
    for (vector<string>::iterator i = n.begin(); i != n.end(); i++) {
        if (*i != "local") {
            MONGO_WRITE_CONFLICT_RETRY_LOOP_BEGIN {
                Database* db = dbHolder().get(txn, *i);
                // This is needed since dropDatabase can't be rolled back.
                // This is safe be replaced by "invariant(db);dropDatabase(txn, db);" once fixed
                if (db == nullptr) {
                    log() << "database disappeared after listDatabases but before drop: " << *i;
                } else {
                    Database::dropDatabase(txn, db);
                }
            }
            MONGO_WRITE_CONFLICT_RETRY_LOOP_END(txn, "dropAllDatabasesExceptLocal", *i);
        }
    }
开发者ID:judahschvimer,项目名称:mongo,代码行数:28,代码来源:database.cpp

示例5: getDatabaseNames

/*static*/
string Database::duplicateUncasedName( bool inholderlock, const string &name, const string &path, set< string > *duplicates ) {
    Lock::assertAtLeastReadLocked(name);

    if ( duplicates ) {
        duplicates->clear();
    }

    vector<string> others;
    getDatabaseNames( others , path );

    set<string> allShortNames;
    dbHolder().getAllShortNames( allShortNames );

    others.insert( others.end(), allShortNames.begin(), allShortNames.end() );

    for ( unsigned i=0; i<others.size(); i++ ) {

        if ( strcasecmp( others[i].c_str() , name.c_str() ) )
            continue;

        if ( strcmp( others[i].c_str() , name.c_str() ) == 0 )
            continue;

        if ( duplicates ) {
            duplicates->insert( others[i] );
        } else {
            return others[i];
        }
    }
    if ( duplicates ) {
        return duplicates->empty() ? "" : *duplicates->begin();
    }
    return "";
}
开发者ID:kevleyski,项目名称:mongo,代码行数:35,代码来源:database.cpp

示例6: LOG

    void IndexBuilder::run() {
        Client::initThread(name().c_str());
        LOG(2) << "IndexBuilder building index " << _index;

        OperationContextImpl txn;

        Lock::ParallelBatchWriterMode::iAmABatchParticipant(txn.lockState());

        txn.getClient()->getAuthorizationSession()->grantInternalAuthorization();

        txn.getCurOp()->reset(HostAndPort(), dbInsert);
        NamespaceString ns(_index["ns"].String());

        ScopedTransaction transaction(&txn, MODE_IX);
        Lock::DBLock dlk(txn.lockState(), ns.db(), MODE_X);
        Client::Context ctx(&txn, ns.getSystemIndexesCollection());

        Database* db = dbHolder().get(&txn, ns.db().toString());

        Status status = _build(&txn, db, true, &dlk);
        if ( !status.isOK() ) {
            error() << "IndexBuilder could not build index: " << status.toString();
            fassert(28555, ErrorCodes::isInterruption(status.code()));
        }

        txn.getClient()->shutdown();
    }
开发者ID:3rf,项目名称:mongo,代码行数:27,代码来源:index_builder.cpp

示例7: massert

    void AutoGetCollectionForRead::_init() {
        massert(28535, "need a non-empty collection name", !_nss.coll().empty());

        // TODO: Client::Context legacy, needs to be removed
        _txn->getCurOp()->ensureStarted();
        _txn->getCurOp()->setNS(_nss.toString());

        // Lock both the DB and the collection (DB is locked in the constructor), because this is
        // necessary in order to to shard version checking.
        const ResourceId resId(RESOURCE_COLLECTION, _nss);
        const LockMode collLockMode = supportsDocLocking() ? MODE_IS : MODE_S;

        invariant(LOCK_OK == _txn->lockState()->lock(resId, collLockMode));

        // Shard version check needs to be performed under the collection lock
        ensureShardVersionOKOrThrow(_nss);

        // At this point, we are locked in shared mode for the database by the DB lock in the
        // constructor, so it is safe to load the DB pointer.
        _db = dbHolder().get(_txn, _nss.db());
        if (_db != NULL) {
            // TODO: Client::Context legacy, needs to be removed
            _txn->getCurOp()->enter(_nss.toString().c_str(), _db->getProfilingLevel());

            _coll = _db->getCollection(_txn, _nss);
        }
    }
开发者ID:FranckBel,项目名称:mongo,代码行数:27,代码来源:client.cpp

示例8: profile

    void profile(OperationContext* txn, const Client& c, int op, CurOp& currentOp) {
        // initialize with 1kb to start, to avoid realloc later
        // doing this outside the dblock to improve performance
        BufBuilder profileBufBuilder(1024);

        try {
            // NOTE: It's kind of weird that we lock the op's namespace, but have to for now since
            // we're sometimes inside the lock already
            Lock::DBWrite lk(txn->lockState(), currentOp.getNS() );
            if (dbHolder().get(txn, nsToDatabase(currentOp.getNS())) != NULL) {
                // We are ok with the profiling happening in a different WUOW from the actual op.
                WriteUnitOfWork wunit(txn->recoveryUnit());
                Client::Context cx(txn, currentOp.getNS(), false);
                _profile(txn, c, cx.db(), currentOp, profileBufBuilder);
                wunit.commit();
            }
            else {
                mongo::log() << "note: not profiling because db went away - probably a close on: "
                             << currentOp.getNS() << endl;
            }
        }
        catch (const AssertionException& assertionEx) {
            warning() << "Caught Assertion while trying to profile " << opToString(op)
                      << " against " << currentOp.getNS()
                      << ": " << assertionEx.toString() << endl;
        }
    }
开发者ID:Benguang,项目名称:mongo,代码行数:27,代码来源:introspect.cpp

示例9: dbHolder

/*static*/
string Database::duplicateUncasedName(const string& name, set<string>* duplicates) {
    if (duplicates) {
        duplicates->clear();
    }

    set<string> allShortNames;
    dbHolder().getAllShortNames(allShortNames);

    for (const auto& dbname : allShortNames) {
        if (strcasecmp(dbname.c_str(), name.c_str()))
            continue;

        if (strcmp(dbname.c_str(), name.c_str()) == 0)
            continue;

        if (duplicates) {
            duplicates->insert(dbname);
        } else {
            return dbname;
        }
    }
    if (duplicates) {
        return duplicates->empty() ? "" : *duplicates->begin();
    }
    return "";
}
开发者ID:judahschvimer,项目名称:mongo,代码行数:27,代码来源:database.cpp

示例10: run

        bool run(OperationContext* txn,
                 const string& dbname,
                 BSONObj& jsobj,
                 int,
                 string& errmsg,
                 BSONObjBuilder& result,
                 bool /*fromRepl*/) {

            Lock::DBRead lk( txn->lockState(), dbname );

            const Database* d = dbHolder().get( txn, dbname );
            const DatabaseCatalogEntry* dbEntry = NULL;

            list<string> names;
            if ( d ) {
                dbEntry = d->getDatabaseCatalogEntry();
                dbEntry->getCollectionNamespaces( &names );
                names.sort();
            }

            scoped_ptr<MatchExpression> matcher;
            if ( jsobj["filter"].isABSONObj() ) {
                StatusWithMatchExpression parsed =
                    MatchExpressionParser::parse( jsobj["filter"].Obj() );
                if ( !parsed.isOK() ) {
                    return appendCommandStatus( result, parsed.getStatus() );
                }
                matcher.reset( parsed.getValue() );
            }

            BSONArrayBuilder arr;

            for ( list<string>::const_iterator i = names.begin(); i != names.end(); ++i ) {
                string ns = *i;

                StringData collection = nsToCollectionSubstring( ns );
                if ( collection == "system.namespaces" ) {
                    continue;
                }

                BSONObjBuilder b;
                b.append( "name", collection );

                CollectionOptions options =
                    dbEntry->getCollectionCatalogEntry( txn, ns )->getCollectionOptions(txn);
                b.append( "options", options.toBSON() );

                BSONObj maybe = b.obj();
                if ( matcher && !matcher->matchesBSON( maybe ) ) {
                    continue;
                }

                arr.append( maybe );
            }

            result.append( "collections", arr.arr() );

            return true;
        }
开发者ID:Benguang,项目名称:mongo,代码行数:59,代码来源:list_collections.cpp

示例11: dbHolder

    void Client::Context::_finishInit() {
        _db = dbHolder().openDb(_txn, _ns, &_justCreated);
        invariant(_db);

        if( _doVersion ) checkNotStale();

        _client->_curOp->enter(_ns.c_str(), _db->getProfilingLevel());
    }
开发者ID:FranckBel,项目名称:mongo,代码行数:8,代码来源:client.cpp

示例12: dbHolder

    void Client::Context::_finishInit() {
        _db = dbHolder().getOrCreate(_txn, _ns, _justCreated);
        invariant(_db);

        if( _doVersion ) checkNotStale();

        _client->_curOp->enter( this );
    }
开发者ID:amyvmiwei,项目名称:mongo,代码行数:8,代码来源:client.cpp

示例13: verify

    void TxnCompleteHooksImpl::noteTxnAbortedFileOps(const set<string> &namespaces, const set<string> &dbs) {
        for (set<string>::const_iterator i = namespaces.begin(); i != namespaces.end(); i++) {
            const char *ns = i->c_str();

            // We cannot be holding a read lock at this point, since we're in one of two situations:
            // - Single-statement txn is aborting. If it did fileops, it had to hold a write lock,
            //   and therefore it still is.
            // - Multi-statement txn is aborting. The only way to do this is through a command that
            //   takes no lock, therefore we're not read locked.
            verify(!Lock::isReadLocked());

            // If something is already write locked we must be in the single-statement case, so
            // assert that the write locked namespace is this one.
            if (Lock::somethingWriteLocked()) {
                verify(Lock::isWriteLocked(ns));
            }

            // The ydb requires that a txn closes any dictionaries it created beforeaborting.
            // Hold a write lock while trying to close the namespace in the nsindex.
            Lock::DBWrite lk(ns);
            if (dbHolder().__isLoaded(ns, dbpath)) {
                scoped_ptr<Client::Context> ctx(cc().getContext() == NULL ?
                                                new Client::Context(ns) : NULL);
                // Pass aborting = true to close_ns(), which hints to the implementation
                // that the calling transaction is about to abort.
                (void) nsindex(ns)->close_ns(ns, true);
            }
        }

        for (set<string>::const_iterator it = dbs.begin(); it != dbs.end(); ++it) {
            const string &db = *it;

            // The same locking rules above apply here.
            verify(!Lock::isReadLocked());
            if (Lock::somethingWriteLocked()) {
                verify(Lock::isWriteLocked(db));
            }

            Lock::DBWrite lk(db);
            if (dbHolder().__isLoaded(db, dbpath)) {
                scoped_ptr<Client::Context> ctx(cc().getContext() == NULL ?
                                                new Client::Context(db) : NULL);
                nsindex(db.c_str())->rollbackCreate();
            }
        }
    }
开发者ID:aberg001,项目名称:mongo,代码行数:46,代码来源:txn_complete_hooks.cpp

示例14: lockedDoProfile

 // Profile the current op in an alternate transaction
 void lockedDoProfile(const Client& c, int op, CurOp& currentOp) {
     if ( dbHolder().__isLoaded( nsToDatabase( currentOp.getNS() ) , dbpath ) ) {
         Client::Context ctx(currentOp.getNS(), dbpath);
         Client::AlternateTransactionStack altStack;
         Client::Transaction txn(DB_SERIALIZABLE);
         profile(c, op, currentOp);
         txn.commit();
     }
 }
开发者ID:nvdnkpr,项目名称:mongo,代码行数:10,代码来源:instance.cpp

示例15: dbHolder

    void Client::Context::_finishInit() {
        OperationContextImpl txn; // TODO get rid of this once reads require transactions
        _db = dbHolder().getOrCreate(&txn, _ns, _justCreated);
        invariant(_db);

        if( _doVersion ) checkNotStale();

        _client->_curOp->enter( this );
    }
开发者ID:Miniconi,项目名称:mongo,代码行数:9,代码来源:client.cpp


注:本文中的dbHolder函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。