diff options
author | Eliot Horowitz <eliot@10gen.com> | 2011-05-18 12:55:38 -0400 |
---|---|---|
committer | Eliot Horowitz <eliot@10gen.com> | 2011-05-18 12:56:11 -0400 |
commit | a1ecdb63772de668e23feca39f9713b735e8fee4 (patch) | |
tree | d543a4ae777142046fd9545801f485c2752b30af | |
parent | a852279bc770ea0594bc799ef14ddca4572944a9 (diff) | |
download | mongo-a1ecdb63772de668e23feca39f9713b735e8fee4.tar.gz |
added a spinlock around _cloneLocs
-rw-r--r-- | s/d_migrate.cpp | 23 |
1 files changed, 19 insertions, 4 deletions
diff --git a/s/d_migrate.cpp b/s/d_migrate.cpp index bc897e7b87d..ff4842ed869 100644 --- a/s/d_migrate.cpp +++ b/s/d_migrate.cpp @@ -273,9 +273,12 @@ namespace mongo { void done() { readlock lk( _ns ); - _deleted.clear(); - _reload.clear(); - _cloneLocs.clear(); + { + scoped_spinlock lk( _trackerLocks ); + _deleted.clear(); + _reload.clear(); + _cloneLocs.clear(); + } _memoryUsed = 0; scoped_lock l(_m); @@ -447,6 +450,8 @@ namespace mongo { maxRecsWhenFull = numeric_limits<long long>::max(); } + scoped_spinlock lk( _trackerLocks ); + // do a full traversal of the chunk and don't stop even if we think it is a large chunk // we want the number of records to better report, in that case bool isLargeChunk = false; @@ -498,6 +503,7 @@ namespace mongo { Client::Context ctx( _ns ); NamespaceDetails *d = nsdetails( _ns.c_str() ); assert( d ); + scoped_spinlock lk( _trackerLocks ); allocSize = std::min(BSONObjMaxUserSize, (int)((12 + d->averageObjectSize()) * _cloneLocs.size())); } BSONArrayBuilder a (allocSize); @@ -507,7 +513,7 @@ namespace mongo { 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? @@ -545,6 +551,11 @@ namespace mongo { if ( ! db->ownsNS( _ns ) ) return; + + // not needed right now + // but trying to prevent a future bug + scoped_spinlock lk( _trackerLocks ); + _cloneLocs.erase( dl ); } @@ -564,6 +575,10 @@ namespace mongo { BSONObj _min; BSONObj _max; + // we need the lock in case there is a malicious _migrateClone for example + // even though it shouldn't be needed under normal operation + SpinLock _trackerLocks; + // disk locs yet to be transferred from here to the other side // no locking needed because built initially by 1 thread in a read lock // emptied by 1 thread in a read lock |