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


C++ BSONObjBuilder::appendTimestamp方法代码示例

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


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

示例1: run

        bool run(const string& , BSONObj& cmdObj, int, string& errmsg, BSONObjBuilder& result, bool) {
            string ns = cmdObj["getShardVersion"].valuestrsafe();
            if ( ns.size() == 0 ) {
                errmsg = "need to specify full namespace";
                return false;
            }

            result.append( "configServer" , shardingState.getConfigServer() );

            result.appendTimestamp( "global" , shardingState.getVersion(ns).toLong() );

            ShardedConnectionInfo* info = ShardedConnectionInfo::get( false );
            result.appendBool( "inShardedMode" , info != 0 );
            if ( info )
                result.appendTimestamp( "mine" , info->getVersion(ns).toLong() );
            else
                result.appendTimestamp( "mine" , 0 );

            if ( cmdObj["fullMetadata"].trueValue() ) {
                CollectionMetadataPtr metadata = shardingState.getCollectionMetadata( ns );
                if ( metadata ) result.append( "metadata", metadata->toBSON() );
                else result.append( "metadata", BSONObj() );
            }

            return true;
        }
开发者ID:GitSullied,项目名称:mongo,代码行数:26,代码来源:d_state.cpp

示例2: run

        void run(){
            Scope * s = globalScriptEngine->createScope();

            BSONObjBuilder b;
            b.appendTimestamp( "a" , 123456789 );
            b.appendMinKey( "b" );
            b.appendMaxKey( "c" );
            b.appendTimestamp( "d" , 1234000 , 9876 );
            

            {
                BSONObj t = b.done();
                ASSERT_EQUALS( 1234000U , t["d"].timestampTime() );
                ASSERT_EQUALS( 9876U , t["d"].timestampInc() );
            }

            s->setObject( "z" , b.obj() );
            
            ASSERT( s->invoke( "y = { a : z.a , b : z.b , c : z.c , d: z.d }" , BSONObj() ) == 0 );

            BSONObj out = s->getObject( "y" );
            ASSERT_EQUALS( Timestamp , out["a"].type() );
            ASSERT_EQUALS( MinKey , out["b"].type() );
            ASSERT_EQUALS( MaxKey , out["c"].type() );
            ASSERT_EQUALS( Timestamp , out["d"].type() );

            ASSERT_EQUALS( 9876U , out["d"].timestampInc() );
            ASSERT_EQUALS( 1234000U , out["d"].timestampTime() );
            ASSERT_EQUALS( 123456789U , out["a"].date() );


            delete s;
        }
开发者ID:hashrocket,项目名称:mongo,代码行数:33,代码来源:jstests.cpp

示例3: _summarizeStatus

    void ReplSetImpl::_summarizeStatus(BSONObjBuilder& b) const {
        vector<BSONObj> v;

        const Member *_self = this->_self;
        assert( _self );

        // add self
        {
            BSONObjBuilder bb;
            bb.append("_id", (int) _self->id());
            bb.append("name", _self->fullName());
            bb.append("health", 1.0);
            bb.append("state", (int) box.getState().s);
            bb.append("stateStr", box.getState().toString());
            bb.appendTimestamp("optime", lastOpTimeWritten.asDate());
            bb.appendDate("optimeDate", lastOpTimeWritten.getSecs() * 1000LL);
            string s = _self->lhb();
            if( !s.empty() )
                bb.append("errmsg", s);
            bb.append("self", true);
            v.push_back(bb.obj());
        }

        Member *m =_members.head();
        while( m ) {
            BSONObjBuilder bb;
            bb.append("_id", (int) m->id());
            bb.append("name", m->fullName());
            double h = m->hbinfo().health;
            bb.append("health", h);
            bb.append("state", (int) m->state().s);
            if( h == 0 ) {
                // if we can't connect the state info is from the past and could be confusing to show
                bb.append("stateStr", "(not reachable/healthy)");
            }
            else {
                bb.append("stateStr", m->state().toString());
            }
            bb.append("uptime", (unsigned) (m->hbinfo().upSince ? (time(0)-m->hbinfo().upSince) : 0));
            bb.appendTimestamp("optime", m->hbinfo().opTime.asDate());
            bb.appendDate("optimeDate", m->hbinfo().opTime.getSecs() * 1000LL);
            bb.appendTimeT("lastHeartbeat", m->hbinfo().lastHeartbeat);
            bb.append("ping", m->hbinfo().ping);
            string s = m->lhb();
            if( !s.empty() )
                bb.append("errmsg", s);
            v.push_back(bb.obj());
            m = m->next();
        }
        sort(v.begin(), v.end());
        b.append("set", name());
        b.appendTimeT("date", time(0));
        b.append("myState", box.getState().s);
        if (_currentSyncTarget) {
            b.append("syncingTo", _currentSyncTarget->fullName());
        }
        b.append("members", v);
        if( replSetBlind )
            b.append("blind",true); // to avoid confusion if set...normally never set except for testing.
    }
开发者ID:kzys,项目名称:mongo,代码行数:60,代码来源:health.cpp

示例4: serialize

    void Chunk::serialize(BSONObjBuilder& to){
        if ( _lastmod )
            to.appendTimestamp( "lastmod" , _lastmod );
        else 
            to.appendTimestamp( "lastmod" );

        to << "ns" << _ns;
        to << "min" << _min;
        to << "max" << _max;
        to << "shard" << _shard;
    }
开发者ID:phildarnowsky,项目名称:mongo,代码行数:11,代码来源:chunk.cpp

示例5: generateSection

        BSONObj generateSection(const BSONElement& configElement) const {
            if (!theReplSet)
                return BSONObj();

            BSONObjBuilder result;
            result.appendTimestamp("latestOptime", theReplSet->lastOpTimeWritten.asDate());
            result.appendTimestamp("earliestOptime",
                                   theReplSet->getEarliestOpTimeWritten().asDate());

            return result.obj();
        }
开发者ID:BeyondMyself,项目名称:mongo,代码行数:11,代码来源:repl_settings.cpp

示例6: tailingQueryGTE

 void OplogReader::tailingQueryGTE(const char *ns, OpTime optime, const BSONObj* fields ) {
     BSONObjBuilder gte;
     gte.appendTimestamp("$gte", optime.asDate());
     BSONObjBuilder query;
     query.append("ts", gte.done());
     tailingQuery(ns, query.done(), fields);
 }
开发者ID:lufeng1102,项目名称:mongo,代码行数:7,代码来源:oplogreader.cpp

示例7: run

        void run() {

            OpTime o;

            {
                mongo::mutex::scoped_lock lk2(OpTime::m);
                o = OpTime::now(lk2);
            }

            BSONObjBuilder b;
            b.append("ns","dummy");
            b.appendTimestamp("ts", o.asLL());
            BSONObj obj = b.obj();
            MockInitialSync mock;

            // all three should succeed
            std::vector<BSONObj> ops;
            ops.push_back(obj);
            replset::multiInitialSyncApply(ops, &mock);

            mock.failOnStep = MockInitialSync::FAIL_FIRST_APPLY;
            replset::multiInitialSyncApply(ops, &mock);

            mock.retry = false;
            replset::multiInitialSyncApply(ops, &mock);

            drop();
        }
开发者ID:Irrelon,项目名称:mongodb-2.2-objectrocket,代码行数:28,代码来源:replsettests.cpp

示例8: run

        void run() {
            writelock lk("");

            OpTime o1 = OpTime::now();
            OpTime o2 = OpTime::now();

            BSONObjBuilder b;
            b.appendTimestamp("ts", o2.asLL());
            BSONObj obj = b.obj();

            MockInitialSync mock;

            // all three should succeed
            mock.applyOp(obj, o1);

            mock.failOnStep = MockInitialSync::FAIL_FIRST_APPLY;
            mock.applyOp(obj, o1);

            mock.retry = false;
            mock.applyOp(obj, o1);

            // force failure
            MockInitialSync mock2;
            mock2.failOnStep = MockInitialSync::FAIL_BOTH_APPLY;

            ASSERT_THROWS(mock2.applyOp(obj, o2), UserException);
        }
开发者ID:dibiasio,项目名称:mongo,代码行数:27,代码来源:replsettests.cpp

