void update( const BSONObj& rid , const string& host , const string& ns , OpTime last ){ scoped_lock mylk(_mutex); Ident ident(rid,host,ns); Info& i = _slaves[ ident ]; if ( i.loc ){ i.loc[0] = last; return; } dbMutex.assertAtLeastReadLocked(); BSONObj res; if ( Helpers::findOne( NS , ident.obj , res ) ){ assert( res["syncedTo"].type() ); i.owned = false; i.loc = (OpTime*)res["syncedTo"].value(); i.loc[0] = last; return; } i.owned = true; i.loc = new OpTime[1]; i.loc[0] = last; _dirty = true; if ( ! _started ){ _started = true; go(); } }
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; } }
bool update( const BSONObj& rid , const BSONObj config , const string& ns , OpTime last ) { REPLDEBUG( config << " " << rid << " " << ns << " " << last ); Ident ident(rid, config, ns); scoped_lock mylk(_mutex); if (last > _slaves[ident]) { _slaves[ident] = last; _dirty = true; if (theReplSet && theReplSet->isPrimary()) { if (!theReplSet->ghost->updateSlave(ident.obj["_id"].OID(), last)) { return false; } } if ( ! _started ) { // start background thread here since we definitely need it _started = true; go(); } _threadsWaitingForReplication.notify_all(); } return true; }
bool opReplicatedEnough( OpTime op , int w ){ if ( w <= 1 ) return true; w--; // now this is the # of slaves i need scoped_lock mylk(_mutex); for ( map<Ident,Info>::iterator i=_slaves.begin(); i!=_slaves.end(); i++){ OpTime s = *(i->second.loc); if ( s < op ){ continue; } if ( --w == 0 ) return true; } return w <= 0; }
void update( const BSONObj& rid , const BSONObj config , const string& ns , GTID gtid ) { REPLDEBUG( config << " " << rid << " " << ns << " " << last ); Ident ident(rid, config, ns); scoped_lock mylk(_mutex); _slaves[ident] = gtid; if (theReplSet && theReplSet->isPrimary()) { theReplSet->ghost->updateSlave(ident.obj["_id"].OID(), gtid); } _threadsWaitingForReplication.notify_all(); }
void update( const BSONObj& rid , const string& host , const string& ns , OpTime last ) { REPLDEBUG( host << " " << rid << " " << ns << " " << last ); scoped_lock mylk(_mutex); #ifdef _DEBUG MongoFileAllowWrites allowWrites; #endif Ident ident(rid,host,ns); Info& i = _slaves[ ident ]; if (theReplSet && theReplSet->isPrimary()) { theReplSet->ghost->updateSlave(ident.obj["_id"].OID(), last); } if ( i.loc ) { if( i.owned ) i.loc[0] = last; else getDur().setNoJournal(i.loc, &last, sizeof(last)); return; } dbMutex.assertAtLeastReadLocked(); BSONObj res; if ( Helpers::findOne( NS , ident.obj , res ) ) { assert( res["syncedTo"].type() ); i.owned = false; i.loc = (OpTime*)res["syncedTo"].value(); getDur().setNoJournal(i.loc, &last, sizeof(last)); return; } i.owned = true; i.loc = new OpTime(last); _dirty = true; if ( ! _started ) { // start background thread here since we definitely need it _started = true; go(); } }
void update( const BSONObj& rid , const string& host , const string& ns , OpTime last ) { REPLDEBUG( host << " " << rid << " " << ns << " " << last ); Ident ident(rid,host,ns); scoped_lock mylk(_mutex); _slaves[ident] = last; _dirty = true; if (theReplSet && theReplSet->isPrimary()) { theReplSet->ghost->updateSlave(ident.obj["_id"].OID(), last); } if ( ! _started ) { // start background thread here since we definitely need it _started = true; go(); } }
void update( const BSONObj& rid , const string& host , const string& ns , OpTime last ){ REPLDEBUG( host << " " << rid << " " << ns << " " << last ); scoped_lock mylk(_mutex); #ifdef _DEBUG MongoFileAllowWrites allowWrites; #endif Ident ident(rid,host,ns); Info& i = _slaves[ ident ]; if ( i.loc ){ i.loc[0] = last; return; } dbMutex.assertAtLeastReadLocked(); BSONObj res; if ( Helpers::findOne( NS , ident.obj , res ) ){ assert( res["syncedTo"].type() ); i.owned = false; i.loc = (OpTime*)res["syncedTo"].value(); i.loc[0] = last; return; } i.owned = true; i.loc = new OpTime[1]; i.loc[0] = last; _dirty = true; if ( ! _started ){ // start background thread here since we definitely need it _started = true; go(); } }
void reset() { if ( _currentlyUpdatingCache ) return; scoped_lock mylk(_mutex); _slaves.clear(); }
void reset() { scoped_lock mylk(_mutex); _slaves.clear(); }