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


C++ DBDirectClient类代码示例

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


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

示例1: logStartup

    void logStartup() {
        BSONObjBuilder toLog;
        stringstream id;
        id << getHostNameCached() << "-" << jsTime();
        toLog.append( "_id", id.str() );
        toLog.append( "hostname", getHostNameCached() );

        toLog.appendTimeT( "startTime", time(0) );
        toLog.append( "startTimeLocal", dateToCtimeString(curTimeMillis64()) );

        toLog.append("cmdLine", serverGlobalParams.parsedOpts);
        toLog.append( "pid", ProcessId::getCurrent().asLongLong() );


        BSONObjBuilder buildinfo( toLog.subobjStart("buildinfo"));
        appendBuildInfo(buildinfo);
        buildinfo.doneFast();

        BSONObj o = toLog.obj();

        Lock::GlobalWrite lk;
        DBDirectClient c;
        const char* name = "local.startup_log";
        c.createCollection( name, 10 * 1024 * 1024, true );
        c.insert( name, o);
    }
开发者ID:BobWeinerJr,项目名称:mongo,代码行数:26,代码来源:db.cpp

示例2: query

    void DocumentSourceCursor::sourceToBson(
        BSONObjBuilder *pBuilder, bool explain) const {

        /* this has no analog in the BSON world, so only allow it for explain */
        if (explain)
        {
            BSONObj bsonObj;
            
            pBuilder->append("query", *pQuery);

            if (pSort.get())
            {
                pBuilder->append("sort", *pSort);
            }

            // construct query for explain
            BSONObjBuilder queryBuilder;
            queryBuilder.append("$query", *pQuery);
            if (pSort.get())
                queryBuilder.append("$orderby", *pSort);
            queryBuilder.append("$explain", 1);
            Query query(queryBuilder.obj());

            DBDirectClient directClient;
            BSONObj explainResult(directClient.findOne(ns, query));

            pBuilder->append("cursor", explainResult);
        }
    }
开发者ID:abhishekkumar1989,项目名称:mongo,代码行数:29,代码来源:document_source_cursor.cpp

示例3: run

        void run(){
            Client::initThread( "slaveTracking" );
            DBDirectClient db;
            while ( ! inShutdown() ){
                sleepsecs( 1 );

                if ( ! _dirty )
                    continue;
                
                writelock lk(NS);

                list< pair<BSONObj,BSONObj> > todo;
                
                {
                    scoped_lock mylk(_mutex);
                    
                    for ( map<Ident,Info>::iterator i=_slaves.begin(); i!=_slaves.end(); i++ ){
                        BSONObjBuilder temp;
                        temp.appendTimestamp( "syncedTo" , i->second.loc[0].asDate() );
                        todo.push_back( pair<BSONObj,BSONObj>( i->first.obj.getOwned() , 
                                                               BSON( "$set" << temp.obj() ).getOwned() ) );
                    }
                    
                    _slaves.clear();
                }

                for ( list< pair<BSONObj,BSONObj> >::iterator i=todo.begin(); i!=todo.end(); i++ ){
                    db.update( NS , i->first , i->second , true );
                }

                _dirty = false;
            }
        }
开发者ID:mikejs,项目名称:mongo,代码行数:33,代码来源:repl_block.cpp

示例4: run

 void run() {
     dblock lk;
     const char *ns = "unittests.cursortests.BtreeCursorTests.MultiRangeGap";
     {
         DBDirectClient c;
         for( int i = 0; i < 10; ++i )
             c.insert( ns, BSON( "a" << i ) );
         for( int i = 100; i < 110; ++i )
             c.insert( ns, BSON( "a" << i ) );
         ASSERT( c.ensureIndex( ns, BSON( "a" << 1 ) ) );
     }
     int v[] = { -50, 2, 40, 60, 109, 200 };
     boost::shared_ptr< FieldRangeVector > frv( vec( v, 6 ) );
     Client::Context ctx( ns );
     scoped_ptr<BtreeCursor> _c( BtreeCursor::make(nsdetails( ns ), 1, nsdetails( ns )->idx(1), frv, 1 ) );
     BtreeCursor &c = *_c.get();
     ASSERT_EQUALS( "BtreeCursor a_1 multi", c.toString() );
     double expected[] = { 0, 1, 2, 109 };
     for( int i = 0; i < 4; ++i ) {
         ASSERT( c.ok() );
         ASSERT_EQUALS( expected[ i ], c.currKey().firstElement().number() );
         c.advance();
     }
     ASSERT( !c.ok() );
 }
