bool NOINLINE_DECL DurableImpl::_aCommitIsNeeded() { switch (Lock::isLocked()) { case '\0': { // lock_w() can call in this state at times if a commit is needed before attempting // its lock. Lock::GlobalRead r; if( commitJob.bytes() < UncommittedBytesLimit ) { // someone else beat us to it // // note before of 'R' state, many threads can pile-in to this point and // still fall through to below, and they will exit without doing work later // once inside groupCommitMutex. this is all likely inefficient. maybe // groupCommitMutex should be on top. return false; } commitNow(); return true; } case 'w': { if( Lock::atLeastReadLocked("local") ) { error() << "can't commitNow from commitIfNeeded, as we are in local db lock" << endl; printStackTrace(); dassert(false); // this will make _DEBUG builds terminate. so we will notice in buildbot. return false; } if( Lock::atLeastReadLocked("admin") ) { error() << "can't commitNow from commitIfNeeded, as we are in admin db lock" << endl; printStackTrace(); dassert(false); return false; } LOG(1) << "commitIfNeeded upgrading from shared write to exclusive write state" << endl; Lock::DBWrite::UpgradeToExclusive ex; if (ex.gotUpgrade()) { commitNow(); } return true; } case 'W': case 'R': commitNow(); return true; case 'r': return false; default: fassertFailed(16434); // unknown lock type } }
bool NOINLINE_DECL DurableImpl::_aCommitIsNeeded() { switch (Lock::isLocked()) { case '\0': { DEV log() << "commitIfNeeded but we are unlocked that is ok but why do we get here" << endl; Lock::GlobalRead r; if( commitJob.bytes() < UncommittedBytesLimit ) { // someone else beat us to it return false; } commitNow(); return true; } case 'w': { if( Lock::atLeastReadLocked("local") ) { error() << "can't commitNow from commitIfNeeded, as we are in local db lock" << endl; printStackTrace(); dassert(false); // this will make _DEBUG builds terminate. so we will notice in buildbot. return false; } if( Lock::atLeastReadLocked("admin") ) { error() << "can't commitNow from commitIfNeeded, as we are in admin db lock" << endl; printStackTrace(); dassert(false); return false; } LOG(1) << "commitIfNeeded upgrading from shared write to exclusive write state" << endl; Lock::DBWrite::UpgradeToExclusive ex; if (ex.gotUpgrade()) { commitNow(); } return true; } case 'W': case 'R': commitNow(); return true; case 'r': return false; default: fassertFailed(16434); // unknown lock type } }