Skip to content

Commit

Permalink
fix problem with groupcommitlimitedlocks simultaneous with dropdataba…
Browse files Browse the repository at this point in the history
…se in 1.9
  • Loading branch information
dwight committed May 3, 2011
1 parent a72aea2 commit 33897ac
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 9 deletions.
5 changes: 5 additions & 0 deletions db/pdfile.cpp
Expand Up @@ -1847,6 +1847,11 @@ namespace mongo {

BackgroundOperation::assertNoBgOpInProgForDb(d->name.c_str());

dbMutex.assertWriteLocked();

// WRITETODATAFILES etc. is in this lock only -- so we need it.
RWLockRecursive::Exclusive lk(MongoFile::mmmutex);

getDur().syncDataAndTruncateJournal();

Database::closeDatabase( d->name.c_str(), d->path );
Expand Down
27 changes: 18 additions & 9 deletions util/concurrency/rwlock.h
Expand Up @@ -365,20 +365,29 @@ namespace mongo {

class Shared : boost::noncopyable {
RWLockRecursive& _r;
bool _alreadyExclusive;
public:
Shared(RWLockRecursive& r) : _r(r) {
int s = _r._state.get();
dassert( s >= 0 ); // -1 would mean exclusive
if( s == 0 )
_r._lk.lock_shared();
_r._state.set(s+1);
_alreadyExclusive = s < 0;
if( !_alreadyExclusive ) {
dassert( s >= 0 ); // -1 would mean exclusive
if( s == 0 )
_r._lk.lock_shared();
_r._state.set(s+1);
}
}
~Shared() {
int s = _r._state.get() - 1;
if( s == 0 )
_r._lk.unlock_shared();
_r._state.set(s);
DEV wassert( s >= 0 );
if( _alreadyExclusive ) {
DEV wassert( _r._state.get() < 0 );
}
else {
int s = _r._state.get() - 1;
if( s == 0 )
_r._lk.unlock_shared();
_r._state.set(s);
DEV wassert( s >= 0 );
}
}
};
};
Expand Down

0 comments on commit 33897ac

Please sign in to comment.