Skip to content

Commit

Permalink
add dbtempreleasecond that only releases if you have a single level lock
Browse files Browse the repository at this point in the history
  • Loading branch information
erh committed Dec 18, 2009
1 parent 0d1a097 commit 4ea2e8f
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 1 deletion.
23 changes: 23 additions & 0 deletions db/db.h
Expand Up @@ -156,6 +156,29 @@ namespace mongo {
}
};

/**
only does a temp release if we're not nested and have a lock
*/
struct dbtempreleasecond {
dbtemprelease * real;
int locktype;

dbtempreleasecond(){
real = 0;
locktype = dbMutex.getState();
if ( locktype == 1 || locktype == -1 )
real = new dbtemprelease();
}

~dbtempreleasecond(){
if ( real ){
delete real;
real = 0;
}
}

};

} // namespace mongo

#include "dbinfo.h"
Expand Down
2 changes: 1 addition & 1 deletion db/query.cpp
Expand Up @@ -155,7 +155,7 @@ namespace mongo {
cc->updateLocation();
cc->setDoingDeletes( false );
{
dbtemprelease unlock;
dbtempreleasecond unlock;
}
if ( ClientCursor::find( id , false ) == 0 ){
cc.reset( 0 );
Expand Down
21 changes: 21 additions & 0 deletions jstests/remove8.js
@@ -0,0 +1,21 @@

t = db.remove8;
t.drop();

N = 1000;

function fill(){
for ( var i=0; i<N; i++ ){
t.save( { x : i } );
}
}

fill();
assert.eq( N , t.count() , "A" );
t.remove( {} )
assert.eq( 0 , t.count() , "B" );

fill();
assert.eq( N , t.count() , "C" );
db.eval( function(){ db.remove8.remove( {} ); } )
assert.eq( 0 , t.count() , "D" );

0 comments on commit 4ea2e8f

Please sign in to comment.