diff options
Diffstat (limited to 's/d_migrate.cpp')
-rw-r--r-- | s/d_migrate.cpp | 57 |
1 files changed, 39 insertions, 18 deletions
diff --git a/s/d_migrate.cpp b/s/d_migrate.cpp index 731761f..918dd86 100644 --- a/s/d_migrate.cpp +++ b/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() ); |