@@ -56,17 +56,6 @@ namespace mongo {
5656 BSONObj obj;
5757 };
5858
59- struct Info {
60- Info () : loc(0 ) {}
61- ~Info () {
62- if ( loc && owned ) {
63- delete loc;
64- }
65- }
66- bool owned; // true if loc is a pointer of our creation (and not a pointer into a MMF)
67- OpTime * loc;
68- };
69-
7059 SlaveTracking () : _mutex(" SlaveTracking" ) {
7160 _dirty = false ;
7261 _started = false ;
@@ -81,26 +70,24 @@ namespace mongo {
8170 if ( ! _dirty )
8271 continue ;
8372
84- writelock lk (NS);
85-
8673 list< pair<BSONObj,BSONObj> > todo;
8774
8875 {
8976 scoped_lock mylk (_mutex);
9077
91- for ( map<Ident,Info >::iterator i=_slaves.begin (); i!=_slaves.end (); i++ ) {
78+ for ( map<Ident,OpTime >::iterator i=_slaves.begin (); i!=_slaves.end (); i++ ) {
9279 BSONObjBuilder temp;
93- temp.appendTimestamp ( " syncedTo" , i->second .loc [ 0 ]. asDate () );
80+ temp.appendTimestamp ( " syncedTo" , i->second .asDate () );
9481 todo.push_back ( pair<BSONObj,BSONObj>( i->first .obj .getOwned () ,
9582 BSON ( " $set" << temp.obj () ).getOwned () ) );
9683 }
84+ _dirty = false ;
9785 }
9886
9987 for ( list< pair<BSONObj,BSONObj> >::iterator i=todo.begin (); i!=todo.end (); i++ ) {
10088 db.update ( NS , i->first , i->second , true );
10189 }
10290
103- _dirty = false ;
10491 }
10592 }
10693
@@ -112,42 +99,17 @@ namespace mongo {
11299 void update ( const BSONObj& rid , const string& host , const string& ns , OpTime last ) {
113100 REPLDEBUG ( host << " " << rid << " " << ns << " " << last );
114101
115- scoped_lock mylk (_mutex );
102+ Ident ident (rid,host,ns );
116103
117- #ifdef _DEBUG
118- MongoFileAllowWrites allowWrites;
119- #endif
104+ scoped_lock mylk (_mutex);
120105
121- Ident ident (rid,host,ns) ;
122- Info& i = _slaves[ ident ] ;
106+ _slaves[ ident] = last ;
107+ _dirty = true ;
123108
124109 if (theReplSet && theReplSet->isPrimary ()) {
125110 theReplSet->ghost ->updateSlave (ident.obj [" _id" ].OID (), last);
126111 }
127112
128- if ( i.loc ) {
129- if ( i.owned )
130- i.loc [0 ] = last;
131- else
132- getDur ().setNoJournal (i.loc , &last, sizeof (last));
133- return ;
134- }
135-
136- Lock::assertAtLeastReadLocked (NS);
137-
138- BSONObj res;
139- if ( Helpers::findOne ( NS , ident.obj , res ) ) {
140- assert ( res[" syncedTo" ].type () );
141- i.owned = false ;
142- i.loc = (OpTime*)res[" syncedTo" ].value ();
143- getDur ().setNoJournal (i.loc , &last, sizeof (last));
144- return ;
145- }
146-
147- i.owned = true ;
148- i.loc = new OpTime (last);
149- _dirty = true ;
150-
151113 if ( ! _started ) {
152114 // start background thread here since we definitely need it
153115 _started = true ;
@@ -189,8 +151,8 @@ namespace mongo {
189151
190152 w--; // now this is the # of slaves i need
191153 scoped_lock mylk (_mutex);
192- for ( map<Ident,Info >::iterator i=_slaves.begin (); i!=_slaves.end (); i++) {
193- OpTime s = *( i->second . loc ) ;
154+ for ( map<Ident,OpTime >::iterator i=_slaves.begin (); i!=_slaves.end (); i++) {
155+ OpTime s = i->second ;
194156 if ( s < op ) {
195157 continue ;
196158 }
@@ -208,7 +170,7 @@ namespace mongo {
208170
209171 // need to be careful not to deadlock with this
210172 mutable mongo::mutex _mutex;
211- map<Ident,Info > _slaves;
173+ map<Ident,OpTime > _slaves;
212174 bool _dirty;
213175 bool _started;
214176
0 commit comments