开发者ID:Eric-Lu,项目名称:mongo,代码行数:25,代码来源:cursortests.cpp

示例5: TEST

    TEST(DBHelperTests, FindDiskLocsNoIndex) {

        DBDirectClient client;
        client.remove( ns, BSONObj() );
        client.insert( ns, BSON( "_id" << OID::gen() ) );

        long long maxSizeBytes = 1024 * 1024 * 1024;

        set<DiskLoc> locs;
        long long numDocsFound;
        long long estSizeBytes;
        {
            Lock::DBRead lk( ns );
            Client::Context ctx( ns );

            // search invalid index range
            KeyRange range( ns,
                            BSON( "badIndex" << 0 ),
                            BSON( "badIndex" << 10 ),
                            BSON( "badIndex" << 1 ) );

            Status result = Helpers::getLocsInRange( range,
                                                     maxSizeBytes,
                                                     &locs,
                                                     &numDocsFound,
                                                     &estSizeBytes );

            // Make sure we get the right error code
            ASSERT_EQUALS( result.code(), ErrorCodes::IndexNotFound );
            ASSERT_EQUALS( static_cast<long long>( locs.size() ), 0 );
            ASSERT_EQUALS( numDocsFound, 0 );
            ASSERT_EQUALS( estSizeBytes, 0 );
        }
    }
开发者ID:328500920,项目名称:mongo,代码行数:34,代码来源:dbhelper_tests.cpp

示例6: insert

    Status AuthzManagerExternalStateMongod::insert(
            const NamespaceString& collectionName,
            const BSONObj& document,
            const BSONObj& writeConcern) {
        try {
            DBDirectClient client;
            {
                Client::GodScope gs;
                // TODO(spencer): Once we're no longer fully rebuilding the user cache on every
                // change to user data we should remove the global lock and uncomment the
                // WriteContext below
                Lock::GlobalWrite w;
                // Client::WriteContext ctx(userNS);
                client.insert(collectionName, document);
            }

            // Handle write concern
            BSONObjBuilder gleBuilder;
            gleBuilder.append("getLastError", 1);
            gleBuilder.appendElements(writeConcern);
            BSONObj res;
            client.runCommand("admin", gleBuilder.done(), res);
            string errstr = client.getLastErrorString(res);
            if (errstr.empty()) {
                return Status::OK();
            }
            if (res.hasField("code") && res["code"].Int() == ASSERT_ID_DUPKEY) {
                return Status(ErrorCodes::DuplicateKey, errstr);
            }
            return Status(ErrorCodes::UnknownError, errstr);
        } catch (const DBException& e) {
            return e.toStatus();
        }
    }
开发者ID:ryannutley,项目名称:mongo,代码行数:34,代码来源:authz_manager_external_state_d.cpp

示例7: doDBUpgrade

    void doDBUpgrade( const string& dbName, DataFileHeader* h ) {
        static DBDirectClient db;

        if ( h->version == 4 && h->versionMinor == 4 ) {
            verify( PDFILE_VERSION == 4 );
            verify( PDFILE_VERSION_MINOR_22_AND_OLDER == 5 );

            list<string> colls = db.getCollectionNames( dbName );
            for ( list<string>::iterator i=colls.begin(); i!=colls.end(); i++) {
                string c = *i;
                log() << "\t upgrading collection:" << c << endl;
                BSONObj out;
                bool ok = db.runCommand( dbName , BSON( "reIndex" << c.substr( dbName.size() + 1 ) ) , out );
                if ( ! ok ) {
                    log() << "\t\t reindex failed: " << out;
                    fassertFailed( 17393 );
                }
            }

            getDur().writingInt(h->versionMinor) = 5;
            return;
        }

        // do this in the general case
        fassert( 17401, repairDatabase( dbName ) );
    }
开发者ID:BobWeinerJr,项目名称:mongo,代码行数:26,代码来源:db.cpp

示例8: insert

    Status AuthzManagerExternalStateMongod::insert(
            const NamespaceString& collectionName,
            const BSONObj& document,
            const BSONObj& writeConcern) {
        try {
            DBDirectClient client;
            client.insert(collectionName, document);

            // Handle write concern
            BSONObjBuilder gleBuilder;
            gleBuilder.append("getLastError", 1);
            gleBuilder.appendElements(writeConcern);
            BSONObj res;
            client.runCommand("admin", gleBuilder.done(), res);
            string errstr = client.getLastErrorString(res);
            if (errstr.empty()) {
                return Status::OK();
            }
            if (res.hasField("code") && res["code"].Int() == ASSERT_ID_DUPKEY) {
                return Status(ErrorCodes::DuplicateKey, errstr);
            }
            return Status(ErrorCodes::UnknownError, errstr);
        } catch (const DBException& e) {
            return e.toStatus();
        }
    }
