diff options
author | Eliot Horowitz <eliot@10gen.com> | 2011-04-29 10:53:58 -0400 |
---|---|---|
committer | Eliot Horowitz <eliot@10gen.com> | 2011-04-29 10:54:12 -0400 |
commit | 1183afb5c661d6fa34f69e75fb7c5d522bc1a8b9 (patch) | |
tree | 06c471868465fd1ee3742ba1d92f64d8dba261be | |
parent | 64e8cca9c9d8048dfe6580635e2e83739caf0a0d (diff) | |
download | mongo-1183afb5c661d6fa34f69e75fb7c5d522bc1a8b9.tar.gz |
don't sleep with lock held SERVER-3020
-rw-r--r-- | s/balance.cpp | 45 |
1 files changed, 24 insertions, 21 deletions
diff --git a/s/balance.cpp b/s/balance.cpp index ffa23ed794b..fba325ed5ae 100644 --- a/s/balance.cpp +++ b/s/balance.cpp @@ -294,29 +294,32 @@ namespace mongo { // use fresh shard state Shard::reloadShardInfo(); - dist_lock_try lk( &balanceLock , "doing balance round" ); - if ( ! lk.got() ) { - log(1) << "skipping balancing round because another balancer is active" << endl; - conn.done(); - - sleepsecs( 30 ); // no need to wake up soon - continue; - } - - log(1) << "*** start balancing round" << endl; - - vector<CandidateChunkPtr> candidateChunks; - _doBalanceRound( conn.conn() , &candidateChunks ); - if ( candidateChunks.size() == 0 ) { - log(1) << "no need to move any chunk" << endl; - } - else { - _balancedLastTime = _moveChunks( &candidateChunks ); + { + dist_lock_try lk( &balanceLock , "doing balance round" ); + if ( ! lk.got() ) { + log(1) << "skipping balancing round because another balancer is active" << endl; + conn.done(); + + sleepsecs( 30 ); // no need to wake up soon + continue; + } + + log(1) << "*** start balancing round" << endl; + + vector<CandidateChunkPtr> candidateChunks; + _doBalanceRound( conn.conn() , &candidateChunks ); + if ( candidateChunks.size() == 0 ) { + log(1) << "no need to move any chunk" << endl; + } + else { + _balancedLastTime = _moveChunks( &candidateChunks ); + } + + log(1) << "*** end of balancing round" << endl; } - - log(1) << "*** end of balancing round" << endl; + conn.done(); - + sleepsecs( _balancedLastTime ? 5 : 10 ); } catch ( std::exception& e ) { |