Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

backport of SERVER-5303 yield when fetching a document for migrate

  • Loading branch information...
commit 40049a3869bfc143b30b8c2a3a8f8c26d865d780 1 parent 8f38fc3
@erh erh authored
Showing with 39 additions and 18 deletions.
  1. +39 −18 s/d_migrate.cpp
View
57 s/d_migrate.cpp
@@ -482,32 +482,53 @@ namespace mongo {
while ( 1 ) {
bool filledBuffer = false;
-
- readlock l( _ns );
- Client::Context ctx( _ns );
- scoped_spinlock lk( _trackerLocks );
- set<DiskLoc>::iterator i = _cloneLocs.begin();
- for ( ; i!=_cloneLocs.end(); ++i ) {
- if (tracker.ping()) // should I yield?
- break;
- DiskLoc dl = *i;
- BSONObj o = dl.obj();
+ auto_ptr<RWLockRecursive::Shared> fileLock;
+ Record* recordToTouch = NULL;
- // use the builder size instead of accumulating 'o's size so that we take into consideration
- // the overhead of BSONArray indices
- if ( a.len() + o.objsize() + 1024 > BSONObjMaxUserSize ) {
- filledBuffer = true; // break out of outer while loop
- break;
- }
+ {
+ readlock rlk(_ns);
+ Client::Context ctx( _ns ); // ReadContext?
+ scoped_spinlock lk( _trackerLocks );
+ set<DiskLoc>::iterator i = _cloneLocs.begin();
+ for ( ; i!=_cloneLocs.end(); ++i ) {
+ if (tracker.ping()) // should I yield?
+ break;
- a.append( o );
- }
+ DiskLoc dl = *i;
+ Record* r = dl.rec();
+ if ( ! r->likelyInPhysicalMemory() ) {
+ fileLock.reset( new RWLockRecursive::Shared( MongoFile::mmmutex) );
+ recordToTouch = r;
+ break;
+ }
+
+ BSONObj o = dl.obj();
+
+ // use the builder size instead of accumulating 'o's size so that we take into consideration
+ // the overhead of BSONArray indices
+ if ( a.len() + o.objsize() + 1024 > BSONObjMaxUserSize ) {
+ filledBuffer = true; // break out of outer while loop
+ break;
+ }
+
+ a.append( o );
+ }
_cloneLocs.erase( _cloneLocs.begin() , i );
if ( _cloneLocs.empty() || filledBuffer )
break;
+ }
+ if ( recordToTouch ) {
+ // its safe to touch here because we have a LockMongoFilesShared
+ // we can't do where we get the lock because we would have to unlock the main readlock and tne _trackerLocks
+ // simpler to handle this out there
+ recordToTouch->touch();
+ recordToTouch = NULL;
+ }
+
+
}
result.appendArray( "objects" , a.arr() );
Please sign in to comment.
Something went wrong with that request. Please try again.