开发者ID:Attnaorg,项目名称:mongo,代码行数:26,代码来源:authz_manager_external_state_d.cpp

示例9: remove

    Status AuthzManagerExternalStateMongod::remove(
            const NamespaceString& collectionName,
            const BSONObj& query,
            const BSONObj& writeConcern,
            int* numRemoved) {
        try {
            DBDirectClient client;
            client.remove(collectionName, query);

            // Handle write concern
            BSONObjBuilder gleBuilder;
            gleBuilder.append("getLastError", 1);
            gleBuilder.appendElements(writeConcern);
            BSONObj res;
            client.runCommand("admin", gleBuilder.done(), res);
            string errstr = client.getLastErrorString(res);
            if (!errstr.empty()) {
                return Status(ErrorCodes::UnknownError, errstr);
            }

            *numRemoved = res["n"].numberInt();
            return Status::OK();
        } catch (const DBException& e) {
            return e.toStatus();
        }
    }
开发者ID:Attnaorg,项目名称:mongo,代码行数:26,代码来源:authz_manager_external_state_d.cpp

示例10: run

 void run() {
     dblock lk;
     const char *ns = "unittests.cursortests.BtreeCursorTests.MultiRangeGap";
     {
         DBDirectClient c;
         for( int i = 0; i < 10; ++i )
             c.insert( ns, BSON( "a" << i ) );
         for( int i = 100; i < 110; ++i )
             c.insert( ns, BSON( "a" << i ) );
         ASSERT( c.ensureIndex( ns, BSON( "a" << 1 ) ) );
     }
     BoundList b;
     b.push_back( pair< BSONObj, BSONObj >( BSON( "" << -50 ), BSON( "" << 2 ) ) );
     b.push_back( pair< BSONObj, BSONObj >( BSON( "" << 40 ), BSON( "" << 60 ) ) );
     b.push_back( pair< BSONObj, BSONObj >( BSON( "" << 109 ), BSON( "" << 200 ) ) );
     Client::Context ctx( ns );
     BtreeCursor c( nsdetails( ns ), 1, nsdetails( ns )->idx(1), b, 1 );
     ASSERT_EQUALS( "BtreeCursor a_1 multi", c.toString() );
     double expected[] = { 0, 1, 2, 109 };
     for( int i = 0; i < 4; ++i ) {
         ASSERT( c.ok() );
         ASSERT_EQUALS( expected[ i ], c.currKey().firstElement().number() );
         c.advance();
     }
     ASSERT( !c.ok() );
 }
开发者ID:anagri,项目名称:mongo,代码行数:26,代码来源:cursortests.cpp

示例11: removePrivilegeDocuments

    Status AuthzManagerExternalStateMongod::removePrivilegeDocuments(const string& dbname,
                                                                     const BSONObj& query) {
        try {
            string userNS = dbname + ".system.users";
            DBDirectClient client;
            {
                Client::GodScope gs;
                // TODO(spencer): Once we're no longer fully rebuilding the user cache on every
                // change to user data we should remove the global lock and uncomment the
                // WriteContext below
                Lock::GlobalWrite w;
                // Client::WriteContext ctx(userNS);
                client.remove(userNS, query);
            }

            // 30 second timeout for w:majority
            BSONObj res = client.getLastErrorDetailed(false, false, -1, 30*1000);
            string errstr = client.getLastErrorString(res);
            if (!errstr.empty()) {
                return Status(ErrorCodes::UserModificationFailed, errstr);
            }

            int numUpdated = res["n"].numberInt();
            if (numUpdated == 0) {
                return Status(ErrorCodes::UserNotFound,
                              mongoutils::str::stream() << "No users found on database \"" << dbname
                                      << "\" matching query: " << query.toString());
            }
            return Status::OK();
        } catch (const DBException& e) {
            return e.toStatus();
        }
    }
开发者ID:man27382210,项目名称:mongo,代码行数:33,代码来源:authz_manager_external_state_d.cpp

