Permalink
Browse files

add dbtempreleasecond that only releases if you have a single level lock

  • Loading branch information...
1 parent 0d1a097 commit 4ea2e8ff49ba65658962eba140b4aca946af47d2 @erh erh committed Dec 18, 2009
Showing with 45 additions and 1 deletion.
  1. +23 −0 db/db.h
  2. +1 −1 db/query.cpp
  3. +21 −0 jstests/remove8.js
View
23 db/db.h
@@ -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"
View
@@ -155,7 +155,7 @@ namespace mongo {
cc->updateLocation();
cc->setDoingDeletes( false );
{
- dbtemprelease unlock;
+ dbtempreleasecond unlock;
}
if ( ClientCursor::find( id , false ) == 0 ){
cc.reset( 0 );
View
@@ -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.