示例9: addOp

        void addOp(const string& op, BSONObj o, BSONObj* o2 = NULL, const char* coll = NULL,
                   int version = 0) {
            OpTime ts(getNextGlobalOptime());

            BSONObjBuilder b;
            b.appendTimestamp("ts", ts.asLL());
            if (version != 0) {
                b.append("v", version);
            }
            b.append("op", op);
            b.append("o", o);

            if (o2) {
                b.append("o2", *o2);
            }

            if (coll) {
                b.append("ns", coll);
            }
            else {
                b.append("ns", ns());
            }

            _bgsync->addDoc(b.done());
        }
开发者ID:AndrewCEmil,项目名称:mongo,代码行数:25,代码来源:replsettests.cpp

示例10: run

    void run() {
        BSONObj o;
        {
            BSONObjBuilder b;
            b.appendTimestamp( "a" );
            b.appendTimestamp( "b" );
            b.append( "_id", 1 );
            o = b.obj();
        }

        BSONObj fixed = fixDocumentForInsert( o ).getValue();
        ASSERT_EQUALS( 3, fixed.nFields() );
        ASSERT( fixed.firstElement().fieldNameStringData() == "_id" );
        ASSERT( fixed.firstElement().number() == 1 );

        BSONElement a = fixed["a"];
        ASSERT( o["a"].type() == Timestamp );
        ASSERT( o["a"].timestampValue() == 0 );
        ASSERT( a.type() == Timestamp );
        ASSERT( a.timestampValue() > 0 );

        BSONElement b = fixed["b"];
        ASSERT( o["b"].type() == Timestamp );
        ASSERT( o["b"].timestampValue() == 0 );
        ASSERT( b.type() == Timestamp );
        ASSERT( b.timestampValue() > 0 );
    }
开发者ID:kingfs,项目名称:tokumxse,代码行数:27,代码来源:pdfiletests.cpp

示例11: 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

示例12: appendLastOp

 void Client::appendLastOp( BSONObjBuilder& b ) const {
     // _lastOp is never set if replication is off
     if (repl::getGlobalReplicationCoordinator()->getReplicationMode() ==
             repl::ReplicationCoordinator::modeReplSet || !_lastOp.isNull()) {
         b.appendTimestamp( "lastOp" , _lastOp.asDate() );
     }
 }
开发者ID:amyvmiwei,项目名称:mongo,代码行数:7,代码来源:client.cpp

示例13: run

        void run() {
            Lock::GlobalWrite lk;

            OpTime o1,o2;

            {
                mongo::mutex::scoped_lock lk2(OpTime::m);
                o1 = OpTime::now(lk2);
                o2 = OpTime::now(lk2);
            }

            BSONObjBuilder b;
            b.appendTimestamp("ts", o2.asLL());
            BSONObj obj = b.obj();

            MockInitialSync mock;

            // all three should succeed
            mock.applyOp(obj, o1);

            mock.failOnStep = MockInitialSync::FAIL_FIRST_APPLY;
            mock.applyOp(obj, o1);

            mock.retry = false;
            mock.applyOp(obj, o1);

            // force failure
            MockInitialSync mock2;
            mock2.failOnStep = MockInitialSync::FAIL_BOTH_APPLY;

            ASSERT_THROWS(mock2.applyOp(obj, o2), UserException);
        }
开发者ID:Desartstudio,项目名称:mongo-nonx86,代码行数:32,代码来源:replsettests.cpp

示例14: run

        bool run(const char *cmdns, BSONObj& cmdObj, string& errmsg, BSONObjBuilder& result, bool){
            string ns = cmdObj["getShardVersion"].valuestrsafe();
            if ( ns.size() == 0 ){
                errmsg = "need to speciy fully namespace";
                return false;
            }
            
            result.append( "configServer" , shardConfigServer.c_str() );

            result.appendTimestamp( "global" , globalVersions[ns] );
            if ( clientShardVersions.get() )
                result.appendTimestamp( "mine" , (*clientShardVersions.get())[ns] );
            else 
                result.appendTimestamp( "mine" , 0 );
            
            return true;
        }
开发者ID:whachoe,项目名称:mongo,代码行数:17,代码来源:d_logic.cpp

示例15: run

 void run() {
     BSONObjBuilder b;
     b.appendTimestamp( "a" );
     BSONObj o = b.done();
     ASSERT( 0 == o.getField( "a" ).date() );
     theDataFileMgr.insert( ns(), o );
     ASSERT( 0 != o.getField( "a" ).date() );
 }
开发者ID:catap,项目名称:mongo,代码行数:8,代码来源:pdfiletests.cpp


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