示例12: LOG

    void ReplSetImpl::assumePrimary() {
        LOG(2) << "replSet assuming primary" << endl;
        verify( iAmPotentiallyHot() );

        // Wait for replication to stop and buffer to be consumed
        LOG(1) << "replSet waiting for replication to finish before becoming primary" << endl;
        replset::BackgroundSync::get()->stopReplicationAndFlushBuffer();

        // Lock here to prevent stepping down & becoming primary from getting interleaved
        Lock::GlobalWrite lk;

        // Make sure that new OpTimes are higher than existing ones even with clock skew
        DBDirectClient c;
        BSONObj lastOp = c.findOne( "local.oplog.rs", Query().sort(reverseNaturalObj), NULL, QueryOption_SlaveOk );
        if ( !lastOp.isEmpty() ) {
            OpTime::setLast( lastOp[ "ts" ].date() );
        }

        // Generate new election unique id
        elect.setElectionId(OID::gen());
        changeState(MemberState::RS_PRIMARY);

        // This must be done after becoming primary but before releasing the write lock. This adds
        // the dropCollection entries for every temp collection to the opLog since we want it to be
        // replicated to secondaries.
        dropAllTempCollections();
    }
开发者ID:LearyLX,项目名称:mongo,代码行数:27,代码来源:rs.cpp

示例13: remove

    Status AuthzManagerExternalStateMongod::remove(
            const NamespaceString& collectionName,
            const BSONObj& query,
            const BSONObj& writeConcern,
            int* numRemoved) {
        try {
            DBDirectClient client;
            {
                Client::GodScope gs;
                // TODO(spencer): Once we're no longer fully rebuilding the user cache on every
                // change to user data we should remove the global lock and uncomment the
                // WriteContext below
                Lock::GlobalWrite w;
                // Client::WriteContext ctx(userNS);
                client.remove(collectionName, query);
            }

            // Handle write concern
            BSONObjBuilder gleBuilder;
            gleBuilder.append("getLastError", 1);
            gleBuilder.appendElements(writeConcern);
            BSONObj res;
            client.runCommand("admin", gleBuilder.done(), res);
            string errstr = client.getLastErrorString(res);
            if (!errstr.empty()) {
                return Status(ErrorCodes::UnknownError, errstr);
            }

            *numRemoved = res["n"].numberInt();
            return Status::OK();
        } catch (const DBException& e) {
            return e.toStatus();
        }
    }
开发者ID:ryannutley,项目名称:mongo,代码行数:34,代码来源:authz_manager_external_state_d.cpp

示例14: doDBUpgrade

    bool doDBUpgrade( const string& dbName , string errmsg , DataFileHeader * h ) {
        static DBDirectClient db;

        if ( h->version == 4 && h->versionMinor == 4 ) {
            verify( PDFILE_VERSION == 4 );
            verify( PDFILE_VERSION_MINOR == 5 );

            list<string> colls = db.getCollectionNames( dbName );
            for ( list<string>::iterator i=colls.begin(); i!=colls.end(); i++) {
                string c = *i;
                log() << "\t upgrading collection:" << c << endl;
                BSONObj out;
                bool ok = db.runCommand( dbName , BSON( "reIndex" << c.substr( dbName.size() + 1 ) ) , out );
                if ( ! ok ) {
                    errmsg = "reindex failed";
                    log() << "\t\t reindex failed: " << out << endl;
                    return false;
                }
            }

            h->versionMinor = 5;
            return true;
        }

        // do this in the general case
        return repairDatabase( dbName.c_str(), errmsg );
    }
开发者ID:opinionaided,项目名称:mongo,代码行数:27,代码来源:db.cpp

示例15: insertPrivilegeDocument

    Status AuthzManagerExternalStateMongod::insertPrivilegeDocument(const string& dbname,
                                                                    const BSONObj& userObj) {
        try {
            string userNS = dbname + ".system.users";
            DBDirectClient client;
            {
                Client::GodScope gs;
                // TODO(spencer): Once we're no longer fully rebuilding the user cache on every
                // change to user data we should remove the global lock and uncomment the
                // WriteContext below
                Lock::GlobalWrite w;
                // Client::WriteContext ctx(userNS);
                client.insert(userNS, userObj);
            }

            // 30 second timeout for w:majority
            BSONObj res = client.getLastErrorDetailed(false, false, -1, 30*1000);
            string errstr = client.getLastErrorString(res);
            if (errstr.empty()) {
                return Status::OK();
            }
            if (res.hasField("code") && res["code"].Int() == ASSERT_ID_DUPKEY) {
                return Status(ErrorCodes::DuplicateKey,
                              mongoutils::str::stream() << "User \"" << userObj["user"].String() <<
                                     "\" already exists on database \"" << dbname << "\"");
            }
            return Status(ErrorCodes::UserModificationFailed, errstr);
        } catch (const DBException& e) {
            return e.toStatus();
        }
    }
开发者ID:man27382210,项目名称:mongo,代码行数:31,代码来源:authz_manager_external_state_d.cpp


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