本文整理汇总了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;
}
示例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;
}
示例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.
}
示例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;
}
示例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();
}
示例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);
}
示例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();
}
示例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);
}
示例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());
}
示例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 );
}
示例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;
}
}
示例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() );
}
}
示例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);
}
示例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;
}
示例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() );
}