Skip to content

Commit 558bb8c

Browse files
committed
fix bug in remove concurrency
1 parent 0d1a097 commit 558bb8c

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

db/query.cpp

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,14 +154,39 @@ namespace mongo {
154154
if ( ++nScanned % 128 == 0 ){
155155
cc->updateLocation();
156156
cc->setDoingDeletes( false );
157+
158+
/* a quick test that our temprelease is safe.
159+
todo: make a YieldingCursor class
160+
and then make the following code part of a unit test.
161+
*/
162+
const int test = 0;
163+
static bool inEmpty = false;
164+
if( test && !inEmpty ) {
165+
inEmpty = true;
166+
log() << "TEST: manipulate collection during remove" << endl;
167+
if( test == 1 )
168+
Helpers::emptyCollection(ns);
169+
else if( test == 2 ) {
170+
BSONObjBuilder b; string m;
171+
dropCollection(ns, m, b);
172+
}
173+
else {
174+
dropDatabase(ns);
175+
}
176+
}
177+
178+
/* yield */
157179
{
158180
dbtemprelease unlock;
159181
}
160182
if ( ClientCursor::find( id , false ) == 0 ){
161-
cc.reset( 0 );
183+
cc.release(); // has already been deleted elsewhere
162184
break;
163185
}
164186
}
187+
188+
// this way we can avoid calling updateLocation() every time (expensive)
189+
// as well as some other nuances handled
165190
cc->setDoingDeletes( true );
166191

167192
DiskLoc rloc = cc->c->currLoc();

0 commit comments

Comments
